43 bool got_log_id =
false;
44 bool got_log_seg =
false;
47 bool got_multi =
false;
48 bool got_oldestmulti =
false;
49 bool got_oldestxid =
false;
50 bool got_mxoff =
false;
51 bool got_nextxlogfile =
false;
52 bool got_float8_pass_by_value =
false;
53 bool got_align =
false;
54 bool got_blocksz =
false;
55 bool got_largesz =
false;
56 bool got_walsz =
false;
57 bool got_walseg =
false;
58 bool got_ident =
false;
59 bool got_index =
false;
60 bool got_toast =
false;
61 bool got_large_object =
false;
62 bool got_date_is_int =
false;
63 bool got_data_checksum_version =
false;
64 bool got_cluster_state =
false;
71 char *language = NULL;
84 if (getenv(
"LC_COLLATE"))
86 if (getenv(
"LC_CTYPE"))
88 if (getenv(
"LC_MONETARY"))
90 if (getenv(
"LC_NUMERIC"))
92 if (getenv(
"LC_TIME"))
96 if (getenv(
"LANGUAGE"))
100 if (getenv(
"LC_MESSAGES"))
116 setenv(
"LC_MESSAGES",
"C", 1);
124 snprintf(cmd,
sizeof(cmd),
"\"%s/pg_controldata\" \"%s\"",
128 if ((
output = popen(cmd,
"r")) == NULL)
129 pg_fatal(
"could not get control data using %s: %s",
133 while (fgets(bufin,
sizeof(bufin),
output))
135 if ((p = strstr(bufin,
"Database cluster state:")) != NULL)
139 if (p == NULL || strlen(p) <= 1)
140 pg_fatal(
"%d: database cluster state problem", __LINE__);
156 if (strcmp(p,
"shut down in recovery") == 0)
159 pg_fatal(
"The source cluster was shut down while in recovery mode. To upgrade, use \"rsync\" as documented or shut it down as a primary.");
161 pg_fatal(
"The target cluster was shut down while in recovery mode. To upgrade, use \"rsync\" as documented or shut it down as a primary.");
163 else if (strcmp(p,
"shut down") != 0)
166 pg_fatal(
"The source cluster was not shut down cleanly, state reported as: \"%s\"", p);
168 pg_fatal(
"The target cluster was not shut down cleanly, state reported as: \"%s\"", p);
170 got_cluster_state =
true;
176 pg_fatal(
"could not get control data using %s: %s",
179 if (!got_cluster_state)
182 pg_fatal(
"The source cluster lacks cluster state information:");
184 pg_fatal(
"The target cluster lacks cluster state information:");
190 resetwal_bin =
"pg_resetxlog\" -n";
192 resetwal_bin =
"pg_resetwal\" -n";
193 snprintf(cmd,
sizeof(cmd),
"\"%s/%s \"%s\"",
195 live_check ?
"pg_controldata\"" : resetwal_bin,
199 if ((
output = popen(cmd,
"r")) == NULL)
200 pg_fatal(
"could not get control data using %s: %s",
206 cluster->controldata.data_checksum_version = 0;
207 got_data_checksum_version =
true;
211 while (fgets(bufin,
sizeof(bufin),
output))
217 if ((p = strstr(bufin,
"pg_control version number:")) != NULL)
221 if (p == NULL || strlen(p) <= 1)
222 pg_fatal(
"%d: pg_resetwal problem", __LINE__);
227 else if ((p = strstr(bufin,
"Catalog version number:")) != NULL)
231 if (p == NULL || strlen(p) <= 1)
232 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
237 else if ((p = strstr(bufin,
"Latest checkpoint's TimeLineID:")) != NULL)
241 if (p == NULL || strlen(p) <= 1)
242 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
248 else if ((p = strstr(bufin,
"First log file ID after reset:")) != NULL)
252 if (p == NULL || strlen(p) <= 1)
253 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
259 else if ((p = strstr(bufin,
"First log file segment after reset:")) != NULL)
263 if (p == NULL || strlen(p) <= 1)
264 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
270 else if ((p = strstr(bufin,
"Latest checkpoint's NextXID:")) != NULL)
274 if (p == NULL || strlen(p) <= 1)
275 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
286 if (strchr(p,
'/') != NULL)
293 if (p == NULL || strlen(p) <= 1)
294 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
300 else if ((p = strstr(bufin,
"Latest checkpoint's NextOID:")) != NULL)
304 if (p == NULL || strlen(p) <= 1)
305 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
311 else if ((p = strstr(bufin,
"Latest checkpoint's NextMultiXactId:")) != NULL)
315 if (p == NULL || strlen(p) <= 1)
316 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
322 else if ((p = strstr(bufin,
"Latest checkpoint's oldestXID:")) != NULL)
326 if (p == NULL || strlen(p) <= 1)
327 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
331 got_oldestxid =
true;
333 else if ((p = strstr(bufin,
"Latest checkpoint's oldestMultiXid:")) != NULL)
337 if (p == NULL || strlen(p) <= 1)
338 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
342 got_oldestmulti =
true;
344 else if ((p = strstr(bufin,
"Latest checkpoint's NextMultiOffset:")) != NULL)
348 if (p == NULL || strlen(p) <= 1)
349 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
355 else if ((p = strstr(bufin,
"First log segment after reset:")) != NULL)
359 if (p == NULL || strlen(p) <= 1)
360 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
361 p = strpbrk(p,
"01234567890ABCDEF");
362 if (p == NULL || strlen(p) <= 1)
363 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
366 if (strspn(p,
"0123456789ABCDEF") != 24)
367 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
370 got_nextxlogfile =
true;
372 else if ((p = strstr(bufin,
"Float8 argument passing:")) != NULL)
376 if (p == NULL || strlen(p) <= 1)
377 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
381 cluster->controldata.float8_pass_by_value = strstr(p,
"by value") != NULL;
382 got_float8_pass_by_value =
true;
384 else if ((p = strstr(bufin,
"Maximum data alignment:")) != NULL)
388 if (p == NULL || strlen(p) <= 1)
389 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
395 else if ((p = strstr(bufin,
"Database block size:")) != NULL)
399 if (p == NULL || strlen(p) <= 1)
400 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
406 else if ((p = strstr(bufin,
"Blocks per segment of large relation:")) != NULL)
410 if (p == NULL || strlen(p) <= 1)
411 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
417 else if ((p = strstr(bufin,
"WAL block size:")) != NULL)
421 if (p == NULL || strlen(p) <= 1)
422 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
428 else if ((p = strstr(bufin,
"Bytes per WAL segment:")) != NULL)
432 if (p == NULL || strlen(p) <= 1)
433 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
439 else if ((p = strstr(bufin,
"Maximum length of identifiers:")) != NULL)
443 if (p == NULL || strlen(p) <= 1)
444 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
450 else if ((p = strstr(bufin,
"Maximum columns in an index:")) != NULL)
454 if (p == NULL || strlen(p) <= 1)
455 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
461 else if ((p = strstr(bufin,
"Maximum size of a TOAST chunk:")) != NULL)
465 if (p == NULL || strlen(p) <= 1)
466 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
472 else if ((p = strstr(bufin,
"Size of a large-object chunk:")) != NULL)
476 if (p == NULL || strlen(p) <= 1)
477 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
481 got_large_object =
true;
483 else if ((p = strstr(bufin,
"Date/time type storage:")) != NULL)
487 if (p == NULL || strlen(p) <= 1)
488 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
491 cluster->controldata.date_is_int = strstr(p,
"64-bit integers") != NULL;
492 got_date_is_int =
true;
494 else if ((p = strstr(bufin,
"checksum")) != NULL)
498 if (p == NULL || strlen(p) <= 1)
499 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
503 got_data_checksum_version =
true;
509 pg_fatal(
"could not get control data using %s: %s",
531 setenv(
"LANGUAGE", language, 1);
533 setenv(
"LC_ALL", lc_all, 1);
557 if (got_tli && got_log_id && got_log_seg)
561 got_nextxlogfile =
true;
566 if (!got_xid || !got_oid ||
567 !got_multi || !got_oldestxid ||
570 !got_mxoff || (!live_check && !got_nextxlogfile) ||
571 !got_float8_pass_by_value || !got_align || !got_blocksz ||
572 !got_largesz || !got_walsz || !got_walseg || !got_ident ||
573 !got_index || !got_toast ||
574 (!got_large_object &&
576 !got_date_is_int || !got_data_checksum_version)
580 "The source cluster lacks some required control information:");
583 "The target cluster lacks some required control information:");
594 if (!got_oldestmulti &&
604 if (!live_check && !got_nextxlogfile)
607 if (!got_float8_pass_by_value)
634 if (!got_large_object &&
638 if (!got_date_is_int)
642 if (!got_data_checksum_version)
645 pg_fatal(
"Cannot continue without required control information, terminating");
660 pg_fatal(
"old and new pg_controldata alignments are invalid or do not match.\n"
661 "Likely one cluster is a 32-bit install, the other 64-bit");
664 pg_fatal(
"old and new pg_controldata block sizes are invalid or do not match");
667 pg_fatal(
"old and new pg_controldata maximum relation segment sizes are invalid or do not match");
670 pg_fatal(
"old and new pg_controldata WAL block sizes are invalid or do not match");
673 pg_fatal(
"old and new pg_controldata WAL segment sizes are invalid or do not match");
676 pg_fatal(
"old and new pg_controldata maximum identifier lengths are invalid or do not match");
679 pg_fatal(
"old and new pg_controldata maximum indexed columns are invalid or do not match");
682 pg_fatal(
"old and new pg_controldata maximum TOAST chunk sizes are invalid or do not match");
687 pg_fatal(
"old and new pg_controldata large-object chunk sizes are invalid or do not match");
690 pg_fatal(
"old and new pg_controldata date/time storage types do not match");
703 pg_fatal(
"old cluster does not use data checksums but the new one does");
706 pg_fatal(
"old cluster uses data checksums but the new one does not");
708 pg_fatal(
"old and new cluster pg_controldata checksum versions do not match");
719 prep_status(
"Adding \".old\" suffix to old global/pg_control");
724 pg_fatal(
"could not rename file \"%s\" to \"%s\": %m",
729 "If you want to start the old cluster, you will need to remove\n"
730 "the \".old\" suffix from %s/global/pg_control.old.\n"
731 "Because \"link\" mode was used, the old cluster cannot be safely\n"
732 "started once the new cluster has been started.",
void cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel)
void get_control_data(ClusterInfo *cluster, bool live_check)
void disable_old_cluster(void)
void check_control_data(ControlData *oldctrl, ControlData *newctrl)
char * pg_strdup(const char *in)
static char * lc_messages
static void check_ok(void)
static char * lc_monetary
static void const char fflush(stdout)
#define LARGE_OBJECT_SIZE_PG_CONTROL_VER
#define MULTIXACT_FORMATCHANGE_CAT_VER
void void unsigned int str2uint(const char *str)
void void pg_log(eLogType type, const char *fmt,...) pg_attribute_printf(2
#define GET_MAJOR_VERSION(v)
void prep_status(const char *fmt,...) pg_attribute_printf(1
size_t strlcpy(char *dst, const char *src, size_t siz)
int pg_strip_crlf(char *str)
uint32 data_checksum_version
char * wait_result_to_str(int exitstatus)