aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-06-21 15:22:18 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-06-21 15:22:18 +0000
commitb49d871f6ac58ff63a3147575494fb8fe9c6a5eb (patch)
treedd96f8bd58f86abeb0f4300b77ab3c7a3e98c19a
parent6f7fc0badef55b376f408bd318a8065fd2edf266 (diff)
downloadpostgresql-b49d871f6ac58ff63a3147575494fb8fe9c6a5eb.tar.gz
postgresql-b49d871f6ac58ff63a3147575494fb8fe9c6a5eb.zip
Fix pg_dumpall to do the right thing with "postgres" database, per
Dave Page. Also, cause it to emit rather than ignore any ACL and datconfig options that may be set for these two databases.
-rw-r--r--src/bin/pg_dump/pg_dumpall.c60
1 files changed, 32 insertions, 28 deletions
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
index 0ed8b921b89..75158a58bfa 100644
--- a/src/bin/pg_dump/pg_dumpall.c
+++ b/src/bin/pg_dump/pg_dumpall.c
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
*
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.60 2005/06/21 04:02:32 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.61 2005/06/21 15:22:18 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -303,7 +303,7 @@ main(int argc, char *argv[])
if (verbose)
dumpTimestamp("Started on");
- printf("\\connect \"postgres\"\n\n");
+ printf("\\connect postgres\n\n");
if (!data_only)
{
@@ -661,40 +661,43 @@ dumpCreateDB(PGconn *conn)
char *dbtablespace = PQgetvalue(res, i, 5);
char *fdbname;
- if (strcmp(dbname, "template1") == 0)
- continue;
-
buf = createPQExpBuffer();
-
- /* needed for buildACLCommands() */
fdbname = strdup(fmtId(dbname));
- if (output_clean)
- appendPQExpBuffer(buf, "DROP DATABASE %s;\n", fdbname);
-
- appendPQExpBuffer(buf, "CREATE DATABASE %s", fdbname);
+ /*
+ * Skip the CREATE DATABASE commands for "template1" and "postgres",
+ * since they are presumably already there in the destination cluster.
+ * We do want to emit their ACLs and config options if any, however.
+ */
+ if (strcmp(dbname, "template1") != 0 &&
+ strcmp(dbname, "postgres") != 0)
+ {
+ if (output_clean)
+ appendPQExpBuffer(buf, "DROP DATABASE %s;\n", fdbname);
- appendPQExpBuffer(buf, " WITH TEMPLATE = template0");
+ appendPQExpBuffer(buf, "CREATE DATABASE %s", fdbname);
- if (strlen(dbowner) != 0)
- appendPQExpBuffer(buf, " OWNER = %s",
- fmtId(dbowner));
+ appendPQExpBuffer(buf, " WITH TEMPLATE = template0");
- appendPQExpBuffer(buf, " ENCODING = ");
- appendStringLiteral(buf, dbencoding, true);
+ if (strlen(dbowner) != 0)
+ appendPQExpBuffer(buf, " OWNER = %s", fmtId(dbowner));
- /* Output tablespace if it isn't default */
- if (strcmp(dbtablespace, "pg_default") != 0)
- appendPQExpBuffer(buf, " TABLESPACE = %s",
- fmtId(dbtablespace));
+ appendPQExpBuffer(buf, " ENCODING = ");
+ appendStringLiteral(buf, dbencoding, true);
- appendPQExpBuffer(buf, ";\n");
+ /* Output tablespace if it isn't default */
+ if (strcmp(dbtablespace, "pg_default") != 0)
+ appendPQExpBuffer(buf, " TABLESPACE = %s",
+ fmtId(dbtablespace));
- if (strcmp(dbistemplate, "t") == 0)
- {
- appendPQExpBuffer(buf, "UPDATE pg_database SET datistemplate = 't' WHERE datname = ");
- appendStringLiteral(buf, dbname, true);
appendPQExpBuffer(buf, ";\n");
+
+ if (strcmp(dbistemplate, "t") == 0)
+ {
+ appendPQExpBuffer(buf, "UPDATE pg_database SET datistemplate = 't' WHERE datname = ");
+ appendStringLiteral(buf, dbname, true);
+ appendPQExpBuffer(buf, ";\n");
+ }
}
if (!skip_acls &&
@@ -708,11 +711,12 @@ dumpCreateDB(PGconn *conn)
}
printf("%s", buf->data);
- destroyPQExpBuffer(buf);
- free(fdbname);
if (server_version >= 70300)
dumpDatabaseConfig(conn, dbname);
+
+ destroyPQExpBuffer(buf);
+ free(fdbname);
}
PQclear(res);