summaryrefslogtreecommitdiffstats
path: root/src/bin/pg_upgrade/dump.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:17:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:17:33 +0000
commit5e45211a64149b3c659b90ff2de6fa982a5a93ed (patch)
tree739caf8c461053357daa9f162bef34516c7bf452 /src/bin/pg_upgrade/dump.c
parentInitial commit. (diff)
downloadpostgresql-15-5e45211a64149b3c659b90ff2de6fa982a5a93ed.tar.xz
postgresql-15-5e45211a64149b3c659b90ff2de6fa982a5a93ed.zip
Adding upstream version 15.5.upstream/15.5
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/bin/pg_upgrade/dump.c')
-rw-r--r--src/bin/pg_upgrade/dump.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/bin/pg_upgrade/dump.c b/src/bin/pg_upgrade/dump.c
new file mode 100644
index 0000000..29b9e44
--- /dev/null
+++ b/src/bin/pg_upgrade/dump.c
@@ -0,0 +1,71 @@
+/*
+ * dump.c
+ *
+ * dump functions
+ *
+ * Copyright (c) 2010-2022, PostgreSQL Global Development Group
+ * src/bin/pg_upgrade/dump.c
+ */
+
+#include "postgres_fe.h"
+
+#include "fe_utils/string_utils.h"
+#include "pg_upgrade.h"
+
+void
+generate_old_dump(void)
+{
+ int dbnum;
+
+ prep_status("Creating dump of global objects");
+
+ /* run new pg_dumpall binary for globals */
+ exec_prog(UTILITY_LOG_FILE, NULL, true, true,
+ "\"%s/pg_dumpall\" %s --globals-only --quote-all-identifiers "
+ "--binary-upgrade %s -f \"%s/%s\"",
+ new_cluster.bindir, cluster_conn_opts(&old_cluster),
+ log_opts.verbose ? "--verbose" : "",
+ log_opts.dumpdir,
+ GLOBALS_DUMP_FILE);
+ check_ok();
+
+ prep_status_progress("Creating dump of database schemas");
+
+ /* create per-db dump files */
+ for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
+ {
+ char sql_file_name[MAXPGPATH],
+ log_file_name[MAXPGPATH];
+ DbInfo *old_db = &old_cluster.dbarr.dbs[dbnum];
+ PQExpBufferData connstr,
+ escaped_connstr;
+
+ initPQExpBuffer(&connstr);
+ appendPQExpBufferStr(&connstr, "dbname=");
+ appendConnStrVal(&connstr, old_db->db_name);
+ initPQExpBuffer(&escaped_connstr);
+ appendShellString(&escaped_connstr, connstr.data);
+ termPQExpBuffer(&connstr);
+
+ pg_log(PG_STATUS, "%s", old_db->db_name);
+ snprintf(sql_file_name, sizeof(sql_file_name), DB_DUMP_FILE_MASK, old_db->db_oid);
+ snprintf(log_file_name, sizeof(log_file_name), DB_DUMP_LOG_FILE_MASK, old_db->db_oid);
+
+ parallel_exec_prog(log_file_name, NULL,
+ "\"%s/pg_dump\" %s --schema-only --quote-all-identifiers "
+ "--binary-upgrade --format=custom %s --file=\"%s/%s\" %s",
+ new_cluster.bindir, cluster_conn_opts(&old_cluster),
+ log_opts.verbose ? "--verbose" : "",
+ log_opts.dumpdir,
+ sql_file_name, escaped_connstr.data);
+
+ termPQExpBuffer(&escaped_connstr);
+ }
+
+ /* reap all children */
+ while (reap_child(true) == true)
+ ;
+
+ end_progress_output();
+ check_ok();
+}