PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
controldata.c File Reference
#include "postgres_fe.h"
#include <ctype.h>
#include <limits.h>
#include "common/string.h"
#include "pg_upgrade.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 (void)
 

Function Documentation

◆ check_control_data()

void check_control_data ( ControlData oldctrl,
ControlData newctrl 
)

Definition at line 697 of file controldata.c.

699{
700 if (oldctrl->align == 0 || oldctrl->align != newctrl->align)
701 pg_fatal("old and new pg_controldata alignments are invalid or do not match.\n"
702 "Likely one cluster is a 32-bit install, the other 64-bit");
703
704 if (oldctrl->blocksz == 0 || oldctrl->blocksz != newctrl->blocksz)
705 pg_fatal("old and new pg_controldata block sizes are invalid or do not match");
706
707 if (oldctrl->largesz == 0 || oldctrl->largesz != newctrl->largesz)
708 pg_fatal("old and new pg_controldata maximum relation segment sizes are invalid or do not match");
709
710 if (oldctrl->walsz == 0 || oldctrl->walsz != newctrl->walsz)
711 pg_fatal("old and new pg_controldata WAL block sizes are invalid or do not match");
712
713 if (oldctrl->walseg == 0 || oldctrl->walseg != newctrl->walseg)
714 pg_fatal("old and new pg_controldata WAL segment sizes are invalid or do not match");
715
716 if (oldctrl->ident == 0 || oldctrl->ident != newctrl->ident)
717 pg_fatal("old and new pg_controldata maximum identifier lengths are invalid or do not match");
718
719 if (oldctrl->index == 0 || oldctrl->index != newctrl->index)
720 pg_fatal("old and new pg_controldata maximum indexed columns are invalid or do not match");
721
722 if (oldctrl->toast == 0 || oldctrl->toast != newctrl->toast)
723 pg_fatal("old and new pg_controldata maximum TOAST chunk sizes are invalid or do not match");
724
725 /* large_object added in 9.5, so it might not exist in the old cluster */
726 if (oldctrl->large_object != 0 &&
727 oldctrl->large_object != newctrl->large_object)
728 pg_fatal("old and new pg_controldata large-object chunk sizes are invalid or do not match");
729
730 if (oldctrl->date_is_int != newctrl->date_is_int)
731 pg_fatal("old and new pg_controldata date/time storage types do not match");
732
733 /*
734 * float8_pass_by_value does not need to match, but is used in
735 * check_for_isn_and_int8_passing_mismatch().
736 */
737
738 /*
739 * We might eventually allow upgrades from checksum to no-checksum
740 * clusters.
741 */
742 if (oldctrl->data_checksum_version == 0 &&
743 newctrl->data_checksum_version != 0)
744 pg_fatal("old cluster does not use data checksums but the new one does");
745 else if (oldctrl->data_checksum_version != 0 &&
746 newctrl->data_checksum_version == 0)
747 pg_fatal("old cluster uses data checksums but the new one does not");
748 else if (oldctrl->data_checksum_version != newctrl->data_checksum_version)
749 pg_fatal("old and new cluster pg_controldata checksum versions do not match");
750}
#define pg_fatal(...)
uint32 data_checksum_version
Definition: pg_upgrade.h:252
uint32 toast
Definition: pg_upgrade.h:248
uint32 index
Definition: pg_upgrade.h:247
uint32 walseg
Definition: pg_upgrade.h:245
uint32 blocksz
Definition: pg_upgrade.h:242
uint32 walsz
Definition: pg_upgrade.h:244
uint32 ident
Definition: pg_upgrade.h:246
bool date_is_int
Definition: pg_upgrade.h:250
uint32 large_object
Definition: pg_upgrade.h:249
uint32 align
Definition: pg_upgrade.h:241
uint32 largesz
Definition: pg_upgrade.h:243

References ControlData::align, ControlData::blocksz, ControlData::data_checksum_version, ControlData::date_is_int, ControlData::ident, ControlData::index, ControlData::large_object, ControlData::largesz, pg_fatal, ControlData::toast, ControlData::walseg, and ControlData::walsz.

