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: %m", cmd);
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", __LINE__);
155 if (strcmp(p,
"shut down in recovery") == 0)
158 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.");
160 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.");
162 else if (strcmp(p,
"shut down") != 0)
165 pg_fatal(
"The source cluster was not shut down cleanly, state reported as: \"%s\"", p);
167 pg_fatal(
"The target cluster was not shut down cleanly, state reported as: \"%s\"", p);
169 got_cluster_state =
true;
175 pg_fatal(
"could not get control data using %s: %s",
178 if (!got_cluster_state)
181 pg_fatal(
"The source cluster lacks cluster state information:");
183 pg_fatal(
"The target cluster lacks cluster state information:");
189 resetwal_bin =
"pg_resetxlog\" -n";
191 resetwal_bin =
"pg_resetwal\" -n";
192 snprintf(cmd,
sizeof(cmd),
"\"%s/%s \"%s\"",
194 live_check ?
"pg_controldata\"" : resetwal_bin,
198 if ((
output = popen(cmd,
"r")) == NULL)
199 pg_fatal(
"could not get control data using %s: %m", cmd);
204 cluster->controldata.data_checksum_version = 0;
205 got_data_checksum_version =
true;
209 while (fgets(bufin,
sizeof(bufin),
output))
215 if ((p = strstr(bufin,
"pg_control version number:")) != NULL)
219 if (p == NULL || strlen(p) <= 1)
220 pg_fatal(
"%d: pg_resetwal problem", __LINE__);
225 else if ((p = strstr(bufin,
"Catalog version number:")) != NULL)
229 if (p == NULL || strlen(p) <= 1)
230 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
235 else if ((p = strstr(bufin,
"Latest checkpoint's TimeLineID:")) != NULL)
239 if (p == NULL || strlen(p) <= 1)
240 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
246 else if ((p = strstr(bufin,
"First log file ID after reset:")) != NULL)
250 if (p == NULL || strlen(p) <= 1)
251 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
257 else if ((p = strstr(bufin,
"First log file segment after reset:")) != NULL)
261 if (p == NULL || strlen(p) <= 1)
262 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
268 else if ((p = strstr(bufin,
"Latest checkpoint's NextXID:")) != NULL)
272 if (p == NULL || strlen(p) <= 1)
273 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
284 if (strchr(p,
'/') != NULL)
291 if (p == NULL || strlen(p) <= 1)
292 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
298 else if ((p = strstr(bufin,
"Latest checkpoint's NextOID:")) != NULL)
302 if (p == NULL || strlen(p) <= 1)
303 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
309 else if ((p = strstr(bufin,
"Latest checkpoint's NextMultiXactId:")) != NULL)
313 if (p == NULL || strlen(p) <= 1)
314 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
320 else if ((p = strstr(bufin,
"Latest checkpoint's oldestXID:")) != NULL)
324 if (p == NULL || strlen(p) <= 1)
325 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
329 got_oldestxid =
true;
331 else if ((p = strstr(bufin,
"Latest checkpoint's oldestMultiXid:")) != NULL)
335 if (p == NULL || strlen(p) <= 1)
336 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
340 got_oldestmulti =
true;
342 else if ((p = strstr(bufin,
"Latest checkpoint's NextMultiOffset:")) != NULL)
346 if (p == NULL || strlen(p) <= 1)
347 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
353 else if ((p = strstr(bufin,
"First log segment after reset:")) != NULL)
357 if (p == NULL || strlen(p) <= 1)
358 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
359 p = strpbrk(p,
"01234567890ABCDEF");
360 if (p == NULL || strlen(p) <= 1)
361 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
364 if (strspn(p,
"0123456789ABCDEF") != 24)
365 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
368 got_nextxlogfile =
true;
370 else if ((p = strstr(bufin,
"Float8 argument passing:")) != NULL)
374 if (p == NULL || strlen(p) <= 1)
375 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
379 cluster->controldata.float8_pass_by_value = strstr(p,
"by value") != NULL;
380 got_float8_pass_by_value =
true;
382 else if ((p = strstr(bufin,
"Maximum data alignment:")) != NULL)
386 if (p == NULL || strlen(p) <= 1)
387 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
393 else if ((p = strstr(bufin,
"Database block size:")) != NULL)
397 if (p == NULL || strlen(p) <= 1)
398 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
404 else if ((p = strstr(bufin,
"Blocks per segment of large relation:")) != NULL)
408 if (p == NULL || strlen(p) <= 1)
409 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
415 else if ((p = strstr(bufin,
"WAL block size:")) != NULL)
419 if (p == NULL || strlen(p) <= 1)
420 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
426 else if ((p = strstr(bufin,
"Bytes per WAL segment:")) != NULL)
430 if (p == NULL || strlen(p) <= 1)
431 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
437 else if ((p = strstr(bufin,
"Maximum length of identifiers:")) != NULL)
441 if (p == NULL || strlen(p) <= 1)
442 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
448 else if ((p = strstr(bufin,
"Maximum columns in an index:")) != NULL)
452 if (p == NULL || strlen(p) <= 1)
453 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
459 else if ((p = strstr(bufin,
"Maximum size of a TOAST chunk:")) != NULL)
463 if (p == NULL || strlen(p) <= 1)
464 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
470 else if ((p = strstr(bufin,
"Size of a large-object chunk:")) != NULL)
474 if (p == NULL || strlen(p) <= 1)
475 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
479 got_large_object =
true;
481 else if ((p = strstr(bufin,
"Date/time type storage:")) != NULL)
485 if (p == NULL || strlen(p) <= 1)
486 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
489 cluster->controldata.date_is_int = strstr(p,
"64-bit integers") != NULL;
490 got_date_is_int =
true;
492 else if ((p = strstr(bufin,
"checksum")) != NULL)
496 if (p == NULL || strlen(p) <= 1)
497 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
501 got_data_checksum_version =
true;
507 pg_fatal(
"could not get control data using %s: %s",
529 setenv(
"LANGUAGE", language, 1);
531 setenv(
"LC_ALL", lc_all, 1);
555 if (got_tli && got_log_id && got_log_seg)
559 got_nextxlogfile =
true;
564 if (!got_xid || !got_oid ||
565 !got_multi || !got_oldestxid ||
568 !got_mxoff || (!live_check && !got_nextxlogfile) ||
569 !got_float8_pass_by_value || !got_align || !got_blocksz ||
570 !got_largesz || !got_walsz || !got_walseg || !got_ident ||
571 !got_index || !got_toast ||
572 (!got_large_object &&
574 !got_date_is_int || !got_data_checksum_version)
578 "The source cluster lacks some required control information:");
581 "The target cluster lacks some required control information:");
592 if (!got_oldestmulti &&
602 if (!live_check && !got_nextxlogfile)
605 if (!got_float8_pass_by_value)
632 if (!got_large_object &&
636 if (!got_date_is_int)
640 if (!got_data_checksum_version)
643 pg_fatal(
"Cannot continue without required control information, terminating");
void cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel)
char * pg_strdup(const char *in)
static char * lc_messages
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)
#define GET_MAJOR_VERSION(v)
size_t strlcpy(char *dst, const char *src, size_t siz)
int pg_strip_crlf(char *str)
char * wait_result_to_str(int exitstatus)