PostgreSQL Source Code  git master
pg_upgrade.c
Go to the documentation of this file.
1 /*
2  * pg_upgrade.c
3  *
4  * main source file
5  *
6  * Copyright (c) 2010-2020, PostgreSQL Global Development Group
7  * src/bin/pg_upgrade/pg_upgrade.c
8  */
9 
10 /*
11  * To simplify the upgrade process, we force certain system values to be
12  * identical between old and new clusters:
13  *
14  * We control all assignments of pg_class.oid (and relfilenode) so toast
15  * oids are the same between old and new clusters. This is important
16  * because toast oids are stored as toast pointers in user tables.
17  *
18  * While pg_class.oid and pg_class.relfilenode are initially the same
19  * in a cluster, they can diverge due to CLUSTER, REINDEX, or VACUUM
20  * FULL. In the new cluster, pg_class.oid and pg_class.relfilenode will
21  * be the same and will match the old pg_class.oid value. Because of
22  * this, old/new pg_class.relfilenode values will not match if CLUSTER,
23  * REINDEX, or VACUUM FULL have been performed in the old cluster.
24  *
25  * We control all assignments of pg_type.oid because these oids are stored
26  * in user composite type values.
27  *
28  * We control all assignments of pg_enum.oid because these oids are stored
29  * in user tables as enum values.
30  *
31  * We control all assignments of pg_authid.oid for historical reasons (the
32  * oids used to be stored in pg_largeobject_metadata, which is now copied via
33  * SQL commands), that might change at some point in the future.
34  */
35 
36 
37 
38 #include "postgres_fe.h"
39 
40 #ifdef HAVE_LANGINFO_H
41 #include <langinfo.h>
42 #endif
43 
44 #include "catalog/pg_class_d.h"
45 #include "common/file_perm.h"
46 #include "common/logging.h"
48 #include "fe_utils/string_utils.h"
49 #include "pg_upgrade.h"
50 
51 static void prepare_new_cluster(void);
52 static void prepare_new_globals(void);
53 static void create_new_objects(void);
54 static void copy_xact_xlog_xid(void);
55 static void set_frozenxids(bool minmxid_only);
56 static void setup(char *argv0, bool *live_check);
57 static void cleanup(void);
58 
62 
63 char *output_files[] = {
65 #ifdef WIN32
66  /* unique file for pg_ctl start */
68 #endif
71  NULL
72 };
73 
74 
75 int
76 main(int argc, char **argv)
77 {
78  char *deletion_script_file_name = NULL;
79  bool live_check = false;
80 
81  pg_logging_init(argv[0]);
82  set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_upgrade"));
83 
84  /* Set default restrictive mask until new cluster permissions are read */
85  umask(PG_MODE_MASK_OWNER);
86 
87  parseCommandLine(argc, argv);
88 
90 
91  adjust_data_dir(&old_cluster);
92  adjust_data_dir(&new_cluster);
93 
94  setup(argv[0], &live_check);
95 
96  output_check_banner(live_check);
97 
99 
100  get_sock_dir(&old_cluster, live_check);
101  get_sock_dir(&new_cluster, false);
102 
103  check_cluster_compatibility(live_check);
104 
105  /* Set mask based on PGDATA permissions */
106  if (!GetDataDirectoryCreatePerm(new_cluster.pgdata))
107  pg_fatal("could not read permissions of directory \"%s\": %s\n",
108  new_cluster.pgdata, strerror(errno));
109 
110  umask(pg_mode_mask);
111 
112  check_and_dump_old_cluster(live_check);
113 
114 
115  /* -- NEW -- */
116  start_postmaster(&new_cluster, true);
117 
120 
122  "\n"
123  "Performing Upgrade\n"
124  "------------------\n");
125 
127 
128  stop_postmaster(false);
129 
130  /*
131  * Destructive Changes to New Cluster
132  */
133 
135 
136  /* New now using xids of the old system */
137 
138  /* -- NEW -- */
139  start_postmaster(&new_cluster, true);
140 
142 
144 
145  stop_postmaster(false);
146 
147  /*
148  * Most failures happen in create_new_objects(), which has completed at
149  * this point. We do this here because it is just before linking, which
150  * will link the old and new cluster data files, preventing the old
151  * cluster from being safely started once the new cluster is started.
152  */
155 
156  transfer_all_new_tablespaces(&old_cluster.dbarr, &new_cluster.dbarr,
157  old_cluster.pgdata, new_cluster.pgdata);
158 
159  /*
160  * Assuming OIDs are only used in system tables, there is no need to
161  * restore the OID counter because we have not transferred any OIDs from
162  * the old system, but we do it anyway just in case. We do it late here
163  * because there is no need to have the schema load use new oids.
164  */
165  prep_status("Setting next OID for new cluster");
166  exec_prog(UTILITY_LOG_FILE, NULL, true, true,
167  "\"%s/pg_resetwal\" -o %u \"%s\"",
168  new_cluster.bindir, old_cluster.controldata.chkpnt_nxtoid,
169  new_cluster.pgdata);
170  check_ok();
171 
172  prep_status("Sync data directory to disk");
173  exec_prog(UTILITY_LOG_FILE, NULL, true, true,
174  "\"%s/initdb\" --sync-only \"%s\"", new_cluster.bindir,
175  new_cluster.pgdata);
176  check_ok();
177 
178  create_script_for_old_cluster_deletion(&deletion_script_file_name);
179 
181 
183  "\n"
184  "Upgrade Complete\n"
185  "----------------\n");
186 
187  output_completion_banner(deletion_script_file_name);
188 
189  pg_free(deletion_script_file_name);
190 
191  cleanup();
192 
193  return 0;
194 }
195 
196 
197 static void
198 setup(char *argv0, bool *live_check)
199 {
200  /*
201  * make sure the user has a clean environment, otherwise, we may confuse
202  * libpq when we connect to one (or both) of the servers.
203  */
205 
206  /*
207  * In case the user hasn't specified the directory for the new binaries
208  * with -B, default to using the path of the currently executed pg_upgrade
209  * binary.
210  */
211  if (!new_cluster.bindir)
212  {
213  char exec_path[MAXPGPATH];
214 
215  if (find_my_exec(argv0, exec_path) < 0)
216  pg_fatal("%s: could not find own program executable\n", argv0);
217  /* Trim off program name and keep just path */
218  *last_dir_separator(exec_path) = '\0';
219  canonicalize_path(exec_path);
220  new_cluster.bindir = pg_strdup(exec_path);
221  }
222 
224 
225  /* no postmasters should be running, except for a live check */
226  if (pid_lock_file_exists(old_cluster.pgdata))
227  {
228  /*
229  * If we have a postmaster.pid file, try to start the server. If it
230  * starts, the pid file was stale, so stop the server. If it doesn't
231  * start, assume the server is running. If the pid file is left over
232  * from a server crash, this also allows any committed transactions
233  * stored in the WAL to be replayed so they are not lost, because WAL
234  * files are not transferred from old to new servers. We later check
235  * for a clean shutdown.
236  */
237  if (start_postmaster(&old_cluster, false))
238  stop_postmaster(false);
239  else
240  {
241  if (!user_opts.check)
242  pg_fatal("There seems to be a postmaster servicing the old cluster.\n"
243  "Please shutdown that postmaster and try again.\n");
244  else
245  *live_check = true;
246  }
247  }
248 
249  /* same goes for the new postmaster */
250  if (pid_lock_file_exists(new_cluster.pgdata))
251  {
252  if (start_postmaster(&new_cluster, false))
253  stop_postmaster(false);
254  else
255  pg_fatal("There seems to be a postmaster servicing the new cluster.\n"
256  "Please shutdown that postmaster and try again.\n");
257  }
258 }
259 
260 
261 static void
263 {
264  /*
265  * It would make more sense to freeze after loading the schema, but that
266  * would cause us to lose the frozenxids restored by the load. We use
267  * --analyze so autovacuum doesn't update statistics later
268  */
269  prep_status("Analyzing all rows in the new cluster");
270  exec_prog(UTILITY_LOG_FILE, NULL, true, true,
271  "\"%s/vacuumdb\" %s --all --analyze %s",
272  new_cluster.bindir, cluster_conn_opts(&new_cluster),
273  log_opts.verbose ? "--verbose" : "");
274  check_ok();
275 
276  /*
277  * We do freeze after analyze so pg_statistic is also frozen. template0 is
278  * not frozen here, but data rows were frozen by initdb, and we set its
279  * datfrozenxid, relfrozenxids, and relminmxid later to match the new xid
280  * counter later.
281  */
282  prep_status("Freezing all rows in the new cluster");
283  exec_prog(UTILITY_LOG_FILE, NULL, true, true,
284  "\"%s/vacuumdb\" %s --all --freeze %s",
285  new_cluster.bindir, cluster_conn_opts(&new_cluster),
286  log_opts.verbose ? "--verbose" : "");
287  check_ok();
288 }
289 
290 
291 static void
293 {
294  /*
295  * Before we restore anything, set frozenxids of initdb-created tables.
296  */
297  set_frozenxids(false);
298 
299  /*
300  * Now restore global objects (roles and tablespaces).
301  */
302  prep_status("Restoring global objects in the new cluster");
303 
304  exec_prog(UTILITY_LOG_FILE, NULL, true, true,
305  "\"%s/psql\" " EXEC_PSQL_ARGS " %s -f \"%s\"",
306  new_cluster.bindir, cluster_conn_opts(&new_cluster),
308  check_ok();
309 }
310 
311 
312 static void
314 {
315  int dbnum;
316 
317  prep_status("Restoring database schemas in the new cluster\n");
318 
319  /*
320  * We cannot process the template1 database concurrently with others,
321  * because when it's transiently dropped, connection attempts would fail.
322  * So handle it in a separate non-parallelized pass.
323  */
324  for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
325  {
326  char sql_file_name[MAXPGPATH],
327  log_file_name[MAXPGPATH];
328  DbInfo *old_db = &old_cluster.dbarr.dbs[dbnum];
329  const char *create_opts;
330 
331  /* Process only template1 in this pass */
332  if (strcmp(old_db->db_name, "template1") != 0)
333  continue;
334 
335  pg_log(PG_STATUS, "%s", old_db->db_name);
336  snprintf(sql_file_name, sizeof(sql_file_name), DB_DUMP_FILE_MASK, old_db->db_oid);
337  snprintf(log_file_name, sizeof(log_file_name), DB_DUMP_LOG_FILE_MASK, old_db->db_oid);
338 
339  /*
340  * template1 database will already exist in the target installation,
341  * so tell pg_restore to drop and recreate it; otherwise we would fail
342  * to propagate its database-level properties.
343  */
344  create_opts = "--clean --create";
345 
346  exec_prog(log_file_name,
347  NULL,
348  true,
349  true,
350  "\"%s/pg_restore\" %s %s --exit-on-error --verbose "
351  "--dbname postgres \"%s\"",
352  new_cluster.bindir,
353  cluster_conn_opts(&new_cluster),
354  create_opts,
355  sql_file_name);
356 
357  break; /* done once we've processed template1 */
358  }
359 
360  for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
361  {
362  char sql_file_name[MAXPGPATH],
363  log_file_name[MAXPGPATH];
364  DbInfo *old_db = &old_cluster.dbarr.dbs[dbnum];
365  const char *create_opts;
366 
367  /* Skip template1 in this pass */
368  if (strcmp(old_db->db_name, "template1") == 0)
369  continue;
370 
371  pg_log(PG_STATUS, "%s", old_db->db_name);
372  snprintf(sql_file_name, sizeof(sql_file_name), DB_DUMP_FILE_MASK, old_db->db_oid);
373  snprintf(log_file_name, sizeof(log_file_name), DB_DUMP_LOG_FILE_MASK, old_db->db_oid);
374 
375  /*
376  * postgres database will already exist in the target installation, so
377  * tell pg_restore to drop and recreate it; otherwise we would fail to
378  * propagate its database-level properties.
379  */
380  if (strcmp(old_db->db_name, "postgres") == 0)
381  create_opts = "--clean --create";
382  else
383  create_opts = "--create";
384 
385  parallel_exec_prog(log_file_name,
386  NULL,
387  "\"%s/pg_restore\" %s %s --exit-on-error --verbose "
388  "--dbname template1 \"%s\"",
389  new_cluster.bindir,
390  cluster_conn_opts(&new_cluster),
391  create_opts,
392  sql_file_name);
393  }
394 
395  /* reap all children */
396  while (reap_child(true) == true)
397  ;
398 
400  check_ok();
401 
402  /*
403  * We don't have minmxids for databases or relations in pre-9.3 clusters,
404  * so set those after we have restored the schema.
405  */
406  if (GET_MAJOR_VERSION(old_cluster.major_version) <= 902)
407  set_frozenxids(true);
408 
409  /* update new_cluster info now that we have objects in the databases */
410  get_db_and_rel_infos(&new_cluster);
411 }
412 
413 /*
414  * Delete the given subdirectory contents from the new cluster
415  */
416 static void
417 remove_new_subdir(const char *subdir, bool rmtopdir)
418 {
419  char new_path[MAXPGPATH];
420 
421  prep_status("Deleting files from new %s", subdir);
422 
423  snprintf(new_path, sizeof(new_path), "%s/%s", new_cluster.pgdata, subdir);
424  if (!rmtree(new_path, rmtopdir))
425  pg_fatal("could not delete directory \"%s\"\n", new_path);
426 
427  check_ok();
428 }
429 
430 /*
431  * Copy the files from the old cluster into it
432  */
433 static void
434 copy_subdir_files(const char *old_subdir, const char *new_subdir)
435 {
436  char old_path[MAXPGPATH];
437  char new_path[MAXPGPATH];
438 
439  remove_new_subdir(new_subdir, true);
440 
441  snprintf(old_path, sizeof(old_path), "%s/%s", old_cluster.pgdata, old_subdir);
442  snprintf(new_path, sizeof(new_path), "%s/%s", new_cluster.pgdata, new_subdir);
443 
444  prep_status("Copying old %s to new server", old_subdir);
445 
446  exec_prog(UTILITY_LOG_FILE, NULL, true, true,
447 #ifndef WIN32
448  "cp -Rf \"%s\" \"%s\"",
449 #else
450  /* flags: everything, no confirm, quiet, overwrite read-only */
451  "xcopy /e /y /q /r \"%s\" \"%s\\\"",
452 #endif
453  old_path, new_path);
454 
455  check_ok();
456 }
457 
458 static void
460 {
461  /*
462  * Copy old commit logs to new data dir. pg_clog has been renamed to
463  * pg_xact in post-10 clusters.
464  */
466  "pg_clog" : "pg_xact",
467  GET_MAJOR_VERSION(new_cluster.major_version) <= 906 ?
468  "pg_clog" : "pg_xact");
469 
470  /* set the next transaction id and epoch of the new cluster */
471  prep_status("Setting next transaction ID and epoch for new cluster");
472  exec_prog(UTILITY_LOG_FILE, NULL, true, true,
473  "\"%s/pg_resetwal\" -f -x %u \"%s\"",
474  new_cluster.bindir, old_cluster.controldata.chkpnt_nxtxid,
475  new_cluster.pgdata);
476  exec_prog(UTILITY_LOG_FILE, NULL, true, true,
477  "\"%s/pg_resetwal\" -f -e %u \"%s\"",
478  new_cluster.bindir, old_cluster.controldata.chkpnt_nxtepoch,
479  new_cluster.pgdata);
480  /* must reset commit timestamp limits also */
481  exec_prog(UTILITY_LOG_FILE, NULL, true, true,
482  "\"%s/pg_resetwal\" -f -c %u,%u \"%s\"",
483  new_cluster.bindir,
484  old_cluster.controldata.chkpnt_nxtxid,
485  old_cluster.controldata.chkpnt_nxtxid,
486  new_cluster.pgdata);
487  check_ok();
488 
489  /*
490  * If the old server is before the MULTIXACT_FORMATCHANGE_CAT_VER change
491  * (see pg_upgrade.h) and the new server is after, then we don't copy
492  * pg_multixact files, but we need to reset pg_control so that the new
493  * server doesn't attempt to read multis older than the cutoff value.
494  */
497  {
498  copy_subdir_files("pg_multixact/offsets", "pg_multixact/offsets");
499  copy_subdir_files("pg_multixact/members", "pg_multixact/members");
500 
501  prep_status("Setting next multixact ID and offset for new cluster");
502 
503  /*
504  * we preserve all files and contents, so we must preserve both "next"
505  * counters here and the oldest multi present on system.
506  */
507  exec_prog(UTILITY_LOG_FILE, NULL, true, true,
508  "\"%s/pg_resetwal\" -O %u -m %u,%u \"%s\"",
509  new_cluster.bindir,
510  old_cluster.controldata.chkpnt_nxtmxoff,
511  old_cluster.controldata.chkpnt_nxtmulti,
512  old_cluster.controldata.chkpnt_oldstMulti,
513  new_cluster.pgdata);
514  check_ok();
515  }
516  else if (new_cluster.controldata.cat_ver >= MULTIXACT_FORMATCHANGE_CAT_VER)
517  {
518  /*
519  * Remove offsets/0000 file created by initdb that no longer matches
520  * the new multi-xid value. "members" starts at zero so no need to
521  * remove it.
522  */
523  remove_new_subdir("pg_multixact/offsets", false);
524 
525  prep_status("Setting oldest multixact ID in new cluster");
526 
527  /*
528  * We don't preserve files in this case, but it's important that the
529  * oldest multi is set to the latest value used by the old system, so
530  * that multixact.c returns the empty set for multis that might be
531  * present on disk. We set next multi to the value following that; it
532  * might end up wrapped around (i.e. 0) if the old cluster had
533  * next=MaxMultiXactId, but multixact.c can cope with that just fine.
534  */
535  exec_prog(UTILITY_LOG_FILE, NULL, true, true,
536  "\"%s/pg_resetwal\" -m %u,%u \"%s\"",
537  new_cluster.bindir,
538  old_cluster.controldata.chkpnt_nxtmulti + 1,
539  old_cluster.controldata.chkpnt_nxtmulti,
540  new_cluster.pgdata);
541  check_ok();
542  }
543 
544  /* now reset the wal archives in the new cluster */
545  prep_status("Resetting WAL archives");
546  exec_prog(UTILITY_LOG_FILE, NULL, true, true,
547  /* use timeline 1 to match controldata and no WAL history file */
548  "\"%s/pg_resetwal\" -l 00000001%s \"%s\"", new_cluster.bindir,
549  old_cluster.controldata.nextxlogfile + 8,
550  new_cluster.pgdata);
551  check_ok();
552 }
553 
554 
555 /*
556  * set_frozenxids()
557  *
558  * This is called on the new cluster before we restore anything, with
559  * minmxid_only = false. Its purpose is to ensure that all initdb-created
560  * vacuumable tables have relfrozenxid/relminmxid matching the old cluster's
561  * xid/mxid counters. We also initialize the datfrozenxid/datminmxid of the
562  * built-in databases to match.
563  *
564  * As we create user tables later, their relfrozenxid/relminmxid fields will
565  * be restored properly by the binary-upgrade restore script. Likewise for
566  * user-database datfrozenxid/datminmxid. However, if we're upgrading from a
567  * pre-9.3 database, which does not store per-table or per-DB minmxid, then
568  * the relminmxid/datminmxid values filled in by the restore script will just
569  * be zeroes.
570  *
571  * Hence, with a pre-9.3 source database, a second call occurs after
572  * everything is restored, with minmxid_only = true. This pass will
573  * initialize all tables and databases, both those made by initdb and user
574  * objects, with the desired minmxid value. frozenxid values are left alone.
575  */
576 static void
577 set_frozenxids(bool minmxid_only)
578 {
579  int dbnum;
580  PGconn *conn,
581  *conn_template1;
582  PGresult *dbres;
583  int ntups;
584  int i_datname;
585  int i_datallowconn;
586 
587  if (!minmxid_only)
588  prep_status("Setting frozenxid and minmxid counters in new cluster");
589  else
590  prep_status("Setting minmxid counter in new cluster");
591 
592  conn_template1 = connectToServer(&new_cluster, "template1");
593 
594  if (!minmxid_only)
595  /* set pg_database.datfrozenxid */
596  PQclear(executeQueryOrDie(conn_template1,
597  "UPDATE pg_catalog.pg_database "
598  "SET datfrozenxid = '%u'",
599  old_cluster.controldata.chkpnt_nxtxid));
600 
601  /* set pg_database.datminmxid */
602  PQclear(executeQueryOrDie(conn_template1,
603  "UPDATE pg_catalog.pg_database "
604  "SET datminmxid = '%u'",
605  old_cluster.controldata.chkpnt_nxtmulti));
606 
607  /* get database names */
608  dbres = executeQueryOrDie(conn_template1,
609  "SELECT datname, datallowconn "
610  "FROM pg_catalog.pg_database");
611 
612  i_datname = PQfnumber(dbres, "datname");
613  i_datallowconn = PQfnumber(dbres, "datallowconn");
614 
615  ntups = PQntuples(dbres);
616  for (dbnum = 0; dbnum < ntups; dbnum++)
617  {
618  char *datname = PQgetvalue(dbres, dbnum, i_datname);
619  char *datallowconn = PQgetvalue(dbres, dbnum, i_datallowconn);
620 
621  /*
622  * We must update databases where datallowconn = false, e.g.
623  * template0, because autovacuum increments their datfrozenxids,
624  * relfrozenxids, and relminmxid even if autovacuum is turned off, and
625  * even though all the data rows are already frozen. To enable this,
626  * we temporarily change datallowconn.
627  */
628  if (strcmp(datallowconn, "f") == 0)
629  PQclear(executeQueryOrDie(conn_template1,
630  "ALTER DATABASE %s ALLOW_CONNECTIONS = true",
631  quote_identifier(datname)));
632 
633  conn = connectToServer(&new_cluster, datname);
634 
635  if (!minmxid_only)
636  /* set pg_class.relfrozenxid */
638  "UPDATE pg_catalog.pg_class "
639  "SET relfrozenxid = '%u' "
640  /* only heap, materialized view, and TOAST are vacuumed */
641  "WHERE relkind IN ("
642  CppAsString2(RELKIND_RELATION) ", "
643  CppAsString2(RELKIND_MATVIEW) ", "
644  CppAsString2(RELKIND_TOASTVALUE) ")",
645  old_cluster.controldata.chkpnt_nxtxid));
646 
647  /* set pg_class.relminmxid */
649  "UPDATE pg_catalog.pg_class "
650  "SET relminmxid = '%u' "
651  /* only heap, materialized view, and TOAST are vacuumed */
652  "WHERE relkind IN ("
653  CppAsString2(RELKIND_RELATION) ", "
654  CppAsString2(RELKIND_MATVIEW) ", "
655  CppAsString2(RELKIND_TOASTVALUE) ")",
656  old_cluster.controldata.chkpnt_nxtmulti));
657  PQfinish(conn);
658 
659  /* Reset datallowconn flag */
660  if (strcmp(datallowconn, "f") == 0)
661  PQclear(executeQueryOrDie(conn_template1,
662  "ALTER DATABASE %s ALLOW_CONNECTIONS = false",
663  quote_identifier(datname)));
664  }
665 
666  PQclear(dbres);
667 
668  PQfinish(conn_template1);
669 
670  check_ok();
671 }
672 
673 
674 static void
675 cleanup(void)
676 {
677  fclose(log_opts.internal);
678 
679  /* Remove dump and log files? */
680  if (!log_opts.retain)
681  {
682  int dbnum;
683  char **filename;
684 
685  for (filename = output_files; *filename != NULL; filename++)
686  unlink(*filename);
687 
688  /* remove dump files */
689  unlink(GLOBALS_DUMP_FILE);
690 
691  if (old_cluster.dbarr.dbs)
692  for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
693  {
694  char sql_file_name[MAXPGPATH],
695  log_file_name[MAXPGPATH];
696  DbInfo *old_db = &old_cluster.dbarr.dbs[dbnum];
697 
698  snprintf(sql_file_name, sizeof(sql_file_name), DB_DUMP_FILE_MASK, old_db->db_oid);
699  unlink(sql_file_name);
700 
701  snprintf(log_file_name, sizeof(log_file_name), DB_DUMP_LOG_FILE_MASK, old_db->db_oid);
702  unlink(log_file_name);
703  }
704  }
705 }
void transfer_all_new_tablespaces(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata)
Definition: relfilenode.c:29
void parallel_exec_prog(const char *log_file, const char *opt_log_file, const char *fmt,...)
Definition: parallel.c:62
static void remove_new_subdir(const char *subdir, bool rmtopdir)
Definition: pg_upgrade.c:417
void parseCommandLine(int argc, char *argv[])
Definition: option.c:39
static char * argv0
Definition: pg_ctl.c:97
uint32 major_version
Definition: pg_upgrade.h:267
static void cleanup(void)
Definition: pg_upgrade.c:675
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10934
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3163
ControlData controldata
Definition: pg_upgrade.h:257
void check_cluster_versions(void)
Definition: check.c:271
static void prepare_new_cluster(void)
Definition: pg_upgrade.c:262
void get_sock_dir(ClusterInfo *cluster, bool live_check)
Definition: option.c:476
bool pid_lock_file_exists(const char *datadir)
Definition: exec.c:219
static void create_new_objects(void)
Definition: pg_upgrade.c:313
void get_restricted_token(void)
uint32 chkpnt_nxtoid
Definition: pg_upgrade.h:206
void pg_logging_init(const char *argv0)
Definition: logging.c:81
PGresult * executeQueryOrDie(PGconn *conn, const char *fmt,...) pg_attribute_printf(2
#define GET_MAJOR_VERSION(v)
Definition: pg_upgrade.h:23
char nextxlogfile[25]
Definition: pg_upgrade.h:203
void end_progress_output(void)
Definition: util.c:43
void canonicalize_path(char *path)
Definition: path.c:254
void output_completion_banner(char *deletion_script_file_name)
Definition: check.c:237
#define pg_fatal(...)
Definition: pg_rewind.h:37
void PQfinish(PGconn *conn)
Definition: fe-connect.c:4174
NameData datname
Definition: pg_database.h:35
void check_cluster_compatibility(bool live_check)
Definition: check.c:313
PGresult char * cluster_conn_opts(ClusterInfo *cluster)
Definition: server.c:90
LogOpts log_opts
Definition: util.c:17
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2769
static void adjust_data_dir(void)
Definition: pg_ctl.c:2177
Oid db_oid
Definition: pg_upgrade.h:178
ClusterInfo new_cluster
Definition: pg_upgrade.c:59
uint32 chkpnt_nxtmxoff
Definition: pg_upgrade.h:208
bool datallowconn
Definition: pg_database.h:53
void check_pghost_envvar(void)
Definition: server.c:357
uint32 chkpnt_nxtxid
Definition: pg_upgrade.h:204
static void prepare_new_globals(void)
Definition: pg_upgrade.c:292
PGconn * conn
Definition: streamutil.c:54
uint32 chkpnt_nxtepoch
Definition: pg_upgrade.h:205
void output_check_banner(bool live_check)
Definition: check.c:63
#define MAXPGPATH
int find_my_exec(const char *argv0, char *retpath)
Definition: exec.c:128
char * output_files[]
Definition: pg_upgrade.c:63
void prep_status(const char *fmt,...) pg_attribute_printf(1
ClusterInfo old_cluster
Definition: pg_upgrade.c:59
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static void check_ok(void)
Definition: initdb.c:2018
#define DB_DUMP_FILE_MASK
Definition: pg_upgrade.h:27
PGconn * connectToServer(ClusterInfo *cluster, const char *db_name)
Definition: server.c:27
void create_script_for_old_cluster_deletion(char **deletion_script_file_name)
Definition: check.c:504
transferMode transfer_mode
Definition: pg_upgrade.h:292
uint32 chkpnt_oldstMulti
Definition: pg_upgrade.h:209
UserOpts user_opts
Definition: option.c:30
static void copy_subdir_files(const char *old_subdir, const char *new_subdir)
Definition: pg_upgrade.c:434
bool verbose
Definition: pg_upgrade.h:280
char * bindir
Definition: pg_upgrade.h:262
bool rmtree(const char *path, bool rmtopdir)
Definition: rmtree.c:42
#define CppAsString2(x)
Definition: c.h:277
uint32 cat_ver
Definition: pg_upgrade.h:202
#define PG_TEXTDOMAIN(domain)
Definition: c.h:1211
uint32 chkpnt_nxtmulti
Definition: pg_upgrade.h:207
static void set_frozenxids(bool minmxid_only)
Definition: pg_upgrade.c:577
#define PG_MODE_MASK_OWNER
Definition: file_perm.h:24
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:2877
static void setup(char *argv0, bool *live_check)
Definition: pg_upgrade.c:198
void stop_postmaster(bool in_atexit)
Definition: server.c:330
#define INTERNAL_LOG_FILE
Definition: pg_upgrade.h:32
char * last_dir_separator(const char *filename)
Definition: path.c:138
void PQclear(PGresult *res)
Definition: fe-exec.c:694
#define SERVER_LOG_FILE
Definition: pg_upgrade.h:30
DbInfoArr dbarr
Definition: pg_upgrade.h:258
void void pg_log(eLogType type, const char *fmt,...) pg_attribute_printf(2
void get_db_and_rel_infos(ClusterInfo *cluster)
Definition: info.c:309
void verify_directories(void)
Definition: exec.c:250
FILE * internal
Definition: pg_upgrade.h:279
int main(int argc, char **argv)
Definition: pg_upgrade.c:76
#define strerror
Definition: port.h:228
static char * exec_path
Definition: pg_ctl.c:92
bool check
Definition: pg_upgrade.h:290
void pg_free(void *ptr)
Definition: fe_memutils.c:105
#define MULTIXACT_FORMATCHANGE_CAT_VER
Definition: pg_upgrade.h:113
#define DB_DUMP_LOG_FILE_MASK
Definition: pg_upgrade.h:29
bool reap_child(bool wait_for_child)
Definition: parallel.c:284
static pgpid_t start_postmaster(void)
Definition: pg_ctl.c:443
#define SERVER_START_LOG_FILE
Definition: pg_upgrade.h:53
#define UTILITY_LOG_FILE
Definition: pg_upgrade.h:31
bool GetDataDirectoryCreatePerm(const char *dataDir)
static char * filename
Definition: pg_dumpall.c:91
char * pgdata
Definition: pg_upgrade.h:259
void set_pglocale_pgservice(const char *argv0, const char *app)
Definition: exec.c:434
void disable_old_cluster(void)
Definition: controldata.c:676
#define EXEC_PSQL_ARGS
Definition: pg_upgrade.h:357
OSInfo os_info
Definition: pg_upgrade.c:61
char * db_name
Definition: pg_upgrade.h:179
void check_new_cluster(void)
Definition: check.c:167
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
void check_and_dump_old_cluster(bool live_check)
Definition: check.c:81
void report_clusters_compatible(void)
Definition: check.c:197
void issue_warnings_and_set_wal_level(void)
Definition: check.c:214
DbInfo * dbs
Definition: pg_upgrade.h:190
bool retain
Definition: pg_upgrade.h:281
#define snprintf
Definition: port.h:215
int pg_mode_mask
Definition: file_perm.c:25
static void copy_xact_xlog_xid(void)
Definition: pg_upgrade.c:459