41 bool got_log_id =
false;
42 bool got_log_seg =
false;
45 bool got_multi =
false;
46 bool got_oldestmulti =
false;
47 bool got_oldestxid =
false;
48 bool got_mxoff =
false;
49 bool got_nextxlogfile =
false;
50 bool got_float8_pass_by_value =
false;
51 bool got_align =
false;
52 bool got_blocksz =
false;
53 bool got_largesz =
false;
54 bool got_walsz =
false;
55 bool got_walseg =
false;
56 bool got_ident =
false;
57 bool got_index =
false;
58 bool got_toast =
false;
59 bool got_large_object =
false;
60 bool got_date_is_int =
false;
61 bool got_data_checksum_version =
false;
62 bool got_cluster_state =
false;
69 char *language = NULL;
82 if (getenv(
"LC_COLLATE"))
84 if (getenv(
"LC_CTYPE"))
86 if (getenv(
"LC_MONETARY"))
88 if (getenv(
"LC_NUMERIC"))
90 if (getenv(
"LC_TIME"))
94 if (getenv(
"LANGUAGE"))
98 if (getenv(
"LC_MESSAGES"))
114 setenv(
"LC_MESSAGES",
"C", 1);
122 snprintf(cmd,
sizeof(cmd),
"\"%s/pg_controldata\" \"%s\"",
127 if ((
output = popen(cmd,
"r")) == NULL)
128 pg_fatal(
"could not get control data using %s: %s\n",
132 while (fgets(bufin,
sizeof(bufin),
output))
134 if ((p = strstr(bufin,
"Database cluster state:")) != NULL)
138 if (p == NULL || strlen(p) <= 1)
139 pg_fatal(
"%d: database cluster state problem\n", __LINE__);
154 if (strcmp(p,
"shut down in recovery\n") == 0)
157 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.\n");
159 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.\n");
161 else if (strcmp(p,
"shut down\n") != 0)
164 pg_fatal(
"The source cluster was not shut down cleanly.\n");
166 pg_fatal(
"The target cluster was not shut down cleanly.\n");
168 got_cluster_state =
true;
174 if (!got_cluster_state)
177 pg_fatal(
"The source cluster lacks cluster state information:\n");
179 pg_fatal(
"The target cluster lacks cluster state information:\n");
185 resetwal_bin =
"pg_resetxlog\" -n";
187 resetwal_bin =
"pg_resetwal\" -n";
188 snprintf(cmd,
sizeof(cmd),
"\"%s/%s \"%s\"",
190 live_check ?
"pg_controldata\"" : resetwal_bin,
195 if ((
output = popen(cmd,
"r")) == NULL)
196 pg_fatal(
"could not get control data using %s: %s\n",
202 cluster->controldata.data_checksum_version = 0;
203 got_data_checksum_version =
true;
207 while (fgets(bufin,
sizeof(bufin),
output))
211 if ((p = strstr(bufin,
"pg_control version number:")) != NULL)
215 if (p == NULL || strlen(p) <= 1)
216 pg_fatal(
"%d: pg_resetwal problem\n", __LINE__);
221 else if ((p = strstr(bufin,
"Catalog version number:")) != NULL)
225 if (p == NULL || strlen(p) <= 1)
226 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
231 else if ((p = strstr(bufin,
"Latest checkpoint's TimeLineID:")) != NULL)
235 if (p == NULL || strlen(p) <= 1)
236 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
242 else if ((p = strstr(bufin,
"First log file ID after reset:")) != NULL)
246 if (p == NULL || strlen(p) <= 1)
247 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
253 else if ((p = strstr(bufin,
"First log file segment after reset:")) != NULL)
257 if (p == NULL || strlen(p) <= 1)
258 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
264 else if ((p = strstr(bufin,
"Latest checkpoint's NextXID:")) != NULL)
268 if (p == NULL || strlen(p) <= 1)
269 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
280 if (strchr(p,
'/') != NULL)
287 if (p == NULL || strlen(p) <= 1)
288 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
294 else if ((p = strstr(bufin,
"Latest checkpoint's NextOID:")) != NULL)
298 if (p == NULL || strlen(p) <= 1)
299 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
305 else if ((p = strstr(bufin,
"Latest checkpoint's NextMultiXactId:")) != NULL)
309 if (p == NULL || strlen(p) <= 1)
310 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
316 else if ((p = strstr(bufin,
"Latest checkpoint's oldestXID:")) != NULL)
320 if (p == NULL || strlen(p) <= 1)
321 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
325 got_oldestxid =
true;
327 else if ((p = strstr(bufin,
"Latest checkpoint's oldestMultiXid:")) != NULL)
331 if (p == NULL || strlen(p) <= 1)
332 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
336 got_oldestmulti =
true;
338 else if ((p = strstr(bufin,
"Latest checkpoint's NextMultiOffset:")) != NULL)
342 if (p == NULL || strlen(p) <= 1)
343 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
349 else if ((p = strstr(bufin,
"First log segment after reset:")) != NULL)
353 if (p == NULL || strlen(p) <= 1)
354 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
355 p = strpbrk(p,
"01234567890ABCDEF");
356 if (p == NULL || strlen(p) <= 1)
357 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
360 if (strspn(p,
"0123456789ABCDEF") != 24)
361 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
364 got_nextxlogfile =
true;
366 else if ((p = strstr(bufin,
"Float8 argument passing:")) != NULL)
370 if (p == NULL || strlen(p) <= 1)
371 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
375 cluster->controldata.float8_pass_by_value = strstr(p,
"by value") != NULL;
376 got_float8_pass_by_value =
true;
378 else if ((p = strstr(bufin,
"Maximum data alignment:")) != NULL)
382 if (p == NULL || strlen(p) <= 1)
383 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
389 else if ((p = strstr(bufin,
"Database block size:")) != NULL)
393 if (p == NULL || strlen(p) <= 1)
394 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
400 else if ((p = strstr(bufin,
"Blocks per segment of large relation:")) != NULL)
404 if (p == NULL || strlen(p) <= 1)
405 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
411 else if ((p = strstr(bufin,
"WAL block size:")) != NULL)
415 if (p == NULL || strlen(p) <= 1)
416 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
422 else if ((p = strstr(bufin,
"Bytes per WAL segment:")) != NULL)
426 if (p == NULL || strlen(p) <= 1)
427 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
433 else if ((p = strstr(bufin,
"Maximum length of identifiers:")) != NULL)
437 if (p == NULL || strlen(p) <= 1)
438 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
444 else if ((p = strstr(bufin,
"Maximum columns in an index:")) != NULL)
448 if (p == NULL || strlen(p) <= 1)
449 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
455 else if ((p = strstr(bufin,
"Maximum size of a TOAST chunk:")) != NULL)
459 if (p == NULL || strlen(p) <= 1)
460 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
466 else if ((p = strstr(bufin,
"Size of a large-object chunk:")) != NULL)
470 if (p == NULL || strlen(p) <= 1)
471 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
475 got_large_object =
true;
477 else if ((p = strstr(bufin,
"Date/time type storage:")) != NULL)
481 if (p == NULL || strlen(p) <= 1)
482 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
485 cluster->controldata.date_is_int = strstr(p,
"64-bit integers") != NULL;
486 got_date_is_int =
true;
488 else if ((p = strstr(bufin,
"checksum")) != NULL)
492 if (p == NULL || strlen(p) <= 1)
493 pg_fatal(
"%d: controldata retrieval problem\n", __LINE__);
498 got_data_checksum_version =
true;
523 setenv(
"LANGUAGE", language, 1);
525 setenv(
"LC_ALL", lc_all, 1);
549 if (got_tli && got_log_id && got_log_seg)
553 got_nextxlogfile =
true;
558 if (!got_xid || !got_oid ||
559 !got_multi || !got_oldestxid ||
562 !got_mxoff || (!live_check && !got_nextxlogfile) ||
563 !got_float8_pass_by_value || !got_align || !got_blocksz ||
564 !got_largesz || !got_walsz || !got_walseg || !got_ident ||
565 !got_index || !got_toast ||
566 (!got_large_object &&
568 !got_date_is_int || !got_data_checksum_version)
572 "The source cluster lacks some required control information:\n");
575 "The target cluster lacks some required control information:\n");
586 if (!got_oldestmulti &&
596 if (!live_check && !got_nextxlogfile)
599 if (!got_float8_pass_by_value)
626 if (!got_large_object &&
630 if (!got_date_is_int)
634 if (!got_data_checksum_version)
637 pg_fatal(
"Cannot continue without required control information, terminating\n");
652 pg_fatal(
"old and new pg_controldata alignments are invalid or do not match\n"
653 "Likely one cluster is a 32-bit install, the other 64-bit\n");
656 pg_fatal(
"old and new pg_controldata block sizes are invalid or do not match\n");
659 pg_fatal(
"old and new pg_controldata maximum relation segment sizes are invalid or do not match\n");
662 pg_fatal(
"old and new pg_controldata WAL block sizes are invalid or do not match\n");
665 pg_fatal(
"old and new pg_controldata WAL segment sizes are invalid or do not match\n");
668 pg_fatal(
"old and new pg_controldata maximum identifier lengths are invalid or do not match\n");
671 pg_fatal(
"old and new pg_controldata maximum indexed columns are invalid or do not match\n");
674 pg_fatal(
"old and new pg_controldata maximum TOAST chunk sizes are invalid or do not match\n");
679 pg_fatal(
"old and new pg_controldata large-object chunk sizes are invalid or do not match\n");
682 pg_fatal(
"old and new pg_controldata date/time storage types do not match\n");
695 pg_fatal(
"old cluster does not use data checksums but the new one does\n");
698 pg_fatal(
"old cluster uses data checksums but the new one does not\n");
700 pg_fatal(
"old and new cluster pg_controldata checksum versions do not match\n");
711 prep_status(
"Adding \".old\" suffix to old global/pg_control");
716 pg_fatal(
"Unable to rename %s to %s.\n", old_path, new_path);
720 "If you want to start the old cluster, you will need to remove\n"
721 "the \".old\" suffix from %s/global/pg_control.old.\n"
722 "Because \"link\" mode was used, the old cluster cannot be safely\n"
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)
static void output(uint64 loop_count)
#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)
bool data_checksum_version