Referenced by check_cluster_compatibility().

◆ disable_old_cluster()

void disable_old_cluster ( void  )

Definition at line 754 of file controldata.c.

755{
756 char old_path[MAXPGPATH],
757 new_path[MAXPGPATH];
758
759 /* rename pg_control so old server cannot be accidentally started */
760 prep_status("Adding \".old\" suffix to old global/pg_control");
761
762 snprintf(old_path, sizeof(old_path), "%s/global/pg_control", old_cluster.pgdata);
763 snprintf(new_path, sizeof(new_path), "%s/global/pg_control.old", old_cluster.pgdata);
764 if (pg_mv_file(old_path, new_path) != 0)
765 pg_fatal("could not rename file \"%s\" to \"%s\": %m",
766 old_path, new_path);
767 check_ok();
768
769 pg_log(PG_REPORT, "\n"
770 "If you want to start the old cluster, you will need to remove\n"
771 "the \".old\" suffix from %s/global/pg_control.old.\n"
772 "Because \"link\" mode was used, the old cluster cannot be safely\n"
773 "started once the new cluster has been started.",
775}
static void check_ok(void)
Definition: initdb.c:2121
#define MAXPGPATH
ClusterInfo old_cluster
Definition: pg_upgrade.c:68
#define pg_mv_file
Definition: pg_upgrade.h:81
void void pg_log(eLogType type, const char *fmt,...) pg_attribute_printf(2
@ PG_REPORT
Definition: pg_upgrade.h:275
void prep_status(const char *fmt,...) pg_attribute_printf(1
#define snprintf
Definition: port.h:239
char * pgdata
Definition: pg_upgrade.h:291

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

Referenced by main().

◆ get_control_data()

void get_control_data ( ClusterInfo cluster)

Definition at line 37 of file controldata.c.

38{
39 char cmd[MAXPGPATH];
40 char bufin[MAX_STRING];
41 FILE *output;
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;
67 char *lc_collate = NULL;
68 char *lc_ctype = NULL;
69 char *lc_monetary = NULL;
70 char *lc_numeric = NULL;
71 char *lc_time = NULL;
72 char *lang = NULL;
73 char *language = NULL;
74 char *lc_all = NULL;
75 char *lc_messages = NULL;
76 uint32 tli = 0;
77 uint32 logid = 0;
78 uint32 segno = 0;
79 char *resetwal_bin;
80 int rc;
81 bool live_check = (cluster == &old_cluster && user_opts.live_check);
82
83 /*
84 * Because we test the pg_resetwal output as strings, it has to be in
85 * English. Copied from pg_regress.c.
86 */
87 if (getenv("LC_COLLATE"))
88 lc_collate = pg_strdup(getenv("LC_COLLATE"));
89 if (getenv("LC_CTYPE"))
90 lc_ctype = pg_strdup(getenv("LC_CTYPE"));
91 if (getenv("LC_MONETARY"))
92 lc_monetary = pg_strdup(getenv("LC_MONETARY"));
93 if (getenv("LC_NUMERIC"))
94 lc_numeric = pg_strdup(getenv("LC_NUMERIC"));
95 if (getenv("LC_TIME"))
96 lc_time = pg_strdup(getenv("LC_TIME"));
97 if (getenv("LANG"))
98 lang = pg_strdup(getenv("LANG"));
99 if (getenv("LANGUAGE"))
100 language = pg_strdup(getenv("LANGUAGE"));
101 if (getenv("LC_ALL"))
102 lc_all = pg_strdup(getenv("LC_ALL"));
103 if (getenv("LC_MESSAGES"))
104 lc_messages = pg_strdup(getenv("LC_MESSAGES"));
105
106 unsetenv("LC_COLLATE");
107 unsetenv("LC_CTYPE");
108 unsetenv("LC_MONETARY");
109 unsetenv("LC_NUMERIC");
110 unsetenv("LC_TIME");
111#ifndef WIN32
112 unsetenv("LANG");
113#else
114 /* On Windows the default locale may not be English, so force it */
115 setenv("LANG", "en", 1);
116#endif
117 unsetenv("LANGUAGE");
118 unsetenv("LC_ALL");
119 setenv("LC_MESSAGES", "C", 1);
120
121 /*
122 * Check for clean shutdown
123 */
124 if (!live_check || cluster == &new_cluster)
125 {
126 /* only pg_controldata outputs the cluster state */
127 snprintf(cmd, sizeof(cmd), "\"%s/pg_controldata\" \"%s\"",
128 cluster->bindir, cluster->pgdata);
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 /* we have the result of cmd in "output". so parse it line by line now */
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++; /* remove ':' char */
145
146 /*
147 * We checked earlier for a postmaster lock file, and if we
148 * found one, we tried to start/stop the server to replay the
149 * WAL. However, pg_ctl -m immediate doesn't leave a lock
150 * file, but does require WAL replay, so we check here that
151 * the server was shut down cleanly, from the controldata
152 * perspective.
153 */
154 /* Remove trailing newline and leading spaces */
155 (void) pg_strip_crlf(p);
156 while (*p == ' ')
157 p++;
158 if (strcmp(p, "shut down in recovery") == 0)
159 {
160 if (cluster == &old_cluster)
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 {
167 if (cluster == &old_cluster)
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
176 rc = pclose(output);
177 if (rc != 0)
178 pg_fatal("could not get control data using %s: %s",
179 cmd, wait_result_to_str(rc));
180
181 if (!got_cluster_state)
182 {
183 if (cluster == &old_cluster)
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 /* pg_resetxlog has been renamed to pg_resetwal in version 10 */
191 if (GET_MAJOR_VERSION(cluster->bin_version) <= 906)
192 resetwal_bin = "pg_resetxlog\" -n";
193 else
194 resetwal_bin = "pg_resetwal\" -n";
195 snprintf(cmd, sizeof(cmd), "\"%s/%s \"%s\"",
196 cluster->bindir,
197 live_check ? "pg_controldata\"" : resetwal_bin,
198 cluster->pgdata);
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 /* Only in <= 9.2 */
205 if (GET_MAJOR_VERSION(cluster->major_version) <= 902)
206 {
207 cluster->controldata.data_checksum_version = 0;
208 got_data_checksum_version = true;
209 }
210
211 /* we have the result of cmd in "output". so parse it line by line now */
212 while (fgets(bufin, sizeof(bufin), output))
213 {
214 /* In verbose mode, log each line */
215 pg_strip_crlf(bufin);
216 pg_log(PG_VERBOSE, "%s", bufin);
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++; /* remove ':' char */
226 cluster->controldata.ctrl_ver = str2uint(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++; /* remove ':' char */
236 cluster->controldata.cat_ver = str2uint(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++; /* remove ':' char */
246 tli = str2uint(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++; /* remove ':' char */
257 logid = str2uint(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++; /* remove ':' char */
268 segno = str2uint(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++; /* remove ':' char */
279 cluster->controldata.chkpnt_nxtepoch = str2uint(p);
280
281 /*
282 * Delimiter changed from '/' to ':' in 9.6. We don't test for
283 * the catalog version of the change because the catalog version
284 * is pulled from pg_controldata too, and it isn't worth adding an
285 * order dependency for this --- we just check the string.
286 */
287 if (strchr(p, '/') != NULL)
288 p = strchr(p, '/');
289 else if (GET_MAJOR_VERSION(cluster->major_version) >= 906)
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++; /* remove '/' or ':' char */
298 cluster->controldata.chkpnt_nxtxid = str2uint(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++; /* remove ':' char */
309 cluster->controldata.chkpnt_nxtoid = str2uint(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++; /* remove ':' char */
320 cluster->controldata.chkpnt_nxtmulti = str2uint(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++; /* remove ':' char */
331 cluster->controldata.chkpnt_oldstxid = str2uint(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++; /* remove ':' char */
342 cluster->controldata.chkpnt_oldstMulti = str2uint(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++; /* remove ':' char */
353 cluster->controldata.chkpnt_nxtmxoff = str2uint(p);
354 got_mxoff = true;
355 }
356 else if ((p = strstr(bufin, "First log segment after reset:")) != NULL)
357 {
358 /* Skip the colon and any whitespace after it */
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 /* Make sure it looks like a valid WAL file name */
367 if (strspn(p, "0123456789ABCDEF") != 24)
368 pg_fatal("%d: controldata retrieval problem", __LINE__);
369
370 strlcpy(cluster->controldata.nextxlogfile, p, 25);
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++; /* remove ':' char */
381 /* used later for contrib check */
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++; /* remove ':' char */
393 cluster->controldata.align = str2uint(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++; /* remove ':' char */
404 cluster->controldata.blocksz = str2uint(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++; /* remove ':' char */
415 cluster->controldata.largesz = str2uint(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++; /* remove ':' char */
426 cluster->controldata.walsz = str2uint(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++; /* remove ':' char */
437 cluster->controldata.walseg = str2uint(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++; /* remove ':' char */
448 cluster->controldata.ident = str2uint(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++; /* remove ':' char */
459 cluster->controldata.index = str2uint(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++; /* remove ':' char */
470 cluster->controldata.toast = str2uint(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++; /* remove ':' char */
481 cluster->controldata.large_object = str2uint(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++; /* remove ':' char */
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++; /* remove ':' char */
503 cluster->controldata.data_checksum_version = str2uint(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 /* Skip the colon and any whitespace after it */
514 p++;
515 while (isspace((unsigned char) *p))
516 p++;
517
518 /* The value should be either 'signed' or 'unsigned' */
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
527 rc = pclose(output);
528 if (rc != 0)
529 pg_fatal("could not get control data using %s: %s",
530 cmd, wait_result_to_str(rc));
531
532 /*
533 * Restore environment variables. Note all but LANG and LC_MESSAGES were
534 * unset above.
535 */
536 if (lc_collate)
537 setenv("LC_COLLATE", lc_collate, 1);
538 if (lc_ctype)
539 setenv("LC_CTYPE", lc_ctype, 1);
540 if (lc_monetary)
541 setenv("LC_MONETARY", lc_monetary, 1);
542 if (lc_numeric)
543 setenv("LC_NUMERIC", lc_numeric, 1);
544 if (lc_time)
545 setenv("LC_TIME", lc_time, 1);
546 if (lang)
547 setenv("LANG", lang, 1);
548 else
549 unsetenv("LANG");
550 if (language)
551 setenv("LANGUAGE", language, 1);
552 if (lc_all)
553 setenv("LC_ALL", lc_all, 1);
554 if (lc_messages)
555 setenv("LC_MESSAGES", lc_messages, 1);
556 else
557 unsetenv("LC_MESSAGES");
558
564 pg_free(lang);
565 pg_free(language);
566 pg_free(lc_all);
568
569 /*
570 * Before 9.3, pg_resetwal reported the xlogid and segno of the first log
571 * file after reset as separate lines. Starting with 9.3, it reports the
572 * WAL file name. If the old cluster is older than 9.3, we construct the
573 * WAL file name from the xlogid and segno.
574 */
575 if (GET_MAJOR_VERSION(cluster->major_version) <= 902)
576 {
577 if (got_tli && got_log_id && got_log_seg)
578 {
579 snprintf(cluster->controldata.nextxlogfile, 25, "%08X%08X%08X",
580 tli, logid, segno);
581 got_nextxlogfile = true;
582 }
583 }
584
585 /*
586 * Pre-v18 database clusters don't have the default char signedness
587 * information. We use the char signedness of the platform where
588 * pg_upgrade was built.
589 */
590 if (cluster->controldata.cat_ver < DEFAULT_CHAR_SIGNEDNESS_CAT_VER)
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 /* verify that we got all the mandatory pg_control data */
601 if (!got_xid || !got_oid ||
602 !got_multi || !got_oldestxid ||
603 (!got_oldestmulti &&
604 cluster->controldata.cat_ver >= MULTIXACT_FORMATCHANGE_CAT_VER) ||
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 &&
610 cluster->controldata.ctrl_ver >= LARGE_OBJECT_SIZE_PG_CONTROL_VER) ||
611 !got_date_is_int || !got_data_checksum_version ||
612 (!got_default_char_signedness &&
613 cluster->controldata.cat_ver >= DEFAULT_CHAR_SIGNEDNESS_CAT_VER))
614 {
615 if (cluster == &old_cluster)
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)
623 pg_log(PG_REPORT, " checkpoint next XID");
624
625 if (!got_oid)
626 pg_log(PG_REPORT, " latest checkpoint next OID");
627
628 if (!got_multi)
629 pg_log(PG_REPORT, " latest checkpoint next MultiXactId");
630
631 if (!got_oldestmulti &&
632 cluster->controldata.cat_ver >= MULTIXACT_FORMATCHANGE_CAT_VER)
633 pg_log(PG_REPORT, " latest checkpoint oldest MultiXactId");
634
635 if (!got_oldestxid)
636 pg_log(PG_REPORT, " latest checkpoint oldestXID");
637
638 if (!got_mxoff)
639 pg_log(PG_REPORT, " latest checkpoint next MultiXactOffset");
640
641 if (!live_check && !got_nextxlogfile)
642 pg_log(PG_REPORT, " first WAL segment after reset");
643
644 if (!got_float8_pass_by_value)
645 pg_log(PG_REPORT, " float8 argument passing method");
646
647 if (!got_align)
648 pg_log(PG_REPORT, " maximum alignment");
649
650 if (!got_blocksz)
651 pg_log(PG_REPORT, " block size");
652
653 if (!got_largesz)
654 pg_log(PG_REPORT, " large relation segment size");
655
656 if (!got_walsz)
657 pg_log(PG_REPORT, " WAL block size");
658
659 if (!got_walseg)
660 pg_log(PG_REPORT, " WAL segment size");
661
662 if (!got_ident)
663 pg_log(PG_REPORT, " maximum identifier length");
664
665 if (!got_index)
666 pg_log(PG_REPORT, " maximum number of indexed columns");
667
668 if (!got_toast)
669 pg_log(PG_REPORT, " maximum TOAST chunk size");
670
671 if (!got_large_object &&
672 cluster->controldata.ctrl_ver >= LARGE_OBJECT_SIZE_PG_CONTROL_VER)
673 pg_log(PG_REPORT, " large-object chunk size");
674
675 if (!got_date_is_int)
676 pg_log(PG_REPORT, " dates/times are integers?");
677
678 /* value added in Postgres 9.3 */
679 if (!got_data_checksum_version)
680 pg_log(PG_REPORT, " data checksum version");
681
682 /* value added in Postgres 18 */
683 if (!got_default_char_signedness)
684 pg_log(PG_REPORT, " default char signedness");
685
686 pg_fatal("Cannot continue without required control information, terminating");
687 }
688}
uint32_t uint32
Definition: c.h:502
void cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel)
Definition: cluster.c:107
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void pg_free(void *ptr)
Definition: fe_memutils.c:105
Assert(PointerIsAligned(start, uint64))
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:69
#define LARGE_OBJECT_SIZE_PG_CONTROL_VER
Definition: pg_upgrade.h:121
#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:272
#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:132
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:330
char * wait_result_to_str(int exitstatus)
Definition: wait_error.c:33
#define unsetenv(x)
Definition: win32_port.h:546
#define setenv(x, y, z)
Definition: win32_port.h:545

References Assert(), cluster(), DEFAULT_CHAR_SIGNEDNESS_CAT_VER, 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_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().