Age Owner Branch data TLA Line data Source code
1 : : /*
2 : : * controldata.c
3 : : *
4 : : * controldata functions
5 : : *
6 : : * Copyright (c) 2010-2026, PostgreSQL Global Development Group
7 : : * src/bin/pg_upgrade/controldata.c
8 : : */
9 : :
10 : : #include "postgres_fe.h"
11 : :
12 : : #include <ctype.h>
13 : : #include <limits.h> /* for CHAR_MIN */
14 : :
15 : : #include "access/xlog_internal.h"
16 : : #include "common/string.h"
17 : : #include "pg_upgrade.h"
18 : : #include "storage/checksum.h"
19 : :
20 : :
21 : : /*
22 : : * get_control_data()
23 : : *
24 : : * gets pg_control information in "ctrl". Assumes that bindir and
25 : : * datadir are valid absolute paths to postgresql bin and pgdata
26 : : * directories respectively *and* pg_resetwal is version compatible
27 : : * with datadir. The main purpose of this function is to get pg_control
28 : : * data in a version independent manner.
29 : : *
30 : : * The approach taken here is to invoke pg_resetwal with -n option
31 : : * and then pipe its output. With little string parsing we get the
32 : : * pg_control data. pg_resetwal cannot be run while the server is running
33 : : * so we use pg_controldata; pg_controldata doesn't provide all the fields
34 : : * we need to actually perform the upgrade, but it provides enough for
35 : : * check mode. We do not implement pg_resetwal -n because it is hard to
36 : : * return valid xid data for a running server.
37 : : */
38 : : void
648 nathan@postgresql.or 39 :CBC 36 : get_control_data(ClusterInfo *cluster)
40 : : {
41 : : char cmd[MAXPGPATH];
42 : : char bufin[MAX_STRING];
43 : : FILE *output;
44 : : char *p;
3857 bruce@momjian.us 45 : 36 : bool got_tli = false;
46 : 36 : bool got_log_id = false;
47 : 36 : bool got_log_seg = false;
5837 48 : 36 : bool got_xid = false;
49 : 36 : bool got_oid = false;
4850 alvherre@alvh.no-ip. 50 : 36 : bool got_multi = false;
51 : 36 : bool got_oldestmulti = false;
1744 bruce@momjian.us 52 : 36 : bool got_oldestxid = false;
3857 53 : 36 : bool got_mxoff = false;
54 : 36 : bool got_nextxlogfile = false;
55 : 36 : bool got_float8_pass_by_value = false;
5837 56 : 36 : bool got_align = false;
57 : 36 : bool got_blocksz = false;
58 : 36 : bool got_largesz = false;
59 : 36 : bool got_walsz = false;
60 : 36 : bool got_walseg = false;
61 : 36 : bool got_ident = false;
62 : 36 : bool got_index = false;
63 : 36 : bool got_toast = false;
4255 64 : 36 : bool got_large_object = false;
5837 65 : 36 : bool got_date_is_int = false;
4753 simon@2ndQuadrant.co 66 : 36 : bool got_data_checksum_version = false;
2838 bruce@momjian.us 67 : 36 : bool got_cluster_state = false;
438 msawada@postgresql.o 68 : 36 : bool got_default_char_signedness = false;
5719 bruce@momjian.us 69 : 36 : char *lc_collate = NULL;
70 : 36 : char *lc_ctype = NULL;
71 : 36 : char *lc_monetary = NULL;
72 : 36 : char *lc_numeric = NULL;
73 : 36 : char *lc_time = NULL;
5837 74 : 36 : char *lang = NULL;
5719 75 : 36 : char *language = NULL;
76 : 36 : char *lc_all = NULL;
77 : 36 : char *lc_messages = NULL;
3857 78 : 36 : uint32 tli = 0;
5061 heikki.linnakangas@i 79 : 36 : uint32 logid = 0;
80 : 36 : uint32 segno = 0;
81 : : char *resetwal_bin;
82 : : int rc;
648 nathan@postgresql.or 83 [ + + - + ]: 36 : 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 : : */
5719 bruce@momjian.us 89 [ - + ]: 36 : if (getenv("LC_COLLATE"))
5677 bruce@momjian.us 90 :UBC 0 : lc_collate = pg_strdup(getenv("LC_COLLATE"));
5719 bruce@momjian.us 91 [ - + ]:CBC 36 : if (getenv("LC_CTYPE"))
5677 bruce@momjian.us 92 :UBC 0 : lc_ctype = pg_strdup(getenv("LC_CTYPE"));
5719 bruce@momjian.us 93 [ - + ]:CBC 36 : if (getenv("LC_MONETARY"))
5677 bruce@momjian.us 94 :UBC 0 : lc_monetary = pg_strdup(getenv("LC_MONETARY"));
5719 bruce@momjian.us 95 [ + - ]:CBC 36 : if (getenv("LC_NUMERIC"))
5677 bruce@momjian.us 96 :GBC 36 : lc_numeric = pg_strdup(getenv("LC_NUMERIC"));
5719 bruce@momjian.us 97 [ - + ]:CBC 36 : if (getenv("LC_TIME"))
5677 bruce@momjian.us 98 :UBC 0 : lc_time = pg_strdup(getenv("LC_TIME"));
5837 bruce@momjian.us 99 [ + - ]:CBC 36 : if (getenv("LANG"))
5677 100 : 36 : lang = pg_strdup(getenv("LANG"));
5719 101 [ - + ]: 36 : if (getenv("LANGUAGE"))
5677 bruce@momjian.us 102 :UBC 0 : language = pg_strdup(getenv("LANGUAGE"));
5719 bruce@momjian.us 103 [ - + ]:CBC 36 : if (getenv("LC_ALL"))
5677 bruce@momjian.us 104 :UBC 0 : lc_all = pg_strdup(getenv("LC_ALL"));
5719 bruce@momjian.us 105 [ + - ]:CBC 36 : if (getenv("LC_MESSAGES"))
5677 106 : 36 : lc_messages = pg_strdup(getenv("LC_MESSAGES"));
107 : :
1952 tgl@sss.pgh.pa.us 108 : 36 : unsetenv("LC_COLLATE");
109 : 36 : unsetenv("LC_CTYPE");
110 : 36 : unsetenv("LC_MONETARY");
111 : 36 : unsetenv("LC_NUMERIC");
112 : 36 : unsetenv("LC_TIME");
113 : : #ifndef WIN32
114 : 36 : 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 : 36 : unsetenv("LANGUAGE");
120 : 36 : unsetenv("LC_ALL");
121 : 36 : setenv("LC_MESSAGES", "C", 1);
122 : :
123 : : /*
124 : : * Check for clean shutdown
125 : : */
2835 bruce@momjian.us 126 [ - + - - ]: 36 : if (!live_check || cluster == &new_cluster)
127 : : {
128 : : /* only pg_controldata outputs the cluster state */
129 : 36 : snprintf(cmd, sizeof(cmd), "\"%s/pg_controldata\" \"%s\"",
130 : : cluster->bindir, cluster->pgdata);
1345 tgl@sss.pgh.pa.us 131 : 36 : fflush(NULL);
132 : :
2835 bruce@momjian.us 133 [ - + ]: 36 : if ((output = popen(cmd, "r")) == NULL)
784 michael@paquier.xyz 134 :UBC 0 : 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 */
2835 bruce@momjian.us 137 [ + + ]:CBC 1980 : while (fgets(bufin, sizeof(bufin), output))
138 : : {
139 [ + + ]: 1908 : if ((p = strstr(bufin, "Database cluster state:")) != NULL)
140 : : {
141 : 36 : p = strchr(p, ':');
142 : :
143 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 144 :UBC 0 : pg_fatal("%d: database cluster state problem", __LINE__);
145 : :
2540 tgl@sss.pgh.pa.us 146 :CBC 36 : 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 */
1020 dgustafsson@postgres 157 : 36 : (void) pg_strip_crlf(p);
2835 bruce@momjian.us 158 [ + + ]: 576 : while (*p == ' ')
159 : 540 : p++;
1020 dgustafsson@postgres 160 [ - + ]: 36 : if (strcmp(p, "shut down in recovery") == 0)
161 : : {
2818 bruce@momjian.us 162 [ # # ]:UBC 0 : if (cluster == &old_cluster)
1393 tgl@sss.pgh.pa.us 163 : 0 : 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 : 0 : 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 : : }
1020 dgustafsson@postgres 167 [ - + ]:CBC 36 : else if (strcmp(p, "shut down") != 0)
168 : : {
2835 bruce@momjian.us 169 [ # # ]:UBC 0 : if (cluster == &old_cluster)
1020 dgustafsson@postgres 170 : 0 : pg_fatal("The source cluster was not shut down cleanly, state reported as: \"%s\"", p);
171 : : else
172 : 0 : pg_fatal("The target cluster was not shut down cleanly, state reported as: \"%s\"", p);
173 : : }
2835 bruce@momjian.us 174 :CBC 36 : got_cluster_state = true;
175 : : }
176 : : }
177 : :
1267 peter@eisentraut.org 178 : 36 : rc = pclose(output);
179 [ - + ]: 36 : if (rc != 0)
1267 peter@eisentraut.org 180 :UBC 0 : pg_fatal("could not get control data using %s: %s",
181 : : cmd, wait_result_to_str(rc));
182 : :
2835 bruce@momjian.us 183 [ - + ]:CBC 36 : if (!got_cluster_state)
184 : : {
2835 bruce@momjian.us 185 [ # # ]:UBC 0 : if (cluster == &old_cluster)
1393 tgl@sss.pgh.pa.us 186 : 0 : pg_fatal("The source cluster lacks cluster state information:");
187 : : else
188 : 0 : pg_fatal("The target cluster lacks cluster state information:");
189 : : }
190 : : }
191 : :
192 : : /* pg_resetxlog has been renamed to pg_resetwal in version 10 */
2037 bruce@momjian.us 193 [ - + ]:CBC 36 : if (GET_MAJOR_VERSION(cluster->bin_version) <= 906)
3366 rhaas@postgresql.org 194 :UBC 0 : resetwal_bin = "pg_resetxlog\" -n";
195 : : else
3366 rhaas@postgresql.org 196 :CBC 36 : resetwal_bin = "pg_resetwal\" -n";
4383 heikki.linnakangas@i 197 [ - + ]: 36 : snprintf(cmd, sizeof(cmd), "\"%s/%s \"%s\"",
198 : : cluster->bindir,
199 : : live_check ? "pg_controldata\"" : resetwal_bin,
200 : : cluster->pgdata);
1345 tgl@sss.pgh.pa.us 201 : 36 : fflush(NULL);
202 : :
5837 bruce@momjian.us 203 [ - + ]: 36 : if ((output = popen(cmd, "r")) == NULL)
784 michael@paquier.xyz 204 :UBC 0 : pg_fatal("could not get control data using %s: %m", cmd);
205 : :
206 : : /* Only in <= 9.2 */
4792 simon@2ndQuadrant.co 207 [ - + ]:CBC 36 : if (GET_MAJOR_VERSION(cluster->major_version) <= 902)
208 : : {
29 dgustafsson@postgres 209 :UNC 0 : cluster->controldata.data_checksum_version = PG_DATA_CHECKSUM_OFF;
4753 simon@2ndQuadrant.co 210 :UBC 0 : got_data_checksum_version = true;
211 : : }
212 : :
213 : : /* we have the result of cmd in "output". so parse it line by line now */
5837 bruce@momjian.us 214 [ + + ]:CBC 1368 : while (fgets(bufin, sizeof(bufin), output))
215 : : {
216 : : /* In verbose mode, log each line */
1393 tgl@sss.pgh.pa.us 217 : 1332 : pg_strip_crlf(bufin);
5167 bruce@momjian.us 218 : 1332 : pg_log(PG_VERBOSE, "%s", bufin);
219 : :
5837 220 [ + + ]: 1332 : if ((p = strstr(bufin, "pg_control version number:")) != NULL)
221 : : {
222 : 36 : p = strchr(p, ':');
223 : :
224 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 225 :UBC 0 : pg_fatal("%d: pg_resetwal problem", __LINE__);
226 : :
4254 bruce@momjian.us 227 :CBC 36 : p++; /* remove ':' char */
5698 228 : 36 : cluster->controldata.ctrl_ver = str2uint(p);
229 : : }
5837 230 [ + + ]: 1296 : else if ((p = strstr(bufin, "Catalog version number:")) != NULL)
231 : : {
232 : 36 : p = strchr(p, ':');
233 : :
234 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 235 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
236 : :
4254 bruce@momjian.us 237 :CBC 36 : p++; /* remove ':' char */
5698 238 : 36 : cluster->controldata.cat_ver = str2uint(p);
239 : : }
3857 240 [ + + ]: 1260 : else if ((p = strstr(bufin, "Latest checkpoint's TimeLineID:")) != NULL)
241 : : {
5837 242 : 36 : p = strchr(p, ':');
243 : :
244 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 245 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
246 : :
4254 bruce@momjian.us 247 :CBC 36 : p++; /* remove ':' char */
3857 248 : 36 : tli = str2uint(p);
249 : 36 : got_tli = true;
250 : : }
251 [ - + ]: 1224 : else if ((p = strstr(bufin, "First log file ID after reset:")) != NULL)
252 : : {
5837 bruce@momjian.us 253 :UBC 0 : p = strchr(p, ':');
254 : :
255 [ # # # # ]: 0 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 256 : 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
257 : :
4254 bruce@momjian.us 258 : 0 : p++; /* remove ':' char */
3857 259 : 0 : logid = str2uint(p);
260 : 0 : got_log_id = true;
261 : : }
3857 bruce@momjian.us 262 [ - + ]:CBC 1224 : else if ((p = strstr(bufin, "First log file segment after reset:")) != NULL)
263 : : {
5837 bruce@momjian.us 264 :UBC 0 : p = strchr(p, ':');
265 : :
266 [ # # # # ]: 0 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 267 : 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
268 : :
4254 bruce@momjian.us 269 : 0 : p++; /* remove ':' char */
3857 270 : 0 : segno = str2uint(p);
271 : 0 : got_log_seg = true;
272 : : }
5837 bruce@momjian.us 273 [ + + ]:CBC 1224 : else if ((p = strstr(bufin, "Latest checkpoint's NextXID:")) != NULL)
274 : : {
4260 275 : 36 : p = strchr(p, ':');
276 : :
277 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 278 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
279 : :
4254 bruce@momjian.us 280 :CBC 36 : p++; /* remove ':' char */
4260 281 : 36 : 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 : : */
3735 mail@joeconway.com 289 [ - + ]: 36 : if (strchr(p, '/') != NULL)
3735 mail@joeconway.com 290 :UBC 0 : p = strchr(p, '/');
3735 mail@joeconway.com 291 [ + - ]:CBC 36 : else if (GET_MAJOR_VERSION(cluster->major_version) >= 906)
292 : 36 : p = strchr(p, ':');
293 : : else
3735 mail@joeconway.com 294 :UBC 0 : p = NULL;
295 : :
4260 bruce@momjian.us 296 [ + - - + ]:CBC 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 297 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
298 : :
3735 mail@joeconway.com 299 :CBC 36 : p++; /* remove '/' or ':' char */
4260 bruce@momjian.us 300 : 36 : cluster->controldata.chkpnt_nxtxid = str2uint(p);
5837 301 : 36 : got_xid = true;
302 : : }
303 [ + + ]: 1188 : else if ((p = strstr(bufin, "Latest checkpoint's NextOID:")) != NULL)
304 : : {
305 : 36 : p = strchr(p, ':');
306 : :
307 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 308 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
309 : :
4254 bruce@momjian.us 310 :CBC 36 : p++; /* remove ':' char */
5698 311 : 36 : cluster->controldata.chkpnt_nxtoid = str2uint(p);
5837 312 : 36 : got_oid = true;
313 : : }
4850 alvherre@alvh.no-ip. 314 [ + + ]: 1152 : else if ((p = strstr(bufin, "Latest checkpoint's NextMultiXactId:")) != NULL)
315 : : {
316 : 36 : p = strchr(p, ':');
317 : :
318 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 319 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
320 : :
4254 bruce@momjian.us 321 :CBC 36 : p++; /* remove ':' char */
4850 alvherre@alvh.no-ip. 322 : 36 : cluster->controldata.chkpnt_nxtmulti = str2uint(p);
323 : 36 : got_multi = true;
324 : : }
1744 bruce@momjian.us 325 [ + + ]: 1116 : else if ((p = strstr(bufin, "Latest checkpoint's oldestXID:")) != NULL)
326 : : {
327 : 36 : p = strchr(p, ':');
328 : :
329 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 330 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
331 : :
1744 bruce@momjian.us 332 :CBC 36 : p++; /* remove ':' char */
333 : 36 : cluster->controldata.chkpnt_oldstxid = str2uint(p);
334 : 36 : got_oldestxid = true;
335 : : }
4850 alvherre@alvh.no-ip. 336 [ + + ]: 1080 : else if ((p = strstr(bufin, "Latest checkpoint's oldestMultiXid:")) != NULL)
337 : : {
338 : 36 : p = strchr(p, ':');
339 : :
340 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 341 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
342 : :
4254 bruce@momjian.us 343 :CBC 36 : p++; /* remove ':' char */
4850 alvherre@alvh.no-ip. 344 : 36 : cluster->controldata.chkpnt_oldstMulti = str2uint(p);
345 : 36 : got_oldestmulti = true;
346 : : }
347 [ + + ]: 1044 : else if ((p = strstr(bufin, "Latest checkpoint's NextMultiOffset:")) != NULL)
348 : : {
349 : 36 : p = strchr(p, ':');
350 : :
351 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 352 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
353 : :
4254 bruce@momjian.us 354 :CBC 36 : p++; /* remove ':' char */
4850 alvherre@alvh.no-ip. 355 : 36 : cluster->controldata.chkpnt_nxtmxoff = str2uint(p);
356 : 36 : got_mxoff = true;
357 : : }
1328 tgl@sss.pgh.pa.us 358 [ + + ]: 1008 : else if ((p = strstr(bufin, "First log segment after reset:")) != NULL)
359 : : {
360 : : /* Skip the colon and any whitespace after it */
4009 bruce@momjian.us 361 : 36 : p = strchr(p, ':');
362 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 363 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
14 michael@paquier.xyz 364 :GNC 36 : p = strpbrk(p, "0123456789ABCDEF");
4009 bruce@momjian.us 365 [ + - - + ]:CBC 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 366 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
367 : :
368 : : /* Make sure it looks like a valid WAL file name */
4009 bruce@momjian.us 369 [ - + ]:CBC 36 : if (strspn(p, "0123456789ABCDEF") != 24)
1393 tgl@sss.pgh.pa.us 370 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
371 : :
4009 bruce@momjian.us 372 :CBC 36 : strlcpy(cluster->controldata.nextxlogfile, p, 25);
373 : 36 : got_nextxlogfile = true;
374 : : }
3857 375 [ + + ]: 972 : else if ((p = strstr(bufin, "Float8 argument passing:")) != NULL)
376 : : {
377 : 36 : p = strchr(p, ':');
378 : :
379 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 380 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
381 : :
3857 bruce@momjian.us 382 :CBC 36 : p++; /* remove ':' char */
383 : : /* used later for contrib check */
384 : 36 : cluster->controldata.float8_pass_by_value = strstr(p, "by value") != NULL;
385 : 36 : got_float8_pass_by_value = true;
386 : : }
5837 387 [ + + ]: 936 : else if ((p = strstr(bufin, "Maximum data alignment:")) != NULL)
388 : : {
389 : 36 : p = strchr(p, ':');
390 : :
391 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 392 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
393 : :
4254 bruce@momjian.us 394 :CBC 36 : p++; /* remove ':' char */
5698 395 : 36 : cluster->controldata.align = str2uint(p);
5837 396 : 36 : got_align = true;
397 : : }
398 [ + + ]: 900 : else if ((p = strstr(bufin, "Database block size:")) != NULL)
399 : : {
400 : 36 : p = strchr(p, ':');
401 : :
402 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 403 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
404 : :
4254 bruce@momjian.us 405 :CBC 36 : p++; /* remove ':' char */
5698 406 : 36 : cluster->controldata.blocksz = str2uint(p);
5837 407 : 36 : got_blocksz = true;
408 : : }
409 [ + + ]: 864 : else if ((p = strstr(bufin, "Blocks per segment of large relation:")) != NULL)
410 : : {
411 : 36 : p = strchr(p, ':');
412 : :
413 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 414 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
415 : :
4254 bruce@momjian.us 416 :CBC 36 : p++; /* remove ':' char */
5698 417 : 36 : cluster->controldata.largesz = str2uint(p);
5837 418 : 36 : got_largesz = true;
419 : : }
420 [ + + ]: 828 : else if ((p = strstr(bufin, "WAL block size:")) != NULL)
421 : : {
422 : 36 : p = strchr(p, ':');
423 : :
424 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 425 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
426 : :
4254 bruce@momjian.us 427 :CBC 36 : p++; /* remove ':' char */
5698 428 : 36 : cluster->controldata.walsz = str2uint(p);
5837 429 : 36 : got_walsz = true;
430 : : }
431 [ + + ]: 792 : else if ((p = strstr(bufin, "Bytes per WAL segment:")) != NULL)
432 : : {
433 : 36 : p = strchr(p, ':');
434 : :
435 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 436 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
437 : :
4254 bruce@momjian.us 438 :CBC 36 : p++; /* remove ':' char */
5698 439 : 36 : cluster->controldata.walseg = str2uint(p);
5837 440 : 36 : got_walseg = true;
441 : : }
442 [ + + ]: 756 : else if ((p = strstr(bufin, "Maximum length of identifiers:")) != NULL)
443 : : {
444 : 36 : p = strchr(p, ':');
445 : :
446 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 447 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
448 : :
4254 bruce@momjian.us 449 :CBC 36 : p++; /* remove ':' char */
5698 450 : 36 : cluster->controldata.ident = str2uint(p);
5837 451 : 36 : got_ident = true;
452 : : }
453 [ + + ]: 720 : else if ((p = strstr(bufin, "Maximum columns in an index:")) != NULL)
454 : : {
455 : 36 : p = strchr(p, ':');
456 : :
457 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 458 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
459 : :
4254 bruce@momjian.us 460 :CBC 36 : p++; /* remove ':' char */
5698 461 : 36 : cluster->controldata.index = str2uint(p);
5837 462 : 36 : got_index = true;
463 : : }
464 [ + + ]: 684 : else if ((p = strstr(bufin, "Maximum size of a TOAST chunk:")) != NULL)
465 : : {
466 : 36 : p = strchr(p, ':');
467 : :
468 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 469 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
470 : :
4254 bruce@momjian.us 471 :CBC 36 : p++; /* remove ':' char */
5698 472 : 36 : cluster->controldata.toast = str2uint(p);
5837 473 : 36 : got_toast = true;
474 : : }
4255 475 [ + + ]: 648 : else if ((p = strstr(bufin, "Size of a large-object chunk:")) != NULL)
476 : : {
477 : 36 : p = strchr(p, ':');
478 : :
479 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 480 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
481 : :
4254 bruce@momjian.us 482 :CBC 36 : p++; /* remove ':' char */
4255 483 : 36 : cluster->controldata.large_object = str2uint(p);
484 : 36 : got_large_object = true;
485 : : }
5837 486 [ + + ]: 612 : else if ((p = strstr(bufin, "Date/time type storage:")) != NULL)
487 : : {
488 : 36 : p = strchr(p, ':');
489 : :
490 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 491 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
492 : :
4254 bruce@momjian.us 493 :CBC 36 : p++; /* remove ':' char */
5837 494 : 36 : cluster->controldata.date_is_int = strstr(p, "64-bit integers") != NULL;
495 : 36 : got_date_is_int = true;
496 : : }
4753 simon@2ndQuadrant.co 497 [ + + ]: 576 : else if ((p = strstr(bufin, "checksum")) != NULL)
498 : : {
4792 499 : 36 : p = strchr(p, ':');
500 : :
501 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
1393 tgl@sss.pgh.pa.us 502 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
503 : :
4254 bruce@momjian.us 504 :CBC 36 : p++; /* remove ':' char */
4753 simon@2ndQuadrant.co 505 : 36 : cluster->controldata.data_checksum_version = str2uint(p);
506 : 36 : got_data_checksum_version = true;
507 : : }
438 msawada@postgresql.o 508 [ + + ]: 540 : else if ((p = strstr(bufin, "Default char data signedness:")) != NULL)
509 : : {
510 : 36 : p = strchr(p, ':');
511 : :
512 [ + - - + ]: 36 : if (p == NULL || strlen(p) <= 1)
438 msawada@postgresql.o 513 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
514 : :
515 : : /* Skip the colon and any whitespace after it */
438 msawada@postgresql.o 516 :CBC 36 : p++;
517 [ + + ]: 360 : while (isspace((unsigned char) *p))
518 : 324 : p++;
519 : :
520 : : /* The value should be either 'signed' or 'unsigned' */
521 [ + + - + ]: 36 : if (strcmp(p, "signed") != 0 && strcmp(p, "unsigned") != 0)
438 msawada@postgresql.o 522 :UBC 0 : pg_fatal("%d: controldata retrieval problem", __LINE__);
523 : :
438 msawada@postgresql.o 524 :CBC 36 : cluster->controldata.default_char_signedness = strcmp(p, "signed") == 0;
525 : 36 : got_default_char_signedness = true;
526 : : }
527 : : }
528 : :
1267 peter@eisentraut.org 529 : 36 : rc = pclose(output);
530 [ - + ]: 36 : if (rc != 0)
1267 peter@eisentraut.org 531 :UBC 0 : 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 : : */
1952 tgl@sss.pgh.pa.us 538 [ - + ]:CBC 36 : if (lc_collate)
1952 tgl@sss.pgh.pa.us 539 :UBC 0 : setenv("LC_COLLATE", lc_collate, 1);
1952 tgl@sss.pgh.pa.us 540 [ - + ]:CBC 36 : if (lc_ctype)
1952 tgl@sss.pgh.pa.us 541 :UBC 0 : setenv("LC_CTYPE", lc_ctype, 1);
1952 tgl@sss.pgh.pa.us 542 [ - + ]:CBC 36 : if (lc_monetary)
1952 tgl@sss.pgh.pa.us 543 :UBC 0 : setenv("LC_MONETARY", lc_monetary, 1);
1952 tgl@sss.pgh.pa.us 544 [ + - ]:CBC 36 : if (lc_numeric)
1952 tgl@sss.pgh.pa.us 545 :GBC 36 : setenv("LC_NUMERIC", lc_numeric, 1);
1952 tgl@sss.pgh.pa.us 546 [ - + ]:CBC 36 : if (lc_time)
1952 tgl@sss.pgh.pa.us 547 :UBC 0 : setenv("LC_TIME", lc_time, 1);
1952 tgl@sss.pgh.pa.us 548 [ + - ]:CBC 36 : if (lang)
549 : 36 : setenv("LANG", lang, 1);
550 : : else
1952 tgl@sss.pgh.pa.us 551 :UBC 0 : unsetenv("LANG");
1952 tgl@sss.pgh.pa.us 552 [ - + ]:CBC 36 : if (language)
1952 tgl@sss.pgh.pa.us 553 :UBC 0 : setenv("LANGUAGE", language, 1);
1952 tgl@sss.pgh.pa.us 554 [ - + ]:CBC 36 : if (lc_all)
1952 tgl@sss.pgh.pa.us 555 :UBC 0 : setenv("LC_ALL", lc_all, 1);
1952 tgl@sss.pgh.pa.us 556 [ + - ]:CBC 36 : if (lc_messages)
557 : 36 : setenv("LC_MESSAGES", lc_messages, 1);
558 : : else
1952 tgl@sss.pgh.pa.us 559 :UBC 0 : unsetenv("LC_MESSAGES");
560 : :
5719 bruce@momjian.us 561 :CBC 36 : pg_free(lc_collate);
562 : 36 : pg_free(lc_ctype);
563 : 36 : pg_free(lc_monetary);
564 : 36 : pg_free(lc_numeric);
565 : 36 : pg_free(lc_time);
566 : 36 : pg_free(lang);
567 : 36 : pg_free(language);
568 : 36 : pg_free(lc_all);
569 : 36 : pg_free(lc_messages);
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 : : */
5061 heikki.linnakangas@i 577 [ - + ]: 36 : if (GET_MAJOR_VERSION(cluster->major_version) <= 902)
578 : : {
4009 bruce@momjian.us 579 [ # # # # :UBC 0 : if (got_tli && got_log_id && got_log_seg)
# # ]
580 : : {
5059 alvherre@alvh.no-ip. 581 : 0 : snprintf(cluster->controldata.nextxlogfile, 25, "%08X%08X%08X",
582 : : tli, logid, segno);
5061 heikki.linnakangas@i 583 : 0 : 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 : : */
438 msawada@postgresql.o 592 [ - + ]:CBC 36 : if (cluster->controldata.cat_ver < DEFAULT_CHAR_SIGNEDNESS_CAT_VER)
593 : : {
438 msawada@postgresql.o 594 [ # # ]:UBC 0 : Assert(!got_default_char_signedness);
595 : : #if CHAR_MIN != 0
596 : 0 : 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 */
5837 bruce@momjian.us 603 [ + - + - ]:CBC 36 : if (!got_xid || !got_oid ||
1744 604 [ + - + - ]: 36 : !got_multi || !got_oldestxid ||
4814 alvherre@alvh.no-ip. 605 [ - + ]: 36 : (!got_oldestmulti &&
4814 alvherre@alvh.no-ip. 606 [ # # ]:UBC 0 : cluster->controldata.cat_ver >= MULTIXACT_FORMATCHANGE_CAT_VER) ||
4009 bruce@momjian.us 607 [ + - + - :CBC 36 : !got_mxoff || (!live_check && !got_nextxlogfile) ||
+ - ]
3857 608 [ + - + - : 36 : !got_float8_pass_by_value || !got_align || !got_blocksz ||
+ - ]
609 [ + - + - : 36 : !got_largesz || !got_walsz || !got_walseg || !got_ident ||
+ - + - ]
610 [ + - + - ]: 36 : !got_index || !got_toast ||
4255 611 [ - + ]: 36 : (!got_large_object &&
4255 bruce@momjian.us 612 [ # # ]:UBC 0 : cluster->controldata.ctrl_ver >= LARGE_OBJECT_SIZE_PG_CONTROL_VER) ||
438 msawada@postgresql.o 613 [ + - + - ]:CBC 36 : !got_date_is_int || !got_data_checksum_version ||
614 [ - + ]: 36 : (!got_default_char_signedness &&
438 msawada@postgresql.o 615 [ # # ]:UBC 0 : cluster->controldata.cat_ver >= DEFAULT_CHAR_SIGNEDNESS_CAT_VER))
616 : : {
3217 alvherre@alvh.no-ip. 617 [ # # ]: 0 : if (cluster == &old_cluster)
618 : 0 : pg_log(PG_REPORT,
619 : : "The source cluster lacks some required control information:");
620 : : else
621 : 0 : pg_log(PG_REPORT,
622 : : "The target cluster lacks some required control information:");
623 : :
5837 bruce@momjian.us 624 [ # # ]: 0 : if (!got_xid)
1393 tgl@sss.pgh.pa.us 625 : 0 : pg_log(PG_REPORT, " checkpoint next XID");
626 : :
5837 bruce@momjian.us 627 [ # # ]: 0 : if (!got_oid)
1393 tgl@sss.pgh.pa.us 628 : 0 : pg_log(PG_REPORT, " latest checkpoint next OID");
629 : :
4850 alvherre@alvh.no-ip. 630 [ # # ]: 0 : if (!got_multi)
1393 tgl@sss.pgh.pa.us 631 : 0 : pg_log(PG_REPORT, " latest checkpoint next MultiXactId");
632 : :
4814 alvherre@alvh.no-ip. 633 [ # # ]: 0 : if (!got_oldestmulti &&
634 [ # # ]: 0 : cluster->controldata.cat_ver >= MULTIXACT_FORMATCHANGE_CAT_VER)
1393 tgl@sss.pgh.pa.us 635 : 0 : pg_log(PG_REPORT, " latest checkpoint oldest MultiXactId");
636 : :
1744 bruce@momjian.us 637 [ # # ]: 0 : if (!got_oldestxid)
1393 tgl@sss.pgh.pa.us 638 : 0 : pg_log(PG_REPORT, " latest checkpoint oldestXID");
639 : :
4009 bruce@momjian.us 640 [ # # ]: 0 : if (!got_mxoff)
1393 tgl@sss.pgh.pa.us 641 : 0 : pg_log(PG_REPORT, " latest checkpoint next MultiXactOffset");
642 : :
5061 heikki.linnakangas@i 643 [ # # # # ]: 0 : if (!live_check && !got_nextxlogfile)
1393 tgl@sss.pgh.pa.us 644 : 0 : pg_log(PG_REPORT, " first WAL segment after reset");
645 : :
3857 bruce@momjian.us 646 [ # # ]: 0 : if (!got_float8_pass_by_value)
1393 tgl@sss.pgh.pa.us 647 : 0 : pg_log(PG_REPORT, " float8 argument passing method");
648 : :
5837 bruce@momjian.us 649 [ # # ]: 0 : if (!got_align)
1393 tgl@sss.pgh.pa.us 650 : 0 : pg_log(PG_REPORT, " maximum alignment");
651 : :
5837 bruce@momjian.us 652 [ # # ]: 0 : if (!got_blocksz)
1393 tgl@sss.pgh.pa.us 653 : 0 : pg_log(PG_REPORT, " block size");
654 : :
5837 bruce@momjian.us 655 [ # # ]: 0 : if (!got_largesz)
1393 tgl@sss.pgh.pa.us 656 : 0 : pg_log(PG_REPORT, " large relation segment size");
657 : :
5837 bruce@momjian.us 658 [ # # ]: 0 : if (!got_walsz)
1393 tgl@sss.pgh.pa.us 659 : 0 : pg_log(PG_REPORT, " WAL block size");
660 : :
5837 bruce@momjian.us 661 [ # # ]: 0 : if (!got_walseg)
1393 tgl@sss.pgh.pa.us 662 : 0 : pg_log(PG_REPORT, " WAL segment size");
663 : :
5837 bruce@momjian.us 664 [ # # ]: 0 : if (!got_ident)
1393 tgl@sss.pgh.pa.us 665 : 0 : pg_log(PG_REPORT, " maximum identifier length");
666 : :
5837 bruce@momjian.us 667 [ # # ]: 0 : if (!got_index)
1393 tgl@sss.pgh.pa.us 668 : 0 : pg_log(PG_REPORT, " maximum number of indexed columns");
669 : :
5837 bruce@momjian.us 670 [ # # ]: 0 : if (!got_toast)
1393 tgl@sss.pgh.pa.us 671 : 0 : pg_log(PG_REPORT, " maximum TOAST chunk size");
672 : :
4255 bruce@momjian.us 673 [ # # ]: 0 : if (!got_large_object &&
674 [ # # ]: 0 : cluster->controldata.ctrl_ver >= LARGE_OBJECT_SIZE_PG_CONTROL_VER)
1393 tgl@sss.pgh.pa.us 675 : 0 : pg_log(PG_REPORT, " large-object chunk size");
676 : :
5837 bruce@momjian.us 677 [ # # ]: 0 : if (!got_date_is_int)
1393 tgl@sss.pgh.pa.us 678 : 0 : pg_log(PG_REPORT, " dates/times are integers?");
679 : :
680 : : /* value added in Postgres 9.3 */
4753 simon@2ndQuadrant.co 681 [ # # ]: 0 : if (!got_data_checksum_version)
1393 tgl@sss.pgh.pa.us 682 : 0 : pg_log(PG_REPORT, " data checksum version");
683 : :
684 : : /* value added in Postgres 18 */
438 msawada@postgresql.o 685 [ # # ]: 0 : if (!got_default_char_signedness)
686 : 0 : pg_log(PG_REPORT, " default char signedness");
687 : :
1393 tgl@sss.pgh.pa.us 688 : 0 : pg_fatal("Cannot continue without required control information, terminating");
689 : : }
5837 bruce@momjian.us 690 :CBC 36 : }
691 : :
692 : :
693 : : /*
694 : : * check_control_data()
695 : : *
696 : : * check to make sure the control data settings are compatible
697 : : */
698 : : void
5677 699 : 18 : check_control_data(ControlData *oldctrl,
700 : : ControlData *newctrl)
701 : : {
5837 702 [ + - - + ]: 18 : if (oldctrl->align == 0 || oldctrl->align != newctrl->align)
1393 tgl@sss.pgh.pa.us 703 :UBC 0 : 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 : :
5837 bruce@momjian.us 706 [ + - - + ]:CBC 18 : if (oldctrl->blocksz == 0 || oldctrl->blocksz != newctrl->blocksz)
1393 tgl@sss.pgh.pa.us 707 :UBC 0 : pg_fatal("old and new pg_controldata block sizes are invalid or do not match");
708 : :
5837 bruce@momjian.us 709 [ + - - + ]:CBC 18 : if (oldctrl->largesz == 0 || oldctrl->largesz != newctrl->largesz)
1393 tgl@sss.pgh.pa.us 710 :UBC 0 : pg_fatal("old and new pg_controldata maximum relation segment sizes are invalid or do not match");
711 : :
5837 bruce@momjian.us 712 [ + - - + ]:CBC 18 : if (oldctrl->walsz == 0 || oldctrl->walsz != newctrl->walsz)
1393 tgl@sss.pgh.pa.us 713 :UBC 0 : pg_fatal("old and new pg_controldata WAL block sizes are invalid or do not match");
714 : :
5837 bruce@momjian.us 715 [ + - - + ]:CBC 18 : if (oldctrl->walseg == 0 || oldctrl->walseg != newctrl->walseg)
1393 tgl@sss.pgh.pa.us 716 :UBC 0 : pg_fatal("old and new pg_controldata WAL segment sizes are invalid or do not match");
717 : :
5837 bruce@momjian.us 718 [ + - - + ]:CBC 18 : if (oldctrl->ident == 0 || oldctrl->ident != newctrl->ident)
1393 tgl@sss.pgh.pa.us 719 :UBC 0 : pg_fatal("old and new pg_controldata maximum identifier lengths are invalid or do not match");
720 : :
5837 bruce@momjian.us 721 [ + - - + ]:CBC 18 : if (oldctrl->index == 0 || oldctrl->index != newctrl->index)
1393 tgl@sss.pgh.pa.us 722 :UBC 0 : pg_fatal("old and new pg_controldata maximum indexed columns are invalid or do not match");
723 : :
5837 bruce@momjian.us 724 [ + - - + ]:CBC 18 : if (oldctrl->toast == 0 || oldctrl->toast != newctrl->toast)
1393 tgl@sss.pgh.pa.us 725 :UBC 0 : 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 */
4255 bruce@momjian.us 728 [ + - ]:CBC 18 : if (oldctrl->large_object != 0 &&
729 [ - + ]: 18 : oldctrl->large_object != newctrl->large_object)
1393 tgl@sss.pgh.pa.us 730 :UBC 0 : pg_fatal("old and new pg_controldata large-object chunk sizes are invalid or do not match");
731 : :
5837 bruce@momjian.us 732 [ - + ]:CBC 18 : if (oldctrl->date_is_int != newctrl->date_is_int)
1393 tgl@sss.pgh.pa.us 733 :UBC 0 : 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 : : */
32 dgustafsson@postgres 745 [ - + ]:GNC 18 : if (oldctrl->data_checksum_version > PG_DATA_CHECKSUM_VERSION)
32 dgustafsson@postgres 746 :UNC 0 : 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 : : */
29 dgustafsson@postgres 752 [ - + ]:GNC 18 : if (oldctrl->data_checksum_version == PG_DATA_CHECKSUM_OFF &&
29 dgustafsson@postgres 753 [ # # ]:UNC 0 : newctrl->data_checksum_version != PG_DATA_CHECKSUM_OFF)
1393 tgl@sss.pgh.pa.us 754 :UBC 0 : pg_fatal("old cluster does not use data checksums but the new one does");
29 dgustafsson@postgres 755 [ + - ]:GNC 18 : else if (oldctrl->data_checksum_version != PG_DATA_CHECKSUM_OFF &&
756 [ - + ]: 18 : newctrl->data_checksum_version == PG_DATA_CHECKSUM_OFF)
1393 tgl@sss.pgh.pa.us 757 :UBC 0 : pg_fatal("old cluster uses data checksums but the new one does not");
4101 bruce@momjian.us 758 [ - + ]:CBC 18 : else if (oldctrl->data_checksum_version != newctrl->data_checksum_version)
1393 tgl@sss.pgh.pa.us 759 :UBC 0 : pg_fatal("old and new cluster pg_controldata checksum versions do not match");
5837 bruce@momjian.us 760 :CBC 18 : }
761 : :
762 : :
763 : : void
406 nathan@postgresql.or 764 : 2 : disable_old_cluster(transferMode transfer_mode)
765 : : {
766 : : char old_path[MAXPGPATH],
767 : : new_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 */
382 fujii@postgresql.org 771 : 2 : prep_status("Adding \".old\" suffix to old \"%s\"", XLOG_CONTROL_FILE);
772 : :
393 773 : 2 : snprintf(old_path, sizeof(old_path), "%s/%s", old_cluster.pgdata, XLOG_CONTROL_FILE);
774 : 2 : snprintf(new_path, sizeof(new_path), "%s/%s.old", old_cluster.pgdata, XLOG_CONTROL_FILE);
5837 bruce@momjian.us 775 [ - + ]: 2 : if (pg_mv_file(old_path, new_path) != 0)
1393 tgl@sss.pgh.pa.us 776 :UBC 0 : pg_fatal("could not rename file \"%s\" to \"%s\": %m",
777 : : old_path, new_path);
5677 bruce@momjian.us 778 :CBC 2 : check_ok();
779 : :
406 nathan@postgresql.or 780 [ + + ]: 2 : if (transfer_mode == TRANSFER_MODE_LINK)
781 : : /* translator: %s/%s is the file path of the control file */
782 : 1 : 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.",
787 : : old_cluster.pgdata, XLOG_CONTROL_FILE);
788 [ + - ]: 1 : else if (transfer_mode == TRANSFER_MODE_SWAP)
789 : 1 : pg_log(PG_REPORT, "\n"
790 : : "Because \"swap\" mode was used, the old cluster can no longer be\n"
791 : : "safely started.");
792 : : else
406 nathan@postgresql.or 793 :UBC 0 : pg_fatal("unrecognized transfer mode");
5837 bruce@momjian.us 794 :CBC 2 : }
|