1 /*
2 * controldata.c
3 *
4 * controldata functions
5 *
6 * Copyright (c) 2010-2016, PostgreSQL Global Development Group
7 * src/bin/pg_upgrade/controldata.c
8 */
9
10 #include "postgres_fe.h"
11
12 #include "pg_upgrade.h"
13
14 #include <ctype.h>
15
16 /*
17 * get_control_data()
18 *
19 * gets pg_control information in "ctrl". Assumes that bindir and
20 * datadir are valid absolute paths to postgresql bin and pgdata
21 * directories respectively *and* pg_resetxlog is version compatible
22 * with datadir. The main purpose of this function is to get pg_control
23 * data in a version independent manner.
24 *
25 * The approach taken here is to invoke pg_resetxlog with -n option
26 * and then pipe its output. With little string parsing we get the
27 * pg_control data. pg_resetxlog cannot be run while the server is running
28 * so we use pg_controldata; pg_controldata doesn't provide all the fields
29 * we need to actually perform the upgrade, but it provides enough for
30 * check mode. We do not implement pg_resetxlog -n because it is hard to
31 * return valid xid data for a running server.
32 */
33 void
get_control_data(ClusterInfo * cluster,bool live_check)34 get_control_data(ClusterInfo *cluster, bool live_check)
35 {
36 char cmd[MAXPGPATH];
37 char bufin[MAX_STRING];
38 FILE *output;
39 char *p;
40 bool got_tli = false;
41 bool got_log_id = false;
42 bool got_log_seg = false;
43 bool got_xid = false;
44 bool got_oid = 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;
63 char *lc_collate = NULL;
64 char *lc_ctype = NULL;
65 char *lc_monetary = NULL;
66 char *lc_numeric = NULL;
67 char *lc_time = NULL;
68 char *lang = NULL;
69 char *language = NULL;
70 char *lc_all = NULL;
71 char *lc_messages = NULL;
72 uint32 tli = 0;
73 uint32 logid = 0;
74 uint32 segno = 0;
75
76
77 /*
78 * Because we test the pg_resetxlog output as strings, it has to be in
79 * English. Copied from pg_regress.c.
80 */
81 if (getenv("LC_COLLATE"))
82 lc_collate = pg_strdup(getenv("LC_COLLATE"));
83 if (getenv("LC_CTYPE"))
84 lc_ctype = pg_strdup(getenv("LC_CTYPE"));
85 if (getenv("LC_MONETARY"))
86 lc_monetary = pg_strdup(getenv("LC_MONETARY"));
87 if (getenv("LC_NUMERIC"))
88 lc_numeric = pg_strdup(getenv("LC_NUMERIC"));
89 if (getenv("LC_TIME"))
90 lc_time = pg_strdup(getenv("LC_TIME"));
91 if (getenv("LANG"))
92 lang = pg_strdup(getenv("LANG"));
93 if (getenv("LANGUAGE"))
94 language = pg_strdup(getenv("LANGUAGE"));
95 if (getenv("LC_ALL"))
96 lc_all = pg_strdup(getenv("LC_ALL"));
97 if (getenv("LC_MESSAGES"))
98 lc_messages = pg_strdup(getenv("LC_MESSAGES"));
99
100 pg_putenv("LC_COLLATE", NULL);
101 pg_putenv("LC_CTYPE", NULL);
102 pg_putenv("LC_MONETARY", NULL);
103 pg_putenv("LC_NUMERIC", NULL);
104 pg_putenv("LC_TIME", NULL);
105 pg_putenv("LANG",
106 #ifndef WIN32
107 NULL);
108 #else
109 /* On Windows the default locale cannot be English, so force it */
110 "en");
111 #endif
112 pg_putenv("LANGUAGE", NULL);
113 pg_putenv("LC_ALL", NULL);
114 pg_putenv("LC_MESSAGES", "C");
115
116 /*
117 * Check for clean shutdown
118 */
119 if (!live_check || cluster == &new_cluster)
120 {
121 /* only pg_controldata outputs the cluster state */
122 snprintf(cmd, sizeof(cmd), "\"%s/pg_controldata\" \"%s\"",
123 cluster->bindir, cluster->pgdata);
124 fflush(stdout);
125 fflush(stderr);
126
127 if ((output = popen(cmd, "r")) == NULL)
128 pg_fatal("could not get control data using %s: %s\n",
129 cmd, strerror(errno));
130
131 /* we have the result of cmd in "output". so parse it line by line now */
132 while (fgets(bufin, sizeof(bufin), output))
133 {
134 if ((p = strstr(bufin, "Database cluster state:")) != NULL)
135 {
136 p = strchr(p, ':');
137
138 if (p == NULL || strlen(p) <= 1)
139 pg_fatal("%d: database cluster state problem\n", __LINE__);
140
141 p++; /* remove ':' char */
142
143 /*
144 * We checked earlier for a postmaster lock file, and if we found
145 * one, we tried to start/stop the server to replay the WAL. However,
146 * pg_ctl -m immediate doesn't leave a lock file, but does require
147 * WAL replay, so we check here that the server was shut down cleanly,
148 * from the controldata perspective.
149 */
150 /* remove leading spaces */
151 while (*p == ' ')
152 p++;
153 if (strcmp(p, "shut down in recovery\n") == 0)
154 {
155 if (cluster == &old_cluster)
156 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");
157 else
158 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");
159 }
160 else if (strcmp(p, "shut down\n") != 0)
161 {
162 if (cluster == &old_cluster)
163 pg_fatal("The source cluster was not shut down cleanly.\n");
164 else
165 pg_fatal("The target cluster was not shut down cleanly.\n");
166 }
167 got_cluster_state = true;
168 }
169 }
170
171 pclose(output);
172
173 if (!got_cluster_state)
174 {
175 if (cluster == &old_cluster)
176 pg_fatal("The source cluster lacks cluster state information:\n");
177 else
178 pg_fatal("The target cluster lacks cluster state information:\n");
179 }
180 }
181
182 snprintf(cmd, sizeof(cmd), "\"%s/%s \"%s\"",
183 cluster->bindir,
184 live_check ? "pg_controldata\"" : "pg_resetxlog\" -n",
185 cluster->pgdata);
186 fflush(stdout);
187 fflush(stderr);
188
189 if ((output = popen(cmd, "r")) == NULL)
190 pg_fatal("could not get control data using %s: %s\n",
191 cmd, strerror(errno));
192
193 /* Only in <= 9.2 */
194 if (GET_MAJOR_VERSION(cluster->major_version) <= 902)
195 {
196 cluster->controldata.data_checksum_version = 0;
197 got_data_checksum_version = true;
198 }
199
200 /* we have the result of cmd in "output". so parse it line by line now */
201 while (fgets(bufin, sizeof(bufin), output))
202 {
203 pg_log(PG_VERBOSE, "%s", bufin);
204
205 if ((p = strstr(bufin, "pg_control version number:")) != NULL)
206 {
207 p = strchr(p, ':');
208
209 if (p == NULL || strlen(p) <= 1)
210 pg_fatal("%d: pg_resetxlog problem\n", __LINE__);
211
212 p++; /* remove ':' char */
213 cluster->controldata.ctrl_ver = str2uint(p);
214 }
215 else if ((p = strstr(bufin, "Catalog version number:")) != NULL)
216 {
217 p = strchr(p, ':');
218
219 if (p == NULL || strlen(p) <= 1)
220 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
221
222 p++; /* remove ':' char */
223 cluster->controldata.cat_ver = str2uint(p);
224 }
225 else if ((p = strstr(bufin, "Latest checkpoint's TimeLineID:")) != NULL)
226 {
227 p = strchr(p, ':');
228
229 if (p == NULL || strlen(p) <= 1)
230 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
231
232 p++; /* remove ':' char */
233 tli = str2uint(p);
234 got_tli = true;
235 }
236 else if ((p = strstr(bufin, "First log file ID after reset:")) != NULL)
237 {
238 p = strchr(p, ':');
239
240 if (p == NULL || strlen(p) <= 1)
241 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
242
243 p++; /* remove ':' char */
244 logid = str2uint(p);
245 got_log_id = true;
246 }
247 else if ((p = strstr(bufin, "First log file segment after reset:")) != NULL)
248 {
249 p = strchr(p, ':');
250
251 if (p == NULL || strlen(p) <= 1)
252 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
253
254 p++; /* remove ':' char */
255 segno = str2uint(p);
256 got_log_seg = true;
257 }
258 else if ((p = strstr(bufin, "Latest checkpoint's NextXID:")) != NULL)
259 {
260 p = strchr(p, ':');
261
262 if (p == NULL || strlen(p) <= 1)
263 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
264
265 p++; /* remove ':' char */
266 cluster->controldata.chkpnt_nxtepoch = str2uint(p);
267
268 /*
269 * Delimiter changed from '/' to ':' in 9.6. We don't test for
270 * the catalog version of the change because the catalog version
271 * is pulled from pg_controldata too, and it isn't worth adding an
272 * order dependency for this --- we just check the string.
273 */
274 if (strchr(p, '/') != NULL)
275 p = strchr(p, '/');
276 else if (GET_MAJOR_VERSION(cluster->major_version) >= 906)
277 p = strchr(p, ':');
278 else
279 p = NULL;
280
281 if (p == NULL || strlen(p) <= 1)
282 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
283
284 p++; /* remove '/' or ':' char */
285 cluster->controldata.chkpnt_nxtxid = str2uint(p);
286 got_xid = true;
287 }
288 else if ((p = strstr(bufin, "Latest checkpoint's NextOID:")) != NULL)
289 {
290 p = strchr(p, ':');
291
292 if (p == NULL || strlen(p) <= 1)
293 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
294
295 p++; /* remove ':' char */
296 cluster->controldata.chkpnt_nxtoid = str2uint(p);
297 got_oid = true;
298 }
299 else if ((p = strstr(bufin, "Latest checkpoint's NextMultiXactId:")) != NULL)
300 {
301 p = strchr(p, ':');
302
303 if (p == NULL || strlen(p) <= 1)
304 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
305
306 p++; /* remove ':' char */
307 cluster->controldata.chkpnt_nxtmulti = str2uint(p);
308 got_multi = true;
309 }
310 else if ((p = strstr(bufin, "Latest checkpoint's oldestXID:")) != NULL)
311 {
312 p = strchr(p, ':');
313
314 if (p == NULL || strlen(p) <= 1)
315 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
316
317 p++; /* remove ':' char */
318 cluster->controldata.chkpnt_oldstxid = str2uint(p);
319 got_oldestxid = true;
320 }
321 else if ((p = strstr(bufin, "Latest checkpoint's oldestMultiXid:")) != NULL)
322 {
323 p = strchr(p, ':');
324
325 if (p == NULL || strlen(p) <= 1)
326 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
327
328 p++; /* remove ':' char */
329 cluster->controldata.chkpnt_oldstMulti = str2uint(p);
330 got_oldestmulti = true;
331 }
332 else if ((p = strstr(bufin, "Latest checkpoint's NextMultiOffset:")) != NULL)
333 {
334 p = strchr(p, ':');
335
336 if (p == NULL || strlen(p) <= 1)
337 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
338
339 p++; /* remove ':' char */
340 cluster->controldata.chkpnt_nxtmxoff = str2uint(p);
341 got_mxoff = true;
342 }
343 else if ((p = strstr(bufin, "First log segment after reset:")) != NULL)
344 {
345 /* Skip the colon and any whitespace after it */
346 p = strchr(p, ':');
347 if (p == NULL || strlen(p) <= 1)
348 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
349 p = strpbrk(p, "01234567890ABCDEF");
350 if (p == NULL || strlen(p) <= 1)
351 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
352
353 /* Make sure it looks like a valid WAL file name */
354 if (strspn(p, "0123456789ABCDEF") != 24)
355 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
356
357 strlcpy(cluster->controldata.nextxlogfile, p, 25);
358 got_nextxlogfile = true;
359 }
360 else if ((p = strstr(bufin, "Float8 argument passing:")) != NULL)
361 {
362 p = strchr(p, ':');
363
364 if (p == NULL || strlen(p) <= 1)
365 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
366
367 p++; /* remove ':' char */
368 /* used later for contrib check */
369 cluster->controldata.float8_pass_by_value = strstr(p, "by value") != NULL;
370 got_float8_pass_by_value = true;
371 }
372 else if ((p = strstr(bufin, "Maximum data alignment:")) != NULL)
373 {
374 p = strchr(p, ':');
375
376 if (p == NULL || strlen(p) <= 1)
377 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
378
379 p++; /* remove ':' char */
380 cluster->controldata.align = str2uint(p);
381 got_align = true;
382 }
383 else if ((p = strstr(bufin, "Database block size:")) != NULL)
384 {
385 p = strchr(p, ':');
386
387 if (p == NULL || strlen(p) <= 1)
388 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
389
390 p++; /* remove ':' char */
391 cluster->controldata.blocksz = str2uint(p);
392 got_blocksz = true;
393 }
394 else if ((p = strstr(bufin, "Blocks per segment of large relation:")) != NULL)
395 {
396 p = strchr(p, ':');
397
398 if (p == NULL || strlen(p) <= 1)
399 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
400
401 p++; /* remove ':' char */
402 cluster->controldata.largesz = str2uint(p);
403 got_largesz = true;
404 }
405 else if ((p = strstr(bufin, "WAL block size:")) != NULL)
406 {
407 p = strchr(p, ':');
408
409 if (p == NULL || strlen(p) <= 1)
410 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
411
412 p++; /* remove ':' char */
413 cluster->controldata.walsz = str2uint(p);
414 got_walsz = true;
415 }
416 else if ((p = strstr(bufin, "Bytes per WAL segment:")) != NULL)
417 {
418 p = strchr(p, ':');
419
420 if (p == NULL || strlen(p) <= 1)
421 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
422
423 p++; /* remove ':' char */
424 cluster->controldata.walseg = str2uint(p);
425 got_walseg = true;
426 }
427 else if ((p = strstr(bufin, "Maximum length of identifiers:")) != NULL)
428 {
429 p = strchr(p, ':');
430
431 if (p == NULL || strlen(p) <= 1)
432 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
433
434 p++; /* remove ':' char */
435 cluster->controldata.ident = str2uint(p);
436 got_ident = true;
437 }
438 else if ((p = strstr(bufin, "Maximum columns in an index:")) != NULL)
439 {
440 p = strchr(p, ':');
441
442 if (p == NULL || strlen(p) <= 1)
443 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
444
445 p++; /* remove ':' char */
446 cluster->controldata.index = str2uint(p);
447 got_index = true;
448 }
449 else if ((p = strstr(bufin, "Maximum size of a TOAST chunk:")) != NULL)
450 {
451 p = strchr(p, ':');
452
453 if (p == NULL || strlen(p) <= 1)
454 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
455
456 p++; /* remove ':' char */
457 cluster->controldata.toast = str2uint(p);
458 got_toast = true;
459 }
460 else if ((p = strstr(bufin, "Size of a large-object chunk:")) != NULL)
461 {
462 p = strchr(p, ':');
463
464 if (p == NULL || strlen(p) <= 1)
465 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
466
467 p++; /* remove ':' char */
468 cluster->controldata.large_object = str2uint(p);
469 got_large_object = true;
470 }
471 else if ((p = strstr(bufin, "Date/time type storage:")) != NULL)
472 {
473 p = strchr(p, ':');
474
475 if (p == NULL || strlen(p) <= 1)
476 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
477
478 p++; /* remove ':' char */
479 cluster->controldata.date_is_int = strstr(p, "64-bit integers") != NULL;
480 got_date_is_int = true;
481 }
482 else if ((p = strstr(bufin, "checksum")) != NULL)
483 {
484 p = strchr(p, ':');
485
486 if (p == NULL || strlen(p) <= 1)
487 pg_fatal("%d: controldata retrieval problem\n", __LINE__);
488
489 p++; /* remove ':' char */
490 /* used later for contrib check */
491 cluster->controldata.data_checksum_version = str2uint(p);
492 got_data_checksum_version = true;
493 }
494 }
495
496 pclose(output);
497
498 /*
499 * Restore environment variables
500 */
501 pg_putenv("LC_COLLATE", lc_collate);
502 pg_putenv("LC_CTYPE", lc_ctype);
503 pg_putenv("LC_MONETARY", lc_monetary);
504 pg_putenv("LC_NUMERIC", lc_numeric);
505 pg_putenv("LC_TIME", lc_time);
506 pg_putenv("LANG", lang);
507 pg_putenv("LANGUAGE", language);
508 pg_putenv("LC_ALL", lc_all);
509 pg_putenv("LC_MESSAGES", lc_messages);
510
511 pg_free(lc_collate);
512 pg_free(lc_ctype);
513 pg_free(lc_monetary);
514 pg_free(lc_numeric);
515 pg_free(lc_time);
516 pg_free(lang);
517 pg_free(language);
518 pg_free(lc_all);
519 pg_free(lc_messages);
520
521 /*
522 * Before 9.3, pg_resetxlog reported the xlogid and segno of the first log
523 * file after reset as separate lines. Starting with 9.3, it reports the
524 * WAL file name. If the old cluster is older than 9.3, we construct the
525 * WAL file name from the xlogid and segno.
526 */
527 if (GET_MAJOR_VERSION(cluster->major_version) <= 902)
528 {
529 if (got_tli && got_log_id && got_log_seg)
530 {
531 snprintf(cluster->controldata.nextxlogfile, 25, "%08X%08X%08X",
532 tli, logid, segno);
533 got_nextxlogfile = true;
534 }
535 }
536
537 /* verify that we got all the mandatory pg_control data */
538 if (!got_xid || !got_oid ||
539 !got_multi || !got_oldestxid ||
540 (!got_oldestmulti &&
541 cluster->controldata.cat_ver >= MULTIXACT_FORMATCHANGE_CAT_VER) ||
542 !got_mxoff || (!live_check && !got_nextxlogfile) ||
543 !got_float8_pass_by_value || !got_align || !got_blocksz ||
544 !got_largesz || !got_walsz || !got_walseg || !got_ident ||
545 !got_index || !got_toast ||
546 (!got_large_object &&
547 cluster->controldata.ctrl_ver >= LARGE_OBJECT_SIZE_PG_CONTROL_VER) ||
548 !got_date_is_int || !got_data_checksum_version)
549 {
550 pg_log(PG_REPORT,
551 "The %s cluster lacks some required control information:\n",
552 CLUSTER_NAME(cluster));
553
554 if (!got_xid)
555 pg_log(PG_REPORT, " checkpoint next XID\n");
556
557 if (!got_oid)
558 pg_log(PG_REPORT, " latest checkpoint next OID\n");
559
560 if (!got_multi)
561 pg_log(PG_REPORT, " latest checkpoint next MultiXactId\n");
562
563 if (!got_oldestmulti &&
564 cluster->controldata.cat_ver >= MULTIXACT_FORMATCHANGE_CAT_VER)
565 pg_log(PG_REPORT, " latest checkpoint oldest MultiXactId\n");
566
567 if (!got_oldestxid)
568 pg_log(PG_REPORT, " latest checkpoint oldestXID\n");
569
570 if (!got_mxoff)
571 pg_log(PG_REPORT, " latest checkpoint next MultiXactOffset\n");
572
573 if (!live_check && !got_nextxlogfile)
574 pg_log(PG_REPORT, " first WAL segment after reset\n");
575
576 if (!got_float8_pass_by_value)
577 pg_log(PG_REPORT, " float8 argument passing method\n");
578
579 if (!got_align)
580 pg_log(PG_REPORT, " maximum alignment\n");
581
582 if (!got_blocksz)
583 pg_log(PG_REPORT, " block size\n");
584
585 if (!got_largesz)
586 pg_log(PG_REPORT, " large relation segment size\n");
587
588 if (!got_walsz)
589 pg_log(PG_REPORT, " WAL block size\n");
590
591 if (!got_walseg)
592 pg_log(PG_REPORT, " WAL segment size\n");
593
594 if (!got_ident)
595 pg_log(PG_REPORT, " maximum identifier length\n");
596
597 if (!got_index)
598 pg_log(PG_REPORT, " maximum number of indexed columns\n");
599
600 if (!got_toast)
601 pg_log(PG_REPORT, " maximum TOAST chunk size\n");
602
603 if (!got_large_object &&
604 cluster->controldata.ctrl_ver >= LARGE_OBJECT_SIZE_PG_CONTROL_VER)
605 pg_log(PG_REPORT, " large-object chunk size\n");
606
607 if (!got_date_is_int)
608 pg_log(PG_REPORT, " dates/times are integers?\n");
609
610 /* value added in Postgres 9.3 */
611 if (!got_data_checksum_version)
612 pg_log(PG_REPORT, " data checksum version\n");
613
614 pg_fatal("Cannot continue without required control information, terminating\n");
615 }
616 }
617
618
619 /*
620 * check_control_data()
621 *
622 * check to make sure the control data settings are compatible
623 */
624 void
check_control_data(ControlData * oldctrl,ControlData * newctrl)625 check_control_data(ControlData *oldctrl,
626 ControlData *newctrl)
627 {
628 if (oldctrl->align == 0 || oldctrl->align != newctrl->align)
629 pg_fatal("old and new pg_controldata alignments are invalid or do not match\n"
630 "Likely one cluster is a 32-bit install, the other 64-bit\n");
631
632 if (oldctrl->blocksz == 0 || oldctrl->blocksz != newctrl->blocksz)
633 pg_fatal("old and new pg_controldata block sizes are invalid or do not match\n");
634
635 if (oldctrl->largesz == 0 || oldctrl->largesz != newctrl->largesz)
636 pg_fatal("old and new pg_controldata maximum relation segment sizes are invalid or do not match\n");
637
638 if (oldctrl->walsz == 0 || oldctrl->walsz != newctrl->walsz)
639 pg_fatal("old and new pg_controldata WAL block sizes are invalid or do not match\n");
640
641 if (oldctrl->walseg == 0 || oldctrl->walseg != newctrl->walseg)
642 pg_fatal("old and new pg_controldata WAL segment sizes are invalid or do not match\n");
643
644 if (oldctrl->ident == 0 || oldctrl->ident != newctrl->ident)
645 pg_fatal("old and new pg_controldata maximum identifier lengths are invalid or do not match\n");
646
647 if (oldctrl->index == 0 || oldctrl->index != newctrl->index)
648 pg_fatal("old and new pg_controldata maximum indexed columns are invalid or do not match\n");
649
650 if (oldctrl->toast == 0 || oldctrl->toast != newctrl->toast)
651 pg_fatal("old and new pg_controldata maximum TOAST chunk sizes are invalid or do not match\n");
652
653 /* large_object added in 9.5, so it might not exist in the old cluster */
654 if (oldctrl->large_object != 0 &&
655 oldctrl->large_object != newctrl->large_object)
656 pg_fatal("old and new pg_controldata large-object chunk sizes are invalid or do not match\n");
657
658 if (oldctrl->date_is_int != newctrl->date_is_int)
659 pg_fatal("old and new pg_controldata date/time storage types do not match\n");
660
661 /*
662 * float8_pass_by_value does not need to match, but is used in
663 * check_for_isn_and_int8_passing_mismatch().
664 */
665
666 /*
667 * We might eventually allow upgrades from checksum to no-checksum
668 * clusters.
669 */
670 if (oldctrl->data_checksum_version == 0 &&
671 newctrl->data_checksum_version != 0)
672 pg_fatal("old cluster does not use data checksums but the new one does\n");
673 else if (oldctrl->data_checksum_version != 0 &&
674 newctrl->data_checksum_version == 0)
675 pg_fatal("old cluster uses data checksums but the new one does not\n");
676 else if (oldctrl->data_checksum_version != newctrl->data_checksum_version)
677 pg_fatal("old and new cluster pg_controldata checksum versions do not match\n");
678 }
679
680
681 void
disable_old_cluster(void)682 disable_old_cluster(void)
683 {
684 char old_path[MAXPGPATH],
685 new_path[MAXPGPATH];
686
687 /* rename pg_control so old server cannot be accidentally started */
688 prep_status("Adding \".old\" suffix to old global/pg_control");
689
690 snprintf(old_path, sizeof(old_path), "%s/global/pg_control", old_cluster.pgdata);
691 snprintf(new_path, sizeof(new_path), "%s/global/pg_control.old", old_cluster.pgdata);
692 if (pg_mv_file(old_path, new_path) != 0)
693 pg_fatal("Unable to rename %s to %s.\n", old_path, new_path);
694 check_ok();
695
696 pg_log(PG_REPORT, "\n"
697 "If you want to start the old cluster, you will need to remove\n"
698 "the \".old\" suffix from %s/global/pg_control.old.\n"
699 "Because \"link\" mode was used, the old cluster cannot be safely\n"
700 "started once the new cluster has been started.\n\n", old_cluster.pgdata);
701 }
702