PostgreSQL Source Code  git master
dump.c
Go to the documentation of this file.
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 "fe_utils/string_utils.h"
13 #include "pg_upgrade.h"
14 
15 void
17 {
18  int dbnum;
19 
20  prep_status("Creating dump of global objects");
21 
22  /* run new pg_dumpall binary for globals */
23  exec_prog(UTILITY_LOG_FILE, NULL, true, true,
24  "\"%s/pg_dumpall\" %s --globals-only --quote-all-identifiers "
25  "--binary-upgrade %s -f %s",
27  log_opts.verbose ? "--verbose" : "",
29  check_ok();
30 
31  prep_status("Creating dump of database schemas\n");
32 
33  /* create per-db dump files */
34  for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
35  {
36  char sql_file_name[MAXPGPATH],
37  log_file_name[MAXPGPATH];
38  DbInfo *old_db = &old_cluster.dbarr.dbs[dbnum];
40  escaped_connstr;
41 
42  initPQExpBuffer(&connstr);
43  appendPQExpBufferStr(&connstr, "dbname=");
44  appendConnStrVal(&connstr, old_db->db_name);
45  initPQExpBuffer(&escaped_connstr);
46  appendShellString(&escaped_connstr, connstr.data);
47  termPQExpBuffer(&connstr);
48 
49  pg_log(PG_STATUS, "%s", old_db->db_name);
50  snprintf(sql_file_name, sizeof(sql_file_name), DB_DUMP_FILE_MASK, old_db->db_oid);
51  snprintf(log_file_name, sizeof(log_file_name), DB_DUMP_LOG_FILE_MASK, old_db->db_oid);
52 
53  parallel_exec_prog(log_file_name, NULL,
54  "\"%s/pg_dump\" %s --schema-only --quote-all-identifiers "
55  "--binary-upgrade --format=custom %s --file=\"%s\" %s",
57  log_opts.verbose ? "--verbose" : "",
58  sql_file_name, escaped_connstr.data);
59 
60  termPQExpBuffer(&escaped_connstr);
61  }
62 
63  /* reap all children */
64  while (reap_child(true) == true)
65  ;
66 
68  check_ok();
69 }
void parallel_exec_prog(const char *log_file, const char *opt_log_file, const char *fmt,...)
Definition: parallel.c:62
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
void end_progress_output(void)
Definition: util.c:43
void appendConnStrVal(PQExpBuffer buf, const char *str)
Definition: string_utils.c:545
PGresult char * cluster_conn_opts(ClusterInfo *cluster)
Definition: server.c:90
LogOpts log_opts
Definition: util.c:17
Oid db_oid
Definition: pg_upgrade.h:180
ClusterInfo new_cluster
Definition: pg_upgrade.c:59
#define MAXPGPATH
void prep_status(const char *fmt,...) pg_attribute_printf(1
ClusterInfo old_cluster
Definition: pg_upgrade.c:59
void generate_old_dump(void)
Definition: dump.c:16
static void check_ok(void)
Definition: initdb.c:2076
#define DB_DUMP_FILE_MASK
Definition: pg_upgrade.h:27
bool verbose
Definition: pg_upgrade.h:282
char * bindir
Definition: pg_upgrade.h:264
void appendShellString(PQExpBuffer buf, const char *str)
Definition: string_utils.c:429
DbInfoArr dbarr
Definition: pg_upgrade.h:260
void void pg_log(eLogType type, const char *fmt,...) pg_attribute_printf(2
#define DB_DUMP_LOG_FILE_MASK
Definition: pg_upgrade.h:29
bool reap_child(bool wait_for_child)
Definition: parallel.c:284
#define UTILITY_LOG_FILE
Definition: pg_upgrade.h:31
char * db_name
Definition: pg_upgrade.h:181
bool exec_prog(const char *log_file, const char *opt_log_file, bool report_error, bool exit_on_error, const char *fmt,...)
Definition: exec.c:80
#define GLOBALS_DUMP_FILE
Definition: pg_upgrade.h:26
DbInfo * dbs
Definition: pg_upgrade.h:192
#define snprintf
Definition: port.h:192
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
static char * connstr
Definition: pg_dumpall.c:61