37{
41 char *p;
42 bool got_tli = false;
43 bool got_log_id = false;
44 bool got_log_seg = false;
45 bool got_xid = false;
46 bool got_oid = 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;
70 char *lang = NULL;
71 char *language = NULL;
72 char *lc_all = NULL;
77 char *resetwal_bin;
78 int rc;
80
81
82
83
84
85 if (getenv("LC_COLLATE"))
87 if (getenv("LC_CTYPE"))
89 if (getenv("LC_MONETARY"))
91 if (getenv("LC_NUMERIC"))
93 if (getenv("LC_TIME"))
95 if (getenv("LANG"))
97 if (getenv("LANGUAGE"))
99 if (getenv("LC_ALL"))
101 if (getenv("LC_MESSAGES"))
103
109#ifndef WIN32
111#else
112
114#endif
117 setenv(
"LC_MESSAGES",
"C", 1);
118
119
120
121
123 {
124
125 snprintf(cmd,
sizeof(cmd),
"\"%s/pg_controldata\" \"%s\"",
128
129 if ((
output = popen(cmd,
"r")) == NULL)
130 pg_fatal(
"could not get control data using %s: %m", cmd);
131
132
133 while (fgets(bufin,
sizeof(bufin),
output))
134 {
135 if ((p = strstr(bufin, "Database cluster state:")) != NULL)
136 {
137 p = strchr(p, ':');
138
139 if (p == NULL || strlen(p) <= 1)
140 pg_fatal(
"%d: database cluster state problem", __LINE__);
141
142 p++;
143
144
145
146
147
148
149
150
151
152
154 while (*p == ' ')
155 p++;
156 if (strcmp(p, "shut down in recovery") == 0)
157 {
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.");
160 else
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.");
162 }
163 else if (strcmp(p, "shut down") != 0)
164 {
166 pg_fatal(
"The source cluster was not shut down cleanly, state reported as: \"%s\"", p);
167 else
168 pg_fatal(
"The target cluster was not shut down cleanly, state reported as: \"%s\"", p);
169 }
170 got_cluster_state = true;
171 }
172 }
173
175 if (rc != 0)
176 pg_fatal(
"could not get control data using %s: %s",
178
179 if (!got_cluster_state)
180 {
182 pg_fatal(
"The source cluster lacks cluster state information:");
183 else
184 pg_fatal(
"The target cluster lacks cluster state information:");
185 }
186 }
187
188
190 resetwal_bin = "pg_resetxlog\" -n";
191 else
192 resetwal_bin = "pg_resetwal\" -n";
193 snprintf(cmd,
sizeof(cmd),
"\"%s/%s \"%s\"",
195 live_check ? "pg_controldata\"" : resetwal_bin,
198
199 if ((
output = popen(cmd,
"r")) == NULL)
200 pg_fatal(
"could not get control data using %s: %m", cmd);
201
202
204 {
205 cluster->controldata.data_checksum_version = 0;
206 got_data_checksum_version = true;
207 }
208
209
210 while (fgets(bufin,
sizeof(bufin),
output))
211 {
212
215
216 if ((p = strstr(bufin, "pg_control version number:")) != NULL)
217 {
218 p = strchr(p, ':');
219
220 if (p == NULL || strlen(p) <= 1)
221 pg_fatal(
"%d: pg_resetwal problem", __LINE__);
222
223 p++;
225 }
226 else if ((p = strstr(bufin, "Catalog version number:")) != NULL)
227 {
228 p = strchr(p, ':');
229
230 if (p == NULL || strlen(p) <= 1)
231 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
232
233 p++;
235 }
236 else if ((p = strstr(bufin, "Latest checkpoint's TimeLineID:")) != NULL)
237 {
238 p = strchr(p, ':');
239
240 if (p == NULL || strlen(p) <= 1)
241 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
242
243 p++;
245 got_tli = true;
246 }
247 else if ((p = strstr(bufin, "First log file ID after reset:")) != NULL)
248 {
249 p = strchr(p, ':');
250
251 if (p == NULL || strlen(p) <= 1)
252 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
253
254 p++;
256 got_log_id = true;
257 }
258 else if ((p = strstr(bufin, "First log file segment after reset:")) != NULL)
259 {
260 p = strchr(p, ':');
261
262 if (p == NULL || strlen(p) <= 1)
263 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
264
265 p++;
267 got_log_seg = true;
268 }
269 else if ((p = strstr(bufin, "Latest checkpoint's NextXID:")) != NULL)
270 {
271 p = strchr(p, ':');
272
273 if (p == NULL || strlen(p) <= 1)
274 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
275
276 p++;
278
279
280
281
282
283
284
285 if (strchr(p, '/') != NULL)
286 p = strchr(p, '/');
288 p = strchr(p, ':');
289 else
290 p = NULL;
291
292 if (p == NULL || strlen(p) <= 1)
293 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
294
295 p++;
297 got_xid = true;
298 }
299 else if ((p = strstr(bufin, "Latest checkpoint's NextOID:")) != NULL)
300 {
301 p = strchr(p, ':');
302
303 if (p == NULL || strlen(p) <= 1)
304 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
305
306 p++;
308 got_oid = true;
309 }
310 else if ((p = strstr(bufin, "Latest checkpoint's NextMultiXactId:")) != NULL)
311 {
312 p = strchr(p, ':');
313
314 if (p == NULL || strlen(p) <= 1)
315 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
316
317 p++;
319 got_multi = true;
320 }
321 else if ((p = strstr(bufin, "Latest checkpoint's oldestXID:")) != NULL)
322 {
323 p = strchr(p, ':');
324
325 if (p == NULL || strlen(p) <= 1)
326 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
327
328 p++;
330 got_oldestxid = true;
331 }
332 else if ((p = strstr(bufin, "Latest checkpoint's oldestMultiXid:")) != NULL)
333 {
334 p = strchr(p, ':');
335
336 if (p == NULL || strlen(p) <= 1)
337 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
338
339 p++;
341 got_oldestmulti = true;
342 }
343 else if ((p = strstr(bufin, "Latest checkpoint's NextMultiOffset:")) != NULL)
344 {
345 p = strchr(p, ':');
346
347 if (p == NULL || strlen(p) <= 1)
348 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
349
350 p++;
352 got_mxoff = true;
353 }
354 else if ((p = strstr(bufin, "First log segment after reset:")) != NULL)
355 {
356
357 p = strchr(p, ':');
358 if (p == NULL || strlen(p) <= 1)
359 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
360 p = strpbrk(p, "01234567890ABCDEF");
361 if (p == NULL || strlen(p) <= 1)
362 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
363
364
365 if (strspn(p, "0123456789ABCDEF") != 24)
366 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
367
369 got_nextxlogfile = true;
370 }
371 else if ((p = strstr(bufin, "Float8 argument passing:")) != NULL)
372 {
373 p = strchr(p, ':');
374
375 if (p == NULL || strlen(p) <= 1)
376 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
377
378 p++;
379
380 cluster->controldata.float8_pass_by_value = strstr(p,
"by value") != NULL;
381 got_float8_pass_by_value = true;
382 }
383 else if ((p = strstr(bufin, "Maximum data alignment:")) != NULL)
384 {
385 p = strchr(p, ':');
386
387 if (p == NULL || strlen(p) <= 1)
388 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
389
390 p++;
392 got_align = true;
393 }
394 else if ((p = strstr(bufin, "Database block size:")) != NULL)
395 {
396 p = strchr(p, ':');
397
398 if (p == NULL || strlen(p) <= 1)
399 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
400
401 p++;
403 got_blocksz = true;
404 }
405 else if ((p = strstr(bufin, "Blocks per segment of large relation:")) != NULL)
406 {
407 p = strchr(p, ':');
408
409 if (p == NULL || strlen(p) <= 1)
410 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
411
412 p++;
414 got_largesz = true;
415 }
416 else if ((p = strstr(bufin, "WAL block size:")) != NULL)
417 {
418 p = strchr(p, ':');
419
420 if (p == NULL || strlen(p) <= 1)
421 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
422
423 p++;
425 got_walsz = true;
426 }
427 else if ((p = strstr(bufin, "Bytes per WAL segment:")) != NULL)
428 {
429 p = strchr(p, ':');
430
431 if (p == NULL || strlen(p) <= 1)
432 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
433
434 p++;
436 got_walseg = true;
437 }
438 else if ((p = strstr(bufin, "Maximum length of identifiers:")) != NULL)
439 {
440 p = strchr(p, ':');
441
442 if (p == NULL || strlen(p) <= 1)
443 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
444
445 p++;
447 got_ident = true;
448 }
449 else if ((p = strstr(bufin, "Maximum columns in an index:")) != NULL)
450 {
451 p = strchr(p, ':');
452
453 if (p == NULL || strlen(p) <= 1)
454 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
455
456 p++;
458 got_index = true;
459 }
460 else if ((p = strstr(bufin, "Maximum size of a TOAST chunk:")) != NULL)
461 {
462 p = strchr(p, ':');
463
464 if (p == NULL || strlen(p) <= 1)
465 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
466
467 p++;
469 got_toast = true;
470 }
471 else if ((p = strstr(bufin, "Size of a large-object chunk:")) != NULL)
472 {
473 p = strchr(p, ':');
474
475 if (p == NULL || strlen(p) <= 1)
476 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
477
478 p++;
480 got_large_object = true;
481 }
482 else if ((p = strstr(bufin, "Date/time type storage:")) != NULL)
483 {
484 p = strchr(p, ':');
485
486 if (p == NULL || strlen(p) <= 1)
487 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
488
489 p++;
490 cluster->controldata.date_is_int = strstr(p,
"64-bit integers") != NULL;
491 got_date_is_int = true;
492 }
493 else if ((p = strstr(bufin, "checksum")) != NULL)
494 {
495 p = strchr(p, ':');
496
497 if (p == NULL || strlen(p) <= 1)
498 pg_fatal(
"%d: controldata retrieval problem", __LINE__);
499
500 p++;
502 got_data_checksum_version = true;
503 }
504 }
505
507 if (rc != 0)
508 pg_fatal(
"could not get control data using %s: %s",
510
511
512
513
514
525 if (lang)
527 else
529 if (language)
530 setenv(
"LANGUAGE", language, 1);
531 if (lc_all)
532 setenv(
"LC_ALL", lc_all, 1);
535 else
537
547
548
549
550
551
552
553
555 {
556 if (got_tli && got_log_id && got_log_seg)
557 {
559 tli, logid, segno);
560 got_nextxlogfile = true;
561 }
562 }
563
564
565 if (!got_xid || !got_oid ||
566 !got_multi || !got_oldestxid ||
567 (!got_oldestmulti &&
569 !got_mxoff || (!live_check && !got_nextxlogfile) ||
570 !got_float8_pass_by_value || !got_align || !got_blocksz ||
571 !got_largesz || !got_walsz || !got_walseg || !got_ident ||
572 !got_index || !got_toast ||
573 (!got_large_object &&
575 !got_date_is_int || !got_data_checksum_version)
576 {
579 "The source cluster lacks some required control information:");
580 else
582 "The target cluster lacks some required control information:");
583
584 if (!got_xid)
586
587 if (!got_oid)
589
590 if (!got_multi)
592
593 if (!got_oldestmulti &&
596
597 if (!got_oldestxid)
599
600 if (!got_mxoff)
602
603 if (!live_check && !got_nextxlogfile)
605
606 if (!got_float8_pass_by_value)
608
609 if (!got_align)
611
612 if (!got_blocksz)
614
615 if (!got_largesz)
617
618 if (!got_walsz)
620
621 if (!got_walseg)
623
624 if (!got_ident)
626
627 if (!got_index)
629
630 if (!got_toast)
632
633 if (!got_large_object &&
636
637 if (!got_date_is_int)
639
640
641 if (!got_data_checksum_version)
643
644 pg_fatal(
"Cannot continue without required control information, terminating");
645 }
646}
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)