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 "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 655 of file controldata.c.

657{
658 if (oldctrl->align == 0 || oldctrl->align != newctrl->align)
659 pg_fatal("old and new pg_controldata alignments are invalid or do not match.\n"
660 "Likely one cluster is a 32-bit install, the other 64-bit");
661
662 if (oldctrl->blocksz == 0 || oldctrl->blocksz != newctrl->blocksz)
663 pg_fatal("old and new pg_controldata block sizes are invalid or do not match");
664
665 if (oldctrl->largesz == 0 || oldctrl->largesz != newctrl->largesz)
666 pg_fatal("old and new pg_controldata maximum relation segment sizes are invalid or do not match");
667
668 if (oldctrl->walsz == 0 || oldctrl->walsz != newctrl->walsz)
669 pg_fatal("old and new pg_controldata WAL block sizes are invalid or do not match");
670
671 if (oldctrl->walseg == 0 || oldctrl->walseg != newctrl->walseg)
672 pg_fatal("old and new pg_controldata WAL segment sizes are invalid or do not match");
673
674 if (oldctrl->ident == 0 || oldctrl->ident != newctrl->ident)
675 pg_fatal("old and new pg_controldata maximum identifier lengths are invalid or do not match");
676
677 if (oldctrl->index == 0 || oldctrl->index != newctrl->index)
678 pg_fatal("old and new pg_controldata maximum indexed columns are invalid or do not match");
679
680 if (oldctrl->toast == 0 || oldctrl->toast != newctrl->toast)
681 pg_fatal("old and new pg_controldata maximum TOAST chunk sizes are invalid or do not match");
682
683 /* large_object added in 9.5, so it might not exist in the old cluster */
684 if (oldctrl->large_object != 0 &&
685 oldctrl->large_object != newctrl->large_object)
686 pg_fatal("old and new pg_controldata large-object chunk sizes are invalid or do not match");
687
688 if (oldctrl->date_is_int != newctrl->date_is_int)
689 pg_fatal("old and new pg_controldata date/time storage types do not match");
690
691 /*
692 * float8_pass_by_value does not need to match, but is used in
693 * check_for_isn_and_int8_passing_mismatch().
694 */
695
696 /*
697 * We might eventually allow upgrades from checksum to no-checksum
698 * clusters.
699 */
700 if (oldctrl->data_checksum_version == 0 &&
701 newctrl->data_checksum_version != 0)
702 pg_fatal("old cluster does not use data checksums but the new one does");
703 else if (oldctrl->data_checksum_version != 0 &&
704 newctrl->data_checksum_version == 0)
705 pg_fatal("old cluster uses data checksums but the new one does not");
706 else if (oldctrl->data_checksum_version != newctrl->data_checksum_version)
707 pg_fatal("old and new cluster pg_controldata checksum versions do not match");
708}
#define pg_fatal(...)
uint32 data_checksum_version
Definition: pg_upgrade.h:247
uint32 toast
Definition: pg_upgrade.h:243
uint32 index
Definition: pg_upgrade.h:242
uint32 walseg
Definition: pg_upgrade.h:240
uint32 blocksz
Definition: pg_upgrade.h:237
uint32 walsz
Definition: pg_upgrade.h:239
uint32 ident
Definition: pg_upgrade.h:241
bool date_is_int
Definition: pg_upgrade.h:245
uint32 large_object
Definition: pg_upgrade.h:244
uint32 align
Definition: pg_upgrade.h:236
uint32 largesz
Definition: pg_upgrade.h:238

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 712 of file controldata.c.

713{
714 char old_path[MAXPGPATH],
715 new_path[MAXPGPATH];
716
717 /* rename pg_control so old server cannot be accidentally started */
718 prep_status("Adding \".old\" suffix to old global/pg_control");
719
720 snprintf(old_path, sizeof(old_path), "%s/global/pg_control", old_cluster.pgdata);
721 snprintf(new_path, sizeof(new_path), "%s/global/pg_control.old", old_cluster.pgdata);
722 if (pg_mv_file(old_path, new_path) != 0)
723 pg_fatal("could not rename file \"%s\" to \"%s\": %m",
724 old_path, new_path);
725 check_ok();
726
727 pg_log(PG_REPORT, "\n"
728 "If you want to start the old cluster, you will need to remove\n"
729 "the \".old\" suffix from %s/global/pg_control.old.\n"
730 "Because \"link\" mode was used, the old cluster cannot be safely\n"
731 "started once the new cluster has been started.",
733}
static void check_ok(void)
Definition: initdb.c:2119
#define MAXPGPATH
ClusterInfo old_cluster
Definition: pg_upgrade.c:67
#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:269
void prep_status(const char *fmt,...) pg_attribute_printf(1
#define snprintf
Definition: port.h:238
char * pgdata
Definition: pg_upgrade.h:285

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 36 of file controldata.c.

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