38{
42 char *p;
43 bool got_tli = false;
44 bool got_log_id = false;
45 bool got_log_seg = false;
46 bool got_xid = false;
47 bool got_oid = false;
48 bool got_multi = false;
49 bool got_oldestmulti = false;
50 bool got_oldestxid = false;
51 bool got_mxoff = false;
52 bool got_nextxlogfile = false;
53 bool got_float8_pass_by_value = false;
54 bool got_align = false;
55 bool got_blocksz = false;
56 bool got_largesz = false;
57 bool got_walsz = false;
58 bool got_walseg = false;
59 bool got_ident = false;
60 bool got_index = false;
61 bool got_toast = false;
62 bool got_large_object = false;
63 bool got_date_is_int = false;
64 bool got_data_checksum_version = false;
65 bool got_cluster_state = false;
66 bool got_default_char_signedness = false;
72 char *lang = NULL;
73 char *language = NULL;
74 char *lc_all = NULL;
79 char *resetwal_bin;
80 int rc;
82
83
84
85
86
87 if (getenv("LC_COLLATE"))
89 if (getenv("LC_CTYPE"))
91 if (getenv("LC_MONETARY"))
93 if (getenv("LC_NUMERIC"))
95 if (getenv("LC_TIME"))
97 if (getenv("LANG"))
99 if (getenv("LANGUAGE"))
100 language =
pg_strdup(getenv(
"LANGUAGE"));
101 if (getenv("LC_ALL"))
103 if (getenv("LC_MESSAGES"))
105
111#ifndef WIN32
113#else
114
116#endif
119 setenv(
"LC_MESSAGES",
"C", 1);
120
121
122
123
125 {
126
127 snprintf(cmd,
sizeof(cmd),
"\"%s/pg_controldata\" \"%s\"",
129 fflush(NULL);
130
131 if ((
output = popen(cmd,
"r")) == NULL)
132 pg_fatal(
"could not get control data using %s: %m", cmd);
133
134
135 while (fgets(bufin,
sizeof(bufin),
output))
136 {
137 if ((p = strstr(bufin, "Database cluster state:")) != NULL)
138 {
139 p = strchr(p, ':');
140
141 if (p == NULL || strlen(p) <= 1)
142 pg_fatal(
"%d: database cluster state problem", __LINE__);
143
144 p++;
145
146
147
148
149
150
151
152
153
154
156 while (*p == ' ')
157 p++;
158 if (strcmp(p, "shut down in recovery") == 0)
159 {
161 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.");
162 else
163 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.");
164 }
165 else if (strcmp(p, "shut down") != 0)
166 {
168 pg_fatal(
"The source cluster was not shut down cleanly, state reported as: \"%s\"", p);
169 else
170 pg_fatal(
"The target cluster was not shut down cleanly, state reported as: \"%s\"", p);
171 }
172 got_cluster_state = true;
173 }
174 }
175
177 if (rc != 0)
178 pg_fatal(
"could not get control data using %s: %s",
180
181 if (!got_cluster_state)
182 {
184 pg_fatal(
"The source cluster lacks cluster state information:");
185 else
186 pg_fatal(
"The target cluster lacks cluster state information:");
187 }
188 }
189
190
192 resetwal_bin = "pg_resetxlog\" -n";
193 else
194 resetwal_bin = "pg_resetwal\" -n";
195 snprintf(cmd,
sizeof(cmd),
"\"%s/%s \"%s\"",
197 live_check ? "pg_controldata\"" : resetwal_bin,
199 fflush(NULL);
200
201 if ((
output = popen(cmd,
"r")) == NULL)
202 pg_fatal(
"could not get control data using %s: %m", cmd);
203
204
206 {
207 cluster->controldata.data_checksum_version = 0;
208 got_data_checksum_version = true;
209 }
210
211
212 while (fgets(bufin,
sizeof(bufin),
output))
213 {
214
217
218 if ((p = strstr(bufin, "pg_control version number:")) != NULL)
219 {
220 p = strchr(p, ':');
221
222 if (p == NULL || strlen(p) <= 1)
223 pg_fatal(
"%d: pg_resetwal problem", __LINE__);
224
225 p++;
227 }
228 else if ((p = strstr(bufin, "Catalog version number:")) != NULL)
229 {
230 p = strchr(p, ':');
231
232 if (p == NULL || strlen(p) <= 1)
233 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
234
235 p++;
237 }
238 else if ((p = strstr(bufin, "Latest checkpoint's TimeLineID:")) != NULL)
239 {
240 p = strchr(p, ':');
241
242 if (p == NULL || strlen(p) <= 1)
243 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
244
245 p++;
247 got_tli = true;
248 }
249 else if ((p = strstr(bufin, "First log file ID after reset:")) != NULL)
250 {
251 p = strchr(p, ':');
252
253 if (p == NULL || strlen(p) <= 1)
254 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
255
256 p++;
258 got_log_id = true;
259 }
260 else if ((p = strstr(bufin, "First log file segment after reset:")) != NULL)
261 {
262 p = strchr(p, ':');
263
264 if (p == NULL || strlen(p) <= 1)
265 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
266
267 p++;
269 got_log_seg = true;
270 }
271 else if ((p = strstr(bufin, "Latest checkpoint's NextXID:")) != NULL)
272 {
273 p = strchr(p, ':');
274
275 if (p == NULL || strlen(p) <= 1)
276 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
277
278 p++;
280
281
282
283
284
285
286
287 if (strchr(p, '/') != NULL)
288 p = strchr(p, '/');
290 p = strchr(p, ':');
291 else
292 p = NULL;
293
294 if (p == NULL || strlen(p) <= 1)
295 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
296
297 p++;
299 got_xid = true;
300 }
301 else if ((p = strstr(bufin, "Latest checkpoint's NextOID:")) != NULL)
302 {
303 p = strchr(p, ':');
304
305 if (p == NULL || strlen(p) <= 1)
306 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
307
308 p++;
310 got_oid = true;
311 }
312 else if ((p = strstr(bufin, "Latest checkpoint's NextMultiXactId:")) != NULL)
313 {
314 p = strchr(p, ':');
315
316 if (p == NULL || strlen(p) <= 1)
317 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
318
319 p++;
321 got_multi = true;
322 }
323 else if ((p = strstr(bufin, "Latest checkpoint's oldestXID:")) != NULL)
324 {
325 p = strchr(p, ':');
326
327 if (p == NULL || strlen(p) <= 1)
328 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
329
330 p++;
332 got_oldestxid = true;
333 }
334 else if ((p = strstr(bufin, "Latest checkpoint's oldestMultiXid:")) != NULL)
335 {
336 p = strchr(p, ':');
337
338 if (p == NULL || strlen(p) <= 1)
339 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
340
341 p++;
343 got_oldestmulti = true;
344 }
345 else if ((p = strstr(bufin, "Latest checkpoint's NextMultiOffset:")) != NULL)
346 {
347 p = strchr(p, ':');
348
349 if (p == NULL || strlen(p) <= 1)
350 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
351
352 p++;
354 got_mxoff = true;
355 }
356 else if ((p = strstr(bufin, "First log segment after reset:")) != NULL)
357 {
358
359 p = strchr(p, ':');
360 if (p == NULL || strlen(p) <= 1)
361 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
362 p = strpbrk(p, "01234567890ABCDEF");
363 if (p == NULL || strlen(p) <= 1)
364 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
365
366
367 if (strspn(p, "0123456789ABCDEF") != 24)
368 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
369
371 got_nextxlogfile = true;
372 }
373 else if ((p = strstr(bufin, "Float8 argument passing:")) != NULL)
374 {
375 p = strchr(p, ':');
376
377 if (p == NULL || strlen(p) <= 1)
378 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
379
380 p++;
381
382 cluster->controldata.float8_pass_by_value = strstr(p,
"by value") != NULL;
383 got_float8_pass_by_value = true;
384 }
385 else if ((p = strstr(bufin, "Maximum data alignment:")) != NULL)
386 {
387 p = strchr(p, ':');
388
389 if (p == NULL || strlen(p) <= 1)
390 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
391
392 p++;
394 got_align = true;
395 }
396 else if ((p = strstr(bufin, "Database block size:")) != NULL)
397 {
398 p = strchr(p, ':');
399
400 if (p == NULL || strlen(p) <= 1)
401 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
402
403 p++;
405 got_blocksz = true;
406 }
407 else if ((p = strstr(bufin, "Blocks per segment of large relation:")) != NULL)
408 {
409 p = strchr(p, ':');
410
411 if (p == NULL || strlen(p) <= 1)
412 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
413
414 p++;
416 got_largesz = true;
417 }
418 else if ((p = strstr(bufin, "WAL block size:")) != NULL)
419 {
420 p = strchr(p, ':');
421
422 if (p == NULL || strlen(p) <= 1)
423 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
424
425 p++;
427 got_walsz = true;
428 }
429 else if ((p = strstr(bufin, "Bytes per WAL segment:")) != NULL)
430 {
431 p = strchr(p, ':');
432
433 if (p == NULL || strlen(p) <= 1)
434 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
435
436 p++;
438 got_walseg = true;
439 }
440 else if ((p = strstr(bufin, "Maximum length of identifiers:")) != NULL)
441 {
442 p = strchr(p, ':');
443
444 if (p == NULL || strlen(p) <= 1)
445 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
446
447 p++;
449 got_ident = true;
450 }
451 else if ((p = strstr(bufin, "Maximum columns in an index:")) != NULL)
452 {
453 p = strchr(p, ':');
454
455 if (p == NULL || strlen(p) <= 1)
456 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
457
458 p++;
460 got_index = true;
461 }
462 else if ((p = strstr(bufin, "Maximum size of a TOAST chunk:")) != NULL)
463 {
464 p = strchr(p, ':');
465
466 if (p == NULL || strlen(p) <= 1)
467 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
468
469 p++;
471 got_toast = true;
472 }
473 else if ((p = strstr(bufin, "Size of a large-object chunk:")) != NULL)
474 {
475 p = strchr(p, ':');
476
477 if (p == NULL || strlen(p) <= 1)
478 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
479
480 p++;
482 got_large_object = true;
483 }
484 else if ((p = strstr(bufin, "Date/time type storage:")) != NULL)
485 {
486 p = strchr(p, ':');
487
488 if (p == NULL || strlen(p) <= 1)
489 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
490
491 p++;
492 cluster->controldata.date_is_int = strstr(p,
"64-bit integers") != NULL;
493 got_date_is_int = true;
494 }
495 else if ((p = strstr(bufin, "checksum")) != NULL)
496 {
497 p = strchr(p, ':');
498
499 if (p == NULL || strlen(p) <= 1)
500 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
501
502 p++;
504 got_data_checksum_version = true;
505 }
506 else if ((p = strstr(bufin, "Default char data signedness:")) != NULL)
507 {
508 p = strchr(p, ':');
509
510 if (p == NULL || strlen(p) <= 1)
511 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
512
513
514 p++;
515 while (isspace((unsigned char) *p))
516 p++;
517
518
519 if (strcmp(p, "signed") != 0 && strcmp(p, "unsigned") != 0)
520 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
521
522 cluster->controldata.default_char_signedness = strcmp(p,
"signed") == 0;
523 got_default_char_signedness = true;
524 }
525 }
526
528 if (rc != 0)
529 pg_fatal(
"could not get control data using %s: %s",
531
532
533
534
535
546 if (lang)
548 else
550 if (language)
551 setenv(
"LANGUAGE", language, 1);
552 if (lc_all)
553 setenv(
"LC_ALL", lc_all, 1);
556 else
558
568
569
570
571
572
573
574
576 {
577 if (got_tli && got_log_id && got_log_seg)
578 {
580 tli, logid, segno);
581 got_nextxlogfile = true;
582 }
583 }
584
585
586
587
588
589
591 {
592 Assert(!got_default_char_signedness);
593#if CHAR_MIN != 0
594 cluster->controldata.default_char_signedness =
true;
595#else
596 cluster->controldata.default_char_signedness =
false;
597#endif
598 }
599
600
601 if (!got_xid || !got_oid ||
602 !got_multi || !got_oldestxid ||
603 (!got_oldestmulti &&
605 !got_mxoff || (!live_check && !got_nextxlogfile) ||
606 !got_float8_pass_by_value || !got_align || !got_blocksz ||
607 !got_largesz || !got_walsz || !got_walseg || !got_ident ||
608 !got_index || !got_toast ||
609 (!got_large_object &&
611 !got_date_is_int || !got_data_checksum_version ||
612 (!got_default_char_signedness &&
614 {
617 "The source cluster lacks some required control information:");
618 else
620 "The target cluster lacks some required control information:");
621
622 if (!got_xid)
624
625 if (!got_oid)
627
628 if (!got_multi)
630
631 if (!got_oldestmulti &&
634
635 if (!got_oldestxid)
637
638 if (!got_mxoff)
640
641 if (!live_check && !got_nextxlogfile)
643
644 if (!got_float8_pass_by_value)
646
647 if (!got_align)
649
650 if (!got_blocksz)
652
653 if (!got_largesz)
655
656 if (!got_walsz)
658
659 if (!got_walseg)
661
662 if (!got_ident)
664
665 if (!got_index)
667
668 if (!got_toast)
670
671 if (!got_large_object &&
674
675 if (!got_date_is_int)
677
678
679 if (!got_data_checksum_version)
681
682
683 if (!got_default_char_signedness)
685
686 pg_fatal(
"Cannot continue without required control information, terminating");
687 }
688}
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)