20 #define DEF_PGUPORT 50432
22 #define MAX_STRING 1024
23 #define QUERY_ALLOC 8192
25 #define MESSAGE_WIDTH 60
27 #define GET_MAJOR_VERSION(v) ((v) / 100)
30 #define GLOBALS_DUMP_FILE "pg_upgrade_dump_globals.sql"
31 #define DB_DUMP_FILE_MASK "pg_upgrade_dump_%u.custom"
39 #define BASE_OUTPUTDIR "pg_upgrade_output.d"
40 #define LOG_OUTPUTDIR "log"
41 #define DUMP_OUTPUTDIR "dump"
43 #define DB_DUMP_LOG_FILE_MASK "pg_upgrade_dump_%u.log"
44 #define SERVER_LOG_FILE "pg_upgrade_server.log"
45 #define UTILITY_LOG_FILE "pg_upgrade_utility.log"
46 #define INTERNAL_LOG_FILE "pg_upgrade_internal.log"
67 #define SERVER_START_LOG_FILE SERVER_LOG_FILE
68 #define SERVER_STOP_LOG_FILE SERVER_LOG_FILE
70 #define SERVER_START_LOG_FILE "pg_upgrade_server_start.log"
76 #define SERVER_STOP_LOG_FILE UTILITY_LOG_FILE
81 #define pg_mv_file rename
82 #define PATH_SEPARATOR '/'
83 #define PATH_QUOTE '\''
84 #define RM_CMD "rm -f"
85 #define RMDIR_CMD "rm -rf"
86 #define SCRIPT_PREFIX "./"
87 #define SCRIPT_EXT "sh"
88 #define ECHO_QUOTE "'"
91 #define pg_mv_file pgrename
92 #define PATH_SEPARATOR '\\'
93 #define PATH_QUOTE '"'
94 /* @ prefix disables command echo in .bat files */
95 #define RM_CMD "@DEL /q"
96 #define RMDIR_CMD "@RMDIR /s/q"
97 #define SCRIPT_PREFIX ""
98 #define SCRIPT_EXT "bat"
99 #define EXE_EXT ".exe"
100 #define ECHO_QUOTE ""
101 #define ECHO_BLANK "."
106 * The format of visibility map was changed with this 9.6 commit.
108 #define VISIBILITY_MAP_FROZEN_BIT_CAT_VER 201603011
111 * pg_multixact format changed in 9.3 commit 0ac5ad5134f2769ccbaefec73844f85,
112 * ("Improve concurrency of foreign key locking") which also updated catalog
113 * version to this value. pg_upgrade behavior depends on whether old and new
114 * server versions are both newer than this, or only the new one is.
116 #define MULTIXACT_FORMATCHANGE_CAT_VER 201301231
119 * large object chunk size added to pg_controldata,
120 * commit 5f93c37805e7485488480916b4585e098d3cc883
122 #define LARGE_OBJECT_SIZE_PG_CONTROL_VER 942
125 * change in JSONB format during 9.4 beta
127 #define JSONB_FORMAT_CHANGE_CAT_VER 201409291
131 * Each relation is represented by a relinfo structure.
135 /* Can't use NAMEDATALEN; not guaranteed to be same on client */
136 char *nspname; /* namespace name */
137 char *relname; /* relation name */
138 Oid reloid; /* relation OID */
139 RelFileNumber relfilenumber; /* relation file number */
140 Oid indtable; /* if index, OID of its table, else 0 */
141 Oid toastheap; /* if toast table, OID of base table, else 0 */
142 char *tablespace; /* tablespace path; "" for cluster default */
143 bool nsp_alloc; /* should nspname be freed? */
144 bool tblsp_alloc; /* should tablespace be freed? */
154 * The following structure represents a relation mapping.
158 const char *old_tablespace;
159 const char *new_tablespace;
160 const char *old_tablespace_suffix;
161 const char *new_tablespace_suffix;
163 RelFileNumber relfilenumber;
164 /* the rest are used only for logging and error reporting */
165 char *nspname; /* namespaces */
170 * Structure to store database information
174 Oid db_oid; /* oid of the database */
175 char *db_name; /* database name */
176 char db_tablespace[MAXPGPATH]; /* database default tablespace
178 RelInfoArr rel_arr; /* array of all user relinfos */
182 * Locale information about a database.
188 char db_collprovider;
195 DbInfo *dbs; /* array of db infos */
196 int ndbs; /* number of db infos */
200 * The following structure is used to hold pg_control information.
201 * Rather than using the backend's control structure we use our own
202 * structure to avoid pg_control version issues between releases.
208 char nextxlogfile[25];
209 uint32 chkpnt_nxtxid;
210 uint32 chkpnt_nxtepoch;
211 uint32 chkpnt_nxtoid;
212 uint32 chkpnt_nxtmulti;
213 uint32 chkpnt_nxtmxoff;
214 uint32 chkpnt_oldstMulti;
215 uint32 chkpnt_oldstxid;
226 bool float8_pass_by_value;
227 uint32 data_checksum_version;
231 * Enumeration to denote transfer modes
241 * Enumeration to denote pg_log modes
246 PG_STATUS, /* these messages do not get a newline added */
247 PG_REPORT_NONL, /* these too */
257 * information about each cluster
261 ControlData controldata; /* pg_control information */
262 DbLocaleInfo *template0; /* template0 locale info */
263 DbInfoArr dbarr; /* dbinfos array */
264 char *pgdata; /* pathname for cluster's $PGDATA directory */
265 char *pgconfig; /* pathname for cluster's config file
267 char *bindir; /* pathname for cluster's executable directory */
268 char *pgopts; /* options to pass to the server, like pg_ctl
270 char *sockdir; /* directory for Unix Domain socket, if any */
271 unsigned short port; /* port number where postmaster is waiting */
272 uint32 major_version; /* PG_VERSION of cluster */
273 char major_version_str[64]; /* string PG_VERSION of cluster */
274 uint32 bin_version; /* version returned from pg_ctl */
275 const char *tablespace_suffix; /* directory specification */
284 FILE *internal; /* internal log FILE */
285 bool verbose; /* true -> be verbose in messages */
286 bool retain; /* retain log files on success */
287 /* Set of internal directories for output files */
288 char *rootdir; /* Root directory, aka pg_upgrade_output.d */
289 char *basedir; /* Base output directory, with timestamp */
290 char *dumpdir; /* Dumps */
291 char *logdir; /* Log files */
292 bool isatty; /* is stdout a tty */
301 bool check; /* true -> ask user for permission to make
303 bool do_sync; /* flush changes to disk */
304 transferMode transfer_mode; /* copy files or link them? */
305 int jobs; /* number of processes/threads to use */
306 char *socketdir; /* directory to use for Unix sockets */
320 const char *progname; /* complete pathname for this program */
321 char *user; /* username for clusters */
322 bool user_specified; /* user specified on command-line */
323 char **old_tablespaces; /* tablespaces */
324 int num_old_tablespaces;
325 LibraryInfo *libraries; /* loadable libraries */
327 ClusterInfo *running_cluster;
334 extern LogOpts log_opts;
335 extern UserOpts user_opts;
336 extern ClusterInfo old_cluster,
338 extern OSInfo os_info;
343 void output_check_banner(bool live_check);
344 void check_and_dump_old_cluster(bool live_check);
345 void check_new_cluster(void);
346 void report_clusters_compatible(void);
347 void issue_warnings_and_set_wal_level(void);
348 void output_completion_banner(char *deletion_script_file_name);
349 void check_cluster_versions(void);
350 void check_cluster_compatibility(bool live_check);
351 void create_script_for_old_cluster_deletion(char **deletion_script_file_name);
356 void get_control_data(ClusterInfo *cluster, bool live_check);
357 void check_control_data(ControlData *oldctrl, ControlData *newctrl);
358 void disable_old_cluster(void);
363 void generate_old_dump(void);
368 #define EXEC_PSQL_ARGS "--echo-queries --set ON_ERROR_STOP=on --no-psqlrc --dbname=template1"
370 bool exec_prog(const char *log_filename, const char *opt_log_file,
371 bool report_error, bool exit_on_error, const char *fmt,...) pg_attribute_printf(5, 6);
372 void verify_directories(void);
373 bool pid_lock_file_exists(const char *datadir);
378 void cloneFile(const char *src, const char *dst,
379 const char *schemaName, const char *relName);
380 void copyFile(const char *src, const char *dst,
381 const char *schemaName, const char *relName);
382 void linkFile(const char *src, const char *dst,
383 const char *schemaName, const char *relName);
384 void rewriteVisibilityMap(const char *fromfile, const char *tofile,
385 const char *schemaName, const char *relName);
386 void check_file_clone(void);
387 void check_hard_link(void);
389 /* fopen_priv() is no longer different from fopen() */
390 #define fopen_priv(path, mode) fopen(path, mode)
394 void get_loadable_libraries(void);
395 void check_loadable_libraries(void);
399 FileNameMap *gen_db_file_maps(DbInfo *old_db,
400 DbInfo *new_db, int *nmaps, const char *old_pgdata,
401 const char *new_pgdata);
402 void get_db_and_rel_infos(ClusterInfo *cluster);
406 void parseCommandLine(int argc, char *argv[]);
407 void adjust_data_dir(ClusterInfo *cluster);
408 void get_sock_dir(ClusterInfo *cluster, bool live_check);
410 /* relfilenumber.c */
412 void transfer_all_new_tablespaces(DbInfoArr *old_db_arr,
413 DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata);
414 void transfer_all_new_dbs(DbInfoArr *old_db_arr,
415 DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata,
416 char *old_tablespace);
420 void init_tablespaces(void);
425 PGconn *connectToServer(ClusterInfo *cluster, const char *db_name);
426 PGresult *executeQueryOrDie(PGconn *conn, const char *fmt,...) pg_attribute_printf(2, 3);
428 char *cluster_conn_opts(ClusterInfo *cluster);
430 bool start_postmaster(ClusterInfo *cluster, bool report_and_exit_on_error);
431 void stop_postmaster(bool in_atexit);
432 uint32 get_major_server_version(ClusterInfo *cluster);
433 void check_pghost_envvar(void);
438 char *quote_identifier(const char *s);
439 int get_user_info(char **user_name_p);
441 void report_status(eLogType type, const char *fmt,...) pg_attribute_printf(2, 3);
442 void pg_log(eLogType type, const char *fmt,...) pg_attribute_printf(2, 3);
443 void pg_fatal(const char *fmt,...) pg_attribute_printf(1, 2) pg_attribute_noreturn();
444 void end_progress_output(void);
445 void cleanup_output_dirs(void);
446 void prep_status(const char *fmt,...) pg_attribute_printf(1, 2);
447 void prep_status_progress(const char *fmt,...) pg_attribute_printf(1, 2);
448 unsigned int str2uint(const char *str);
453 bool check_for_data_types_usage(ClusterInfo *cluster,
454 const char *base_query,
455 const char *output_path);
456 bool check_for_data_type_usage(ClusterInfo *cluster,
457 const char *type_name,
458 const char *output_path);
459 void old_9_3_check_for_line_data_type_usage(ClusterInfo *cluster);
460 void old_9_6_check_for_unknown_data_type_usage(ClusterInfo *cluster);
461 void old_9_6_invalidate_hash_indexes(ClusterInfo *cluster,
464 void old_11_check_for_sql_identifier_data_type_usage(ClusterInfo *cluster);
465 void report_extension_updates(ClusterInfo *cluster);
468 void parallel_exec_prog(const char *log_file, const char *opt_log_file,
469 const char *fmt,...) pg_attribute_printf(3, 4);
470 void parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
471 char *old_pgdata, char *new_pgdata,
472 char *old_tablespace);
473 bool reap_child(bool wait_for_child);