66 * Portions Copyright (c) 1994, Regents of the University of California
77 *
88 *
9- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.60 2005/06/2104:02:32 tgl Exp $
9+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.61 2005/06/2115:22:18 tgl Exp $
1010 *
1111 *-------------------------------------------------------------------------
1212 */
@@ -303,7 +303,7 @@ main(int argc, char *argv[])
303303if (verbose )
304304dumpTimestamp ("Started on" );
305305
306- printf ("\\connect\" postgres\" \n\n" );
306+ printf ("\\connect postgres\n\n" );
307307
308308if (!data_only )
309309{
@@ -661,40 +661,43 @@ dumpCreateDB(PGconn *conn)
661661char * dbtablespace = PQgetvalue (res ,i ,5 );
662662char * fdbname ;
663663
664- if (strcmp (dbname ,"template1" )== 0 )
665- continue ;
666-
667664buf = createPQExpBuffer ();
668-
669- /* needed for buildACLCommands() */
670665fdbname = strdup (fmtId (dbname ));
671666
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 );
676677
677- appendPQExpBuffer (buf ," WITH TEMPLATE = template0" );
678+ appendPQExpBuffer (buf ,"CREATE DATABASE %s" , fdbname );
678679
679- if (strlen (dbowner )!= 0 )
680- appendPQExpBuffer (buf ," OWNER = %s" ,
681- fmtId (dbowner ));
680+ appendPQExpBuffer (buf ," WITH TEMPLATE = template0" );
682681
683- appendPQExpBuffer ( buf , " ENCODING = " );
684- appendStringLiteral (buf ,dbencoding , true );
682+ if ( strlen ( dbowner ) != 0 )
683+ appendPQExpBuffer (buf ," OWNER = %s" , fmtId ( dbowner ) );
685684
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);
690687
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 ));
692692
693- if (strcmp (dbistemplate ,"t" )== 0 )
694- {
695- appendPQExpBuffer (buf ,"UPDATE pg_database SET datistemplate = 't' WHERE datname = " );
696- appendStringLiteral (buf ,dbname , true);
697693appendPQExpBuffer (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+ }
698701}
699702
700703if (!skip_acls &&
@@ -708,11 +711,12 @@ dumpCreateDB(PGconn *conn)
708711}
709712
710713printf ("%s" ,buf -> data );
711- destroyPQExpBuffer (buf );
712- free (fdbname );
713714
714715if (server_version >=70300 )
715716dumpDatabaseConfig (conn ,dbname );
717+
718+ destroyPQExpBuffer (buf );
719+ free (fdbname );
716720}
717721
718722PQclear (res );