Commit 6cbdbd9e authored by Andrew Dunstan's avatar Andrew Dunstan

Add extra descriptive headings in pg_dumpall

Headings are added for the User Configurations and Databases sections,
and for each user configuration and database in the output.

Author: Fabien Coelho
Discussion: https://postgr.es/m/alpine.DEB.2.21.1812272222130.32444@lancre
parent f092de05
...@@ -1346,6 +1346,7 @@ dumpUserConfig(PGconn *conn, const char *username) ...@@ -1346,6 +1346,7 @@ dumpUserConfig(PGconn *conn, const char *username)
{ {
PQExpBuffer buf = createPQExpBuffer(); PQExpBuffer buf = createPQExpBuffer();
int count = 1; int count = 1;
bool first = true;
for (;;) for (;;)
{ {
...@@ -1367,6 +1368,14 @@ dumpUserConfig(PGconn *conn, const char *username) ...@@ -1367,6 +1368,14 @@ dumpUserConfig(PGconn *conn, const char *username)
if (PQntuples(res) == 1 && if (PQntuples(res) == 1 &&
!PQgetisnull(res, 0, 0)) !PQgetisnull(res, 0, 0))
{ {
/* comment at section start, only if needed */
if (first)
{
fprintf(OPF, "--\n-- User Configurations\n--\n\n");
first = false;
}
fprintf(OPF, "--\n-- User Config \"%s\"\n--\n\n", username);
resetPQExpBuffer(buf); resetPQExpBuffer(buf);
makeAlterConfigCommand(conn, PQgetvalue(res, 0, 0), makeAlterConfigCommand(conn, PQgetvalue(res, 0, 0),
"ROLE", username, NULL, NULL, "ROLE", username, NULL, NULL,
...@@ -1454,6 +1463,9 @@ dumpDatabases(PGconn *conn) ...@@ -1454,6 +1463,9 @@ dumpDatabases(PGconn *conn)
"WHERE datallowconn " "WHERE datallowconn "
"ORDER BY (datname <> 'template1'), datname"); "ORDER BY (datname <> 'template1'), datname");
if (PQntuples(res) > 0)
fprintf(OPF, "--\n-- Databases\n--\n\n");
for (i = 0; i < PQntuples(res); i++) for (i = 0; i < PQntuples(res); i++)
{ {
char *dbname = PQgetvalue(res, i, 0); char *dbname = PQgetvalue(res, i, 0);
...@@ -1476,6 +1488,8 @@ dumpDatabases(PGconn *conn) ...@@ -1476,6 +1488,8 @@ dumpDatabases(PGconn *conn)
if (verbose) if (verbose)
fprintf(stderr, _("%s: dumping database \"%s\"...\n"), progname, dbname); fprintf(stderr, _("%s: dumping database \"%s\"...\n"), progname, dbname);
fprintf(OPF, "--\n-- Database \"%s\" dump\n--\n\n", dbname);
/* /*
* We assume that "template1" and "postgres" already exist in the * We assume that "template1" and "postgres" already exist in the
* target installation. dropDBs() won't have removed them, for fear * target installation. dropDBs() won't have removed them, for fear
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment