6
6
* Portions Copyright (c) 1994, Regents of the University of California
7
7
*
8
8
*
9
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.60 2005/06/21 04:02:32 tgl Exp $
9
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.61 2005/06/21 15:22:18 tgl Exp $
10
10
*
11
11
*-------------------------------------------------------------------------
12
12
*/
@@ -303,7 +303,7 @@ main(int argc, char *argv[])
303
303
if (verbose )
304
304
dumpTimestamp ("Started on" );
305
305
306
- printf ("\\connect \" postgres\" \n\n" );
306
+ printf ("\\connect postgres\n\n" );
307
307
308
308
if (!data_only )
309
309
{
@@ -661,40 +661,43 @@ dumpCreateDB(PGconn *conn)
661
661
char * dbtablespace = PQgetvalue (res , i , 5 );
662
662
char * fdbname ;
663
663
664
- if (strcmp (dbname , "template1" ) == 0 )
665
- continue ;
666
-
667
664
buf = createPQExpBuffer ();
668
-
669
- /* needed for buildACLCommands() */
670
665
fdbname = strdup (fmtId (dbname ));
671
666
672
- if (output_clean )
673
- appendPQExpBuffer (buf , "DROP DATABASE %s;\n" , fdbname );
674
-
675
- appendPQExpBuffer (buf , "CREATE DATABASE %s" , fdbname );
667
+ /*
668
+ * Skip the CREATE DATABASE commands for "template1" and "postgres",
669
+ * since they are presumably already there in the destination cluster.
670
+ * We do want to emit their ACLs and config options if any, however.
671
+ */
672
+ if (strcmp (dbname , "template1" ) != 0 &&
673
+ strcmp (dbname , "postgres" ) != 0 )
674
+ {
675
+ if (output_clean )
676
+ appendPQExpBuffer (buf , "DROP DATABASE %s;\n" , fdbname );
676
677
677
- appendPQExpBuffer (buf , " WITH TEMPLATE = template0" );
678
+ appendPQExpBuffer (buf , "CREATE DATABASE %s" , fdbname );
678
679
679
- if (strlen (dbowner ) != 0 )
680
- appendPQExpBuffer (buf , " OWNER = %s" ,
681
- fmtId (dbowner ));
680
+ appendPQExpBuffer (buf , " WITH TEMPLATE = template0" );
682
681
683
- appendPQExpBuffer ( buf , " ENCODING = " );
684
- appendStringLiteral (buf , dbencoding , true );
682
+ if ( strlen ( dbowner ) != 0 )
683
+ appendPQExpBuffer (buf , " OWNER = %s" , fmtId ( dbowner ) );
685
684
686
- /* Output tablespace if it isn't default */
687
- if (strcmp (dbtablespace , "pg_default" ) != 0 )
688
- appendPQExpBuffer (buf , " TABLESPACE = %s" ,
689
- fmtId (dbtablespace ));
685
+ appendPQExpBuffer (buf , " ENCODING = " );
686
+ appendStringLiteral (buf , dbencoding , true);
690
687
691
- appendPQExpBuffer (buf , ";\n" );
688
+ /* Output tablespace if it isn't default */
689
+ if (strcmp (dbtablespace , "pg_default" ) != 0 )
690
+ appendPQExpBuffer (buf , " TABLESPACE = %s" ,
691
+ fmtId (dbtablespace ));
692
692
693
- if (strcmp (dbistemplate , "t" ) == 0 )
694
- {
695
- appendPQExpBuffer (buf , "UPDATE pg_database SET datistemplate = 't' WHERE datname = " );
696
- appendStringLiteral (buf , dbname , true);
697
693
appendPQExpBuffer (buf , ";\n" );
694
+
695
+ if (strcmp (dbistemplate , "t" ) == 0 )
696
+ {
697
+ appendPQExpBuffer (buf , "UPDATE pg_database SET datistemplate = 't' WHERE datname = " );
698
+ appendStringLiteral (buf , dbname , true);
699
+ appendPQExpBuffer (buf , ";\n" );
700
+ }
698
701
}
699
702
700
703
if (!skip_acls &&
@@ -708,11 +711,12 @@ dumpCreateDB(PGconn *conn)
708
711
}
709
712
710
713
printf ("%s" , buf -> data );
711
- destroyPQExpBuffer (buf );
712
- free (fdbname );
713
714
714
715
if (server_version >= 70300 )
715
716
dumpDatabaseConfig (conn , dbname );
717
+
718
+ destroyPQExpBuffer (buf );
719
+ free (fdbname );
716
720
}
717
721
718
722
PQclear (res );
0 commit comments