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