dumpall_cleanup.patch2-noci

text/plain

Filename: dumpall_cleanup.patch2-noci
Type: text/plain
Part: 3
Message: Re: Non-text mode for pg_dumpall
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
index 7ceaba27419..7a06e595b88 100644
--- a/src/bin/pg_dump/pg_dumpall.c
+++ b/src/bin/pg_dump/pg_dumpall.c
@@ -1639,10 +1639,9 @@ dumpDatabases(PGconn *conn, ArchiveFormat archDumpFormat)
 		fprintf(OPF, "--\n-- Databases\n--\n\n");
 
 	/*
-	 * If directory/tar/custom format is specified then create a subdirectory
-	 * under the main directory and each database dump file subdirectory will
-	 * be created under the subdirectory in archive mode as per single db
-	 * pg_dump.
+	 * If directory/tar/custom format is specified, create a subdirectory
+	 * under the main directory and each database dump file or subdirectory
+	 * will be created in that subdirectory by pg_dump.
 	 */
 	if (archDumpFormat != archNull)
 	{
@@ -1666,7 +1665,7 @@ dumpDatabases(PGconn *conn, ArchiveFormat archDumpFormat)
 	{
 		char	   *dbname = PQgetvalue(res, i, 0);
 		char	   *oid = PQgetvalue(res, i, 1);
-		const char *create_opts;
+		const char *create_opts = "";
 		int			ret;
 
 		/* Skip template0, even if it's not marked !datallowconn. */
@@ -1699,7 +1698,8 @@ dumpDatabases(PGconn *conn, ArchiveFormat archDumpFormat)
 
 		pg_log_info("dumping database \"%s\"", dbname);
 
-		fprintf(OPF, "--\n-- Database \"%s\" dump\n--\n\n", dbname);
+		if (archDumpFormat == archNull)
+			 fprintf(OPF, "--\n-- Database \"%s\" dump\n--\n\n", dbname);
 
 		/*
 		 * We assume that "template1" and "postgres" already exist in the
@@ -1713,20 +1713,8 @@ dumpDatabases(PGconn *conn, ArchiveFormat archDumpFormat)
 		{
 			if (output_clean)
 				create_opts = "--clean --create";
-			else
-			{
-				/* Since pg_dump won't emit a \connect command, we must */
-				if (archDumpFormat == archNull)
-				{
-					create_opts = "";
-					fprintf(OPF, "\\connect %s\n\n", dbname);
-				}
-				else
-				{
-					/* Dumping all databases so add --create option. */
-					create_opts = "--create";
-				}
-			}
+			else if (archDumpFormat == archNull)
+				fprintf(OPF, "\\connect %s\n\n", dbname);
 		}
 		else
 			create_opts = "--create";