39{
43 char *p;
44 bool got_tli = false;
45 bool got_log_id = false;
46 bool got_log_seg = false;
47 bool got_xid = false;
48 bool got_oid = false;
49 bool got_multi = false;
50 bool got_oldestmulti = false;
51 bool got_oldestxid = false;
52 bool got_mxoff = false;
53 bool got_nextxlogfile = false;
54 bool got_float8_pass_by_value = false;
55 bool got_align = false;
56 bool got_blocksz = false;
57 bool got_largesz = false;
58 bool got_walsz = false;
59 bool got_walseg = false;
60 bool got_ident = false;
61 bool got_index = false;
62 bool got_toast = false;
63 bool got_large_object = false;
64 bool got_date_is_int = false;
65 bool got_data_checksum_version = false;
66 bool got_cluster_state = false;
67 bool got_default_char_signedness = false;
73 char *lang = NULL;
74 char *language = NULL;
75 char *lc_all = NULL;
80 char *resetwal_bin;
81 int rc;
83
84
85
86
87
88 if (getenv("LC_COLLATE"))
90 if (getenv("LC_CTYPE"))
92 if (getenv("LC_MONETARY"))
94 if (getenv("LC_NUMERIC"))
96 if (getenv("LC_TIME"))
98 if (getenv("LANG"))
100 if (getenv("LANGUAGE"))
101 language =
pg_strdup(getenv(
"LANGUAGE"));
102 if (getenv("LC_ALL"))
104 if (getenv("LC_MESSAGES"))
106
112#ifndef WIN32
114#else
115
117#endif
120 setenv(
"LC_MESSAGES",
"C", 1);
121
122
123
124
126 {
127
128 snprintf(cmd,
sizeof(cmd),
"\"%s/pg_controldata\" \"%s\"",
130 fflush(NULL);
131
132 if ((
output = popen(cmd,
"r")) == NULL)
133 pg_fatal(
"could not get control data using %s: %m", cmd);
134
135
136 while (fgets(bufin,
sizeof(bufin),
output))
137 {
138 if ((p = strstr(bufin, "Database cluster state:")) != NULL)
139 {
140 p = strchr(p, ':');
141
142 if (p == NULL || strlen(p) <= 1)
143 pg_fatal(
"%d: database cluster state problem", __LINE__);
144
145 p++;
146
147
148
149
150
151
152
153
154
155
157 while (*p == ' ')
158 p++;
159 if (strcmp(p, "shut down in recovery") == 0)
160 {
162 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.");
163 else
164 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.");
165 }
166 else if (strcmp(p, "shut down") != 0)
167 {
169 pg_fatal(
"The source cluster was not shut down cleanly, state reported as: \"%s\"", p);
170 else
171 pg_fatal(
"The target cluster was not shut down cleanly, state reported as: \"%s\"", p);
172 }
173 got_cluster_state = true;
174 }
175 }
176
178 if (rc != 0)
179 pg_fatal(
"could not get control data using %s: %s",
181
182 if (!got_cluster_state)
183 {
185 pg_fatal(
"The source cluster lacks cluster state information:");
186 else
187 pg_fatal(
"The target cluster lacks cluster state information:");
188 }
189 }
190
191
193 resetwal_bin = "pg_resetxlog\" -n";
194 else
195 resetwal_bin = "pg_resetwal\" -n";
196 snprintf(cmd,
sizeof(cmd),
"\"%s/%s \"%s\"",
198 live_check ? "pg_controldata\"" : resetwal_bin,
200 fflush(NULL);
201
202 if ((
output = popen(cmd,
"r")) == NULL)
203 pg_fatal(
"could not get control data using %s: %m", cmd);
204
205
207 {
208 cluster->controldata.data_checksum_version = 0;
209 got_data_checksum_version = true;
210 }
211
212
213 while (fgets(bufin,
sizeof(bufin),
output))
214 {
215
218
219 if ((p = strstr(bufin, "pg_control version number:")) != NULL)
220 {
221 p = strchr(p, ':');
222
223 if (p == NULL || strlen(p) <= 1)
224 pg_fatal(
"%d: pg_resetwal problem", __LINE__);
225
226 p++;
228 }
229 else if ((p = strstr(bufin, "Catalog version number:")) != NULL)
230 {
231 p = strchr(p, ':');
232
233 if (p == NULL || strlen(p) <= 1)
234 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
235
236 p++;
238 }
239 else if ((p = strstr(bufin, "Latest checkpoint's TimeLineID:")) != NULL)
240 {
241 p = strchr(p, ':');
242
243 if (p == NULL || strlen(p) <= 1)
244 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
245
246 p++;
248 got_tli = true;
249 }
250 else if ((p = strstr(bufin, "First log file ID after reset:")) != NULL)
251 {
252 p = strchr(p, ':');
253
254 if (p == NULL || strlen(p) <= 1)
255 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
256
257 p++;
259 got_log_id = true;
260 }
261 else if ((p = strstr(bufin, "First log file segment after reset:")) != NULL)
262 {
263 p = strchr(p, ':');
264
265 if (p == NULL || strlen(p) <= 1)
266 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
267
268 p++;
270 got_log_seg = true;
271 }
272 else if ((p = strstr(bufin, "Latest checkpoint's NextXID:")) != NULL)
273 {
274 p = strchr(p, ':');
275
276 if (p == NULL || strlen(p) <= 1)
277 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
278
279 p++;
281
282
283
284
285
286
287
288 if (strchr(p, '/') != NULL)
289 p = strchr(p, '/');
291 p = strchr(p, ':');
292 else
293 p = NULL;
294
295 if (p == NULL || strlen(p) <= 1)
296 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
297
298 p++;
300 got_xid = true;
301 }
302 else if ((p = strstr(bufin, "Latest checkpoint's NextOID:")) != NULL)
303 {
304 p = strchr(p, ':');
305
306 if (p == NULL || strlen(p) <= 1)
307 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
308
309 p++;
311 got_oid = true;
312 }
313 else if ((p = strstr(bufin, "Latest checkpoint's NextMultiXactId:")) != NULL)
314 {
315 p = strchr(p, ':');
316
317 if (p == NULL || strlen(p) <= 1)
318 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
319
320 p++;
322 got_multi = true;
323 }
324 else if ((p = strstr(bufin, "Latest checkpoint's oldestXID:")) != NULL)
325 {
326 p = strchr(p, ':');
327
328 if (p == NULL || strlen(p) <= 1)
329 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
330
331 p++;
333 got_oldestxid = true;
334 }
335 else if ((p = strstr(bufin, "Latest checkpoint's oldestMultiXid:")) != NULL)
336 {
337 p = strchr(p, ':');
338
339 if (p == NULL || strlen(p) <= 1)
340 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
341
342 p++;
344 got_oldestmulti = true;
345 }
346 else if ((p = strstr(bufin, "Latest checkpoint's NextMultiOffset:")) != NULL)
347 {
348 p = strchr(p, ':');
349
350 if (p == NULL || strlen(p) <= 1)
351 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
352
353 p++;
355 got_mxoff = true;
356 }
357 else if ((p = strstr(bufin, "First log segment after reset:")) != NULL)
358 {
359
360 p = strchr(p, ':');
361 if (p == NULL || strlen(p) <= 1)
362 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
363 p = strpbrk(p, "01234567890ABCDEF");
364 if (p == NULL || strlen(p) <= 1)
365 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
366
367
368 if (strspn(p, "0123456789ABCDEF") != 24)
369 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
370
372 got_nextxlogfile = true;
373 }
374 else if ((p = strstr(bufin, "Float8 argument passing:")) != NULL)
375 {
376 p = strchr(p, ':');
377
378 if (p == NULL || strlen(p) <= 1)
379 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
380
381 p++;
382
383 cluster->controldata.float8_pass_by_value = strstr(p,
"by value") != NULL;
384 got_float8_pass_by_value = true;
385 }
386 else if ((p = strstr(bufin, "Maximum data alignment:")) != NULL)
387 {
388 p = strchr(p, ':');
389
390 if (p == NULL || strlen(p) <= 1)
391 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
392
393 p++;
395 got_align = true;
396 }
397 else if ((p = strstr(bufin, "Database block size:")) != NULL)
398 {
399 p = strchr(p, ':');
400
401 if (p == NULL || strlen(p) <= 1)
402 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
403
404 p++;
406 got_blocksz = true;
407 }
408 else if ((p = strstr(bufin, "Blocks per segment of large relation:")) != NULL)
409 {
410 p = strchr(p, ':');
411
412 if (p == NULL || strlen(p) <= 1)
413 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
414
415 p++;
417 got_largesz = true;
418 }
419 else if ((p = strstr(bufin, "WAL block size:")) != NULL)
420 {
421 p = strchr(p, ':');
422
423 if (p == NULL || strlen(p) <= 1)
424 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
425
426 p++;
428 got_walsz = true;
429 }
430 else if ((p = strstr(bufin, "Bytes per WAL segment:")) != NULL)
431 {
432 p = strchr(p, ':');
433
434 if (p == NULL || strlen(p) <= 1)
435 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
436
437 p++;
439 got_walseg = true;
440 }
441 else if ((p = strstr(bufin, "Maximum length of identifiers:")) != NULL)
442 {
443 p = strchr(p, ':');
444
445 if (p == NULL || strlen(p) <= 1)
446 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
447
448 p++;
450 got_ident = true;
451 }
452 else if ((p = strstr(bufin, "Maximum columns in an index:")) != NULL)
453 {
454 p = strchr(p, ':');
455
456 if (p == NULL || strlen(p) <= 1)
457 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
458
459 p++;
461 got_index = true;
462 }
463 else if ((p = strstr(bufin, "Maximum size of a TOAST chunk:")) != NULL)
464 {
465 p = strchr(p, ':');
466
467 if (p == NULL || strlen(p) <= 1)
468 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
469
470 p++;
472 got_toast = true;
473 }
474 else if ((p = strstr(bufin, "Size of a large-object chunk:")) != NULL)
475 {
476 p = strchr(p, ':');
477
478 if (p == NULL || strlen(p) <= 1)
479 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
480
481 p++;
483 got_large_object = true;
484 }
485 else if ((p = strstr(bufin, "Date/time type storage:")) != NULL)
486 {
487 p = strchr(p, ':');
488
489 if (p == NULL || strlen(p) <= 1)
490 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
491
492 p++;
493 cluster->controldata.date_is_int = strstr(p,
"64-bit integers") != NULL;
494 got_date_is_int = true;
495 }
496 else if ((p = strstr(bufin, "checksum")) != NULL)
497 {
498 p = strchr(p, ':');
499
500 if (p == NULL || strlen(p) <= 1)
501 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
502
503 p++;
505 got_data_checksum_version = true;
506 }
507 else if ((p = strstr(bufin, "Default char data signedness:")) != NULL)
508 {
509 p = strchr(p, ':');
510
511 if (p == NULL || strlen(p) <= 1)
512 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
513
514
515 p++;
516 while (isspace((unsigned char) *p))
517 p++;
518
519
520 if (strcmp(p, "signed") != 0 && strcmp(p, "unsigned") != 0)
521 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
522
523 cluster->controldata.default_char_signedness = strcmp(p,
"signed") == 0;
524 got_default_char_signedness = true;
525 }
526 }
527
529 if (rc != 0)
530 pg_fatal(
"could not get control data using %s: %s",
532
533
534
535
536
547 if (lang)
549 else
551 if (language)
552 setenv(
"LANGUAGE", language, 1);
553 if (lc_all)
554 setenv(
"LC_ALL", lc_all, 1);
557 else
559
569
570
571
572
573
574
575
577 {
578 if (got_tli && got_log_id && got_log_seg)
579 {
581 tli, logid, segno);
582 got_nextxlogfile = true;
583 }
584 }
585
586
587
588
589
590
592 {
593 Assert(!got_default_char_signedness);
594#if CHAR_MIN != 0
595 cluster->controldata.default_char_signedness =
true;
596#else
597 cluster->controldata.default_char_signedness =
false;
598#endif
599 }
600
601
602 if (!got_xid || !got_oid ||
603 !got_multi || !got_oldestxid ||
604 (!got_oldestmulti &&
606 !got_mxoff || (!live_check && !got_nextxlogfile) ||
607 !got_float8_pass_by_value || !got_align || !got_blocksz ||
608 !got_largesz || !got_walsz || !got_walseg || !got_ident ||
609 !got_index || !got_toast ||
610 (!got_large_object &&
612 !got_date_is_int || !got_data_checksum_version ||
613 (!got_default_char_signedness &&
615 {
618 "The source cluster lacks some required control information:");
619 else
621 "The target cluster lacks some required control information:");
622
623 if (!got_xid)
625
626 if (!got_oid)
628
629 if (!got_multi)
631
632 if (!got_oldestmulti &&
635
636 if (!got_oldestxid)
638
639 if (!got_mxoff)
641
642 if (!live_check && !got_nextxlogfile)
644
645 if (!got_float8_pass_by_value)
647
648 if (!got_align)
650
651 if (!got_blocksz)
653
654 if (!got_largesz)
656
657 if (!got_walsz)
659
660 if (!got_walseg)
662
663 if (!got_ident)
665
666 if (!got_index)
668
669 if (!got_toast)
671
672 if (!got_large_object &&
675
676 if (!got_date_is_int)
678
679
680 if (!got_data_checksum_version)
682
683
684 if (!got_default_char_signedness)
686
687 pg_fatal(
"Cannot continue without required control information, terminating");
688 }
689}
void cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel)
char * pg_strdup(const char *in)
Assert(PointerIsAligned(start, uint64))
static char * lc_messages
static char * lc_monetary
#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)
#define DEFAULT_CHAR_SIGNEDNESS_CAT_VER
size_t strlcpy(char *dst, const char *src, size_t siz)
int pg_strip_crlf(char *str)
char * wait_result_to_str(int exitstatus)