PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
dump.c
Go to the documentation of this file.
1 /*
2  * dump.c
3  *
4  * dump functions
5  *
6  * Copyright (c) 2010-2017, 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 
17 void
19 {
20  int dbnum;
21  mode_t old_umask;
22 
23  prep_status("Creating dump of global objects");
24 
25  /* run new pg_dumpall binary for globals */
27  "\"%s/pg_dumpall\" %s --globals-only --quote-all-identifiers "
28  "--binary-upgrade %s -f %s",
30  log_opts.verbose ? "--verbose" : "",
32  check_ok();
33 
34  prep_status("Creating dump of database schemas\n");
35 
36  /*
37  * Set umask for this function, all functions it calls, and all
38  * subprocesses/threads it creates. We can't use fopen_priv() as Windows
39  * uses threads and umask is process-global.
40  */
41  old_umask = umask(S_IRWXG | S_IRWXO);
42 
43  /* create per-db dump files */
44  for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
45  {
46  char sql_file_name[MAXPGPATH],
47  log_file_name[MAXPGPATH];
48  DbInfo *old_db = &old_cluster.dbarr.dbs[dbnum];
50  escaped_connstr;
51 
52  initPQExpBuffer(&connstr);
53  appendPQExpBuffer(&connstr, "dbname=");
54  appendConnStrVal(&connstr, old_db->db_name);
55  initPQExpBuffer(&escaped_connstr);
56  appendShellString(&escaped_connstr, connstr.data);
57  termPQExpBuffer(&connstr);
58 
59  pg_log(PG_STATUS, "%s", old_db->db_name);
60  snprintf(sql_file_name, sizeof(sql_file_name), DB_DUMP_FILE_MASK, old_db->db_oid);
61  snprintf(log_file_name, sizeof(log_file_name), DB_DUMP_LOG_FILE_MASK, old_db->db_oid);
62 
63  parallel_exec_prog(log_file_name, NULL,
64  "\"%s/pg_dump\" %s --schema-only --quote-all-identifiers "
65  "--binary-upgrade --format=custom %s --file=\"%s\" %s",
67  log_opts.verbose ? "--verbose" : "",
68  sql_file_name, escaped_connstr.data);
69 
70  termPQExpBuffer(&escaped_connstr);
71  }
72 
73  /* reap all children */
74  while (reap_child(true) == true)
75  ;
76 
77  umask(old_umask);
78 
80  check_ok();
81 }
void parallel_exec_prog(const char *log_file, const char *opt_log_file, const char *fmt,...)
Definition: parallel.c:63
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:128
void end_progress_output(void)
Definition: util.c:44
void appendConnStrVal(PQExpBuffer buf, const char *str)
Definition: string_utils.c:536
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
PGresult char * cluster_conn_opts(ClusterInfo *cluster)
Definition: server.c:88
LogOpts log_opts
Definition: util.c:18
Oid db_oid
Definition: pg_upgrade.h:184
ClusterInfo new_cluster
Definition: pg_upgrade.c:56
#define MAXPGPATH
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:262
void prep_status(const char *fmt,...) pg_attribute_printf(1
ClusterInfo old_cluster
Definition: pg_upgrade.c:56
void pg_log(eLogType type, const char *fmt,...)
Definition: logging.c:69
void generate_old_dump(void)
Definition: dump.c:18
static void check_ok(void)
Definition: initdb.c:2008
#define DB_DUMP_FILE_MASK
Definition: pg_upgrade.h:33
bool verbose
Definition: pg_upgrade.h:285
char * bindir
Definition: pg_upgrade.h:267
#define S_IRWXO
Definition: win32.h:484
void appendShellString(PQExpBuffer buf, const char *str)
Definition: string_utils.c:430
DbInfoArr dbarr
Definition: pg_upgrade.h:263
#define NULL
Definition: c.h:229
#define DB_DUMP_LOG_FILE_MASK
Definition: pg_upgrade.h:35
bool reap_child(bool wait_for_child)
Definition: parallel.c:290
#define S_IRWXG
Definition: win32.h:480
#define UTILITY_LOG_FILE
Definition: pg_upgrade.h:37
bool exec_prog(const char *log_file, const char *opt_log_file, bool throw_error, const char *fmt,...)
Definition: exec.c:77
char * db_name
Definition: pg_upgrade.h:185
#define GLOBALS_DUMP_FILE
Definition: pg_upgrade.h:32
DbInfo * dbs
Definition: pg_upgrade.h:196
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:89
static char * connstr
Definition: pg_dumpall.c:64