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