PostgreSQL Source Code git master
Loading...
Searching...
No Matches
controldata.c File Reference
#include "postgres_fe.h"
#include <ctype.h>
#include <limits.h>
#include "access/xlog_internal.h"
#include "common/string.h"
#include "pg_upgrade.h"
#include "storage/checksum.h"
Include dependency graph for controldata.c:

Go to the source code of this file.

Functions

void get_control_data (ClusterInfo *cluster)
 
void check_control_data (ControlData *oldctrl, ControlData *newctrl)
 
void disable_old_cluster (transferMode transfer_mode)
 

Function Documentation

◆ check_control_data()

void check_control_data ( ControlData oldctrl,
ControlData newctrl 
)

Definition at line 699 of file controldata.c.

701{
702 if (oldctrl->align == 0 || oldctrl->align != newctrl->align)
703 pg_fatal("old and new pg_controldata alignments are invalid or do not match.\n"
704 "Likely one cluster is a 32-bit install, the other 64-bit");
705
706 if (oldctrl->blocksz == 0 || oldctrl->blocksz != newctrl->blocksz)
707 pg_fatal("old and new pg_controldata block sizes are invalid or do not match");
708
709 if (oldctrl->largesz == 0 || oldctrl->largesz != newctrl->largesz)
710 pg_fatal("old and new pg_controldata maximum relation segment sizes are invalid or do not match");
711
712 if (oldctrl->walsz == 0 || oldctrl->walsz != newctrl->walsz)
713 pg_fatal("old and new pg_controldata WAL block sizes are invalid or do not match");
714
715 if (oldctrl->walseg == 0 || oldctrl->walseg != newctrl->walseg)
716 pg_fatal("old and new pg_controldata WAL segment sizes are invalid or do not match");
717
718 if (oldctrl->ident == 0 || oldctrl->ident != newctrl->ident)
719 pg_fatal("old and new pg_controldata maximum identifier lengths are invalid or do not match");
720
721 if (oldctrl->index == 0 || oldctrl->index != newctrl->index)
722 pg_fatal("old and new pg_controldata maximum indexed columns are invalid or do not match");
723
724 if (oldctrl->toast == 0 || oldctrl->toast != newctrl->toast)
725 pg_fatal("old and new pg_controldata maximum TOAST chunk sizes are invalid or do not match");
726
727 /* large_object added in 9.5, so it might not exist in the old cluster */
728 if (oldctrl->large_object != 0 &&
729 oldctrl->large_object != newctrl->large_object)
730 pg_fatal("old and new pg_controldata large-object chunk sizes are invalid or do not match");
731
732 if (oldctrl->date_is_int != newctrl->date_is_int)
733 pg_fatal("old and new pg_controldata date/time storage types do not match");
734
735 /*
736 * float8_pass_by_value does not need to match, but is used in
737 * check_for_isn_and_int8_passing_mismatch().
738 */
739
740 /*
741 * If data checksums are in any in-progress state then disallow the
742 * upgrade. The user should either let the process finish, or turn off
743 * data checksums, before retrying.
744 */
745 if (oldctrl->data_checksum_version > PG_DATA_CHECKSUM_VERSION)
746 pg_fatal("checksums are being enabled in the old cluster");
747
748 /*
749 * We might eventually allow upgrades from checksum to no-checksum
750 * clusters.
751 */
752 if (oldctrl->data_checksum_version == PG_DATA_CHECKSUM_OFF &&
753 newctrl->data_checksum_version != PG_DATA_CHECKSUM_OFF)
754 pg_fatal("old cluster does not use data checksums but the new one does");
755 else if (oldctrl->data_checksum_version != PG_DATA_CHECKSUM_OFF &&
756 newctrl->data_checksum_version == PG_DATA_CHECKSUM_OFF)
757 pg_fatal("old cluster uses data checksums but the new one does not");
758 else if (oldctrl->data_checksum_version != newctrl->data_checksum_version)
759 pg_fatal("old and new cluster pg_controldata checksum versions do not match");
760}
@ PG_DATA_CHECKSUM_VERSION
Definition checksum.h:29
@ PG_DATA_CHECKSUM_OFF
Definition checksum.h:28
#define pg_fatal(...)
static int fb(int x)

References fb(), PG_DATA_CHECKSUM_OFF, PG_DATA_CHECKSUM_VERSION, and pg_fatal.

Referenced by check_cluster_compatibility().

◆ disable_old_cluster()

void disable_old_cluster ( transferMode  transfer_mode)

Definition at line 764 of file controldata.c.

765{
766 char old_path[MAXPGPATH],
768
769 /* rename pg_control so old server cannot be accidentally started */
770 /* translator: %s is the file path of the control file */
771 prep_status("Adding \".old\" suffix to old \"%s\"", XLOG_CONTROL_FILE);
772
775 if (pg_mv_file(old_path, new_path) != 0)
776 pg_fatal("could not rename file \"%s\" to \"%s\": %m",
778 check_ok();
779
780 if (transfer_mode == TRANSFER_MODE_LINK)
781 /* translator: %s/%s is the file path of the control file */
782 pg_log(PG_REPORT, "\n"
783 "If you want to start the old cluster, you will need to remove\n"
784 "the \".old\" suffix from \"%s/%s.old\".\n"
785 "Because \"link\" mode was used, the old cluster cannot be safely\n"
786 "started once the new cluster has been started.",
788 else if (transfer_mode == TRANSFER_MODE_SWAP)
789 pg_log(PG_REPORT, "\n"
790 "Because \"swap\" mode was used, the old cluster can no longer be\n"
791 "safely started.");
792 else
793 pg_fatal("unrecognized transfer mode");
794}
static void check_ok(void)
Definition initdb.c:2132
#define MAXPGPATH
ClusterInfo old_cluster
Definition pg_upgrade.c:73
#define pg_mv_file
Definition pg_upgrade.h:81
void void pg_log(eLogType type, const char *fmt,...) pg_attribute_printf(2
@ TRANSFER_MODE_LINK
Definition pg_upgrade.h:271
@ TRANSFER_MODE_SWAP
Definition pg_upgrade.h:272
@ PG_REPORT
Definition pg_upgrade.h:283
void prep_status(const char *fmt,...) pg_attribute_printf(1
#define snprintf
Definition port.h:260
char * pgdata
Definition pg_upgrade.h:299
#define XLOG_CONTROL_FILE

References check_ok(), fb(), MAXPGPATH, old_cluster, pg_fatal, pg_log(), pg_mv_file, PG_REPORT, ClusterInfo::pgdata, prep_status(), snprintf, TRANSFER_MODE_LINK, TRANSFER_MODE_SWAP, and XLOG_CONTROL_FILE.

Referenced by main().

◆ get_control_data()

void get_control_data ( ClusterInfo cluster)

Definition at line 39 of file controldata.c.

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

References Assert, DEFAULT_CHAR_SIGNEDNESS_CAT_VER, fb(), GET_MAJOR_VERSION, LARGE_OBJECT_SIZE_PG_CONTROL_VER, lc_collate, lc_ctype, lc_messages, lc_monetary, lc_numeric, lc_time, UserOpts::live_check, MAX_STRING, MAXPGPATH, MULTIXACT_FORMATCHANGE_CAT_VER, new_cluster, old_cluster, output, PG_DATA_CHECKSUM_OFF, pg_fatal, pg_free(), pg_log(), PG_REPORT, pg_strdup(), pg_strip_crlf(), PG_VERBOSE, setenv, snprintf, str2uint(), strlcpy(), unsetenv, user_opts, and wait_result_to_str().

Referenced by check_cluster_compatibility().