1/*
2 * dump.c
3 *
4 * dump functions
5 *
6 * Copyright (c) 2010-2019, PostgreSQL Global Development Group
7 * src/bin/pg_upgrade/dump.c
8 */
9
10#include "postgres_fe.h"
11
12#include "pg_upgrade.h"
13
14#include "fe_utils/string_utils.h"
15
16
17void
18generate_old_dump(void)
19{
20 int dbnum;
21
22 prep_status("Creating dump of global objects");
23
24 /* run new pg_dumpall binary for globals */
25 exec_prog(UTILITY_LOG_FILE, NULL, true, true,
26 "\"%s/pg_dumpall\" %s --globals-only --quote-all-identifiers "
27 "--binary-upgrade %s -f %s",
28 new_cluster.bindir, cluster_conn_opts(&old_cluster),
29 log_opts.verbose ? "--verbose" : "",
30 GLOBALS_DUMP_FILE);
31 check_ok();
32
33 prep_status("Creating dump of database schemas\n");
34
35 /* create per-db dump files */
36 for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
37 {
38 char sql_file_name[MAXPGPATH],
39 log_file_name[MAXPGPATH];
40 DbInfo *old_db = &old_cluster.dbarr.dbs[dbnum];
41 PQExpBufferData connstr,
42 escaped_connstr;
43
44 initPQExpBuffer(&connstr);
45 appendPQExpBuffer(&connstr, "dbname=");
46 appendConnStrVal(&connstr, old_db->db_name);
47 initPQExpBuffer(&escaped_connstr);
48 appendShellString(&escaped_connstr, connstr.data);
49 termPQExpBuffer(&connstr);
50
51 pg_log(PG_STATUS, "%s", old_db->db_name);
52 snprintf(sql_file_name, sizeof(sql_file_name), DB_DUMP_FILE_MASK, old_db->db_oid);
53 snprintf(log_file_name, sizeof(log_file_name), DB_DUMP_LOG_FILE_MASK, old_db->db_oid);
54
55 parallel_exec_prog(log_file_name, NULL,
56 "\"%s/pg_dump\" %s --schema-only --quote-all-identifiers "
57 "--binary-upgrade --format=custom %s --file=\"%s\" %s",
58 new_cluster.bindir, cluster_conn_opts(&old_cluster),
59 log_opts.verbose ? "--verbose" : "",
60 sql_file_name, escaped_connstr.data);
61
62 termPQExpBuffer(&escaped_connstr);
63 }
64
65 /* reap all children */
66 while (reap_child(true) == true)
67 ;
68
69 end_progress_output();
70 check_ok();
71}
72