diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-06-21 04:02:34 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-06-21 04:02:34 +0000 |
| commit | 6f7fc0badef55b376f408bd318a8065fd2edf266 (patch) | |
| tree | b86da563c6c8de5c930f00e8f2a7d5a994ba2d18 /src/bin/initdb/initdb.c | |
| parent | ec3a1af0a89a169c100f7157f7c6932234ae5988 (diff) | |
| download | postgresql-6f7fc0badef55b376f408bd318a8065fd2edf266.tar.gz | |
Cause initdb to create a third standard database "postgres", which
unlike template0 and template1 does not have any special status in
terms of backend functionality. However, all external utilities such
as createuser and createdb now connect to "postgres" instead of
template1, and the documentation is changed to encourage people to use
"postgres" instead of template1 as a play area. This should fix some
longstanding gotchas involving unexpected propagation of database
objects by createdb (when you used template1 without understanding
the implications), as well as ameliorating the problem that CREATE
DATABASE is unhappy if anyone else is connected to template1.
Patch by Dave Page, minor editing by Tom Lane. All per recent
pghackers discussions.
Diffstat (limited to 'src/bin/initdb/initdb.c')
| -rw-r--r-- | src/bin/initdb/initdb.c | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 9e42c902f1..dd830f7c03 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -8,14 +8,19 @@ * * To create the database cluster, we create the directory that contains * all its data, create the files that hold the global tables, create - * a few other control files for it, and create two databases: the - * template0 and template1 databases. + * a few other control files for it, and create three databases: the + * template databases "template0" and "template1", and a default user + * database "postgres". * * The template databases are ordinary PostgreSQL databases. template0 * is never supposed to change after initdb, whereas template1 can be * changed to add site-local standard data. Either one can be copied * to produce a new database. * + * For largely-historical reasons, the template1 database is the one built + * by the basic bootstrap process. After it is complete, template0 and + * the default database, postgres, are made just by copying template1. + * * To create template1, we run the postgres (backend) program in bootstrap * mode and feed it data from the postgres.bki library file. After this * initial bootstrap phase, some additional stuff is created by normal @@ -23,12 +28,10 @@ * just embedded into this program (yeah, it's ugly), but larger chunks * are taken from script files. * - * template0 is made just by copying the completed template1. * * Note: * The program has some memory leakage - it isn't worth cleaning it up. * - * * This is a C implementation of the previous shell script for setting up a * PostgreSQL cluster location, and should be highly compatible with it. * author of C translation: Andrew Dunstan mailto:andrew@dunslane.net @@ -39,7 +42,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * Portions taken from FreeBSD. * - * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.84 2005/06/17 22:32:47 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.85 2005/06/21 04:02:32 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -178,6 +181,7 @@ static void set_info_version(void); static void setup_schema(void); static void vacuum_db(void); static void make_template0(void); +static void make_postgres(void); static void trapsig(int signum); static void check_ok(void); static char *escape_quotes(const char *src); @@ -1846,7 +1850,7 @@ make_template0(void) * We use the OID of template0 to determine lastsysoid */ "UPDATE pg_database SET datlastsysoid = " - " (SELECT oid::int4 - 1 FROM pg_database " + " (SELECT oid FROM pg_database " " WHERE datname = 'template0');\n", /* @@ -1882,6 +1886,37 @@ make_template0(void) check_ok(); } +/* + * copy template1 to postgres + */ +static void +make_postgres(void) +{ + PG_CMD_DECL; + char **line; + static char *postgres_setup[] = { + "CREATE DATABASE postgres;\n", + NULL + }; + + fputs(_("copying template1 to postgres ... "), stdout); + fflush(stdout); + + snprintf(cmd, sizeof(cmd), + "\"%s\" %s template1 >%s", + backend_exec, backend_options, + DEVNULL); + + PG_CMD_OPEN; + + for (line = postgres_setup; *line; line++) + PG_CMD_PUTS(*line); + + PG_CMD_CLOSE; + + check_ok(); +} + /* * signal handler in case we are interrupted. @@ -2609,6 +2644,8 @@ main(int argc, char *argv[]) make_template0(); + make_postgres(); + if (authwarning != NULL) fprintf(stderr, "%s", authwarning); |
