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/scripts | |
| 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/scripts')
| -rw-r--r-- | src/bin/scripts/clusterdb.c | 4 | ||||
| -rw-r--r-- | src/bin/scripts/createdb.c | 5 | ||||
| -rw-r--r-- | src/bin/scripts/createuser.c | 4 | ||||
| -rw-r--r-- | src/bin/scripts/dropdb.c | 5 | ||||
| -rw-r--r-- | src/bin/scripts/dropuser.c | 4 | ||||
| -rw-r--r-- | src/bin/scripts/vacuumdb.c | 4 |
6 files changed, 14 insertions, 12 deletions
diff --git a/src/bin/scripts/clusterdb.c b/src/bin/scripts/clusterdb.c index 4b5bc6f15f..3ab0be575e 100644 --- a/src/bin/scripts/clusterdb.c +++ b/src/bin/scripts/clusterdb.c @@ -4,7 +4,7 @@ * * Portions Copyright (c) 2002-2005, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/scripts/clusterdb.c,v 1.12 2005/01/01 05:43:08 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/clusterdb.c,v 1.13 2005/06/21 04:02:33 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -207,7 +207,7 @@ cluster_all_databases(const char *host, const char *port, PGresult *result; int i; - conn = connectDatabase("template1", host, port, username, password, progname); + conn = connectDatabase("postgres", host, port, username, password, progname); result = executeQuery(conn, "SELECT datname FROM pg_database WHERE datallowconn;", progname, echo); PQfinish(conn); diff --git a/src/bin/scripts/createdb.c b/src/bin/scripts/createdb.c index f85e4e84fe..1585523ab9 100644 --- a/src/bin/scripts/createdb.c +++ b/src/bin/scripts/createdb.c @@ -5,7 +5,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/scripts/createdb.c,v 1.14 2004/12/31 22:03:17 pgsql Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/createdb.c,v 1.15 2005/06/21 04:02:33 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -157,7 +157,8 @@ main(int argc, char *argv[]) appendPQExpBuffer(&sql, " TEMPLATE %s", fmtId(template)); appendPQExpBuffer(&sql, ";\n"); - conn = connectDatabase("template1", host, port, username, password, progname); + conn = connectDatabase(strcmp(dbname, "postgres") == 0 ? "template1" : "postgres", + host, port, username, password, progname); if (echo) printf("%s", sql.data); diff --git a/src/bin/scripts/createuser.c b/src/bin/scripts/createuser.c index 67758e00d7..db85837952 100644 --- a/src/bin/scripts/createuser.c +++ b/src/bin/scripts/createuser.c @@ -5,7 +5,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.16 2004/12/31 22:03:17 pgsql Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.17 2005/06/21 04:02:33 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -209,7 +209,7 @@ main(int argc, char *argv[]) appendPQExpBuffer(&sql, " NOCREATEUSER"); appendPQExpBuffer(&sql, ";\n"); - conn = connectDatabase("template1", host, port, username, password, progname); + conn = connectDatabase("postgres", host, port, username, password, progname); if (echo) printf("%s", sql.data); diff --git a/src/bin/scripts/dropdb.c b/src/bin/scripts/dropdb.c index d58ffcb4ef..944c68dbe3 100644 --- a/src/bin/scripts/dropdb.c +++ b/src/bin/scripts/dropdb.c @@ -5,7 +5,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/scripts/dropdb.c,v 1.14 2004/12/31 22:03:17 pgsql Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/dropdb.c,v 1.15 2005/06/21 04:02:33 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -117,7 +117,8 @@ main(int argc, char *argv[]) appendPQExpBuffer(&sql, "DROP DATABASE %s;\n", fmtId(dbname)); - conn = connectDatabase("template1", host, port, username, password, progname); + conn = connectDatabase(strcmp(dbname, "postgres") == 0 ? "template1" : "postgres", + host, port, username, password, progname); if (echo) printf("%s", sql.data); diff --git a/src/bin/scripts/dropuser.c b/src/bin/scripts/dropuser.c index 343cae39b8..32aa83557a 100644 --- a/src/bin/scripts/dropuser.c +++ b/src/bin/scripts/dropuser.c @@ -5,7 +5,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/scripts/dropuser.c,v 1.13 2004/12/31 22:03:17 pgsql Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/dropuser.c,v 1.14 2005/06/21 04:02:33 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -116,7 +116,7 @@ main(int argc, char *argv[]) initPQExpBuffer(&sql); appendPQExpBuffer(&sql, "DROP USER %s;\n", fmtId(dropuser)); - conn = connectDatabase("template1", host, port, username, password, progname); + conn = connectDatabase("postgres", host, port, username, password, progname); if (echo) printf("%s", sql.data); diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c index 2015e44242..8998d5da6c 100644 --- a/src/bin/scripts/vacuumdb.c +++ b/src/bin/scripts/vacuumdb.c @@ -5,7 +5,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/scripts/vacuumdb.c,v 1.12 2004/12/31 22:03:17 pgsql Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/vacuumdb.c,v 1.13 2005/06/21 04:02:33 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -233,7 +233,7 @@ vacuum_all_databases(bool full, bool verbose, bool analyze, PGresult *result; int i; - conn = connectDatabase("template1", host, port, username, password, progname); + conn = connectDatabase("postgres", host, port, username, password, progname); result = executeQuery(conn, "SELECT datname FROM pg_database WHERE datallowconn;", progname, echo); PQfinish(conn); |
