LCOV - differential code coverage report
Current view: top level - src/bin/pg_upgrade - controldata.c (source / functions) Coverage Total Hit UNC LBC UIC UBC GBC GIC GNC CBC EUB ECB DUB DCB
Current: Differential Code Coverage HEAD vs 15 Lines: 65.1 % 418 272 72 8 31 35 19 114 7 132 79 95 13 37
Current Date: 2023-04-08 17:13:01 Functions: 66.7 % 3 2 1 2 1 1 1
Baseline: 15 Line coverage date bins:
Baseline Date: 2023-04-08 15:09:40 (120,180] days: 66.7 % 6 4 2 4
Legend: Lines: hit not hit (180,240] days: 100.0 % 3 3 1 2
(240..) days: 64.8 % 409 265 70 8 31 35 19 113 1 132 76 95
Function coverage date bins:
(240..) days: 40.0 % 5 2 1 2 1 1

 Age         Owner                  TLA  Line data    Source code
                                  1                 : /*
                                  2                 :  *  controldata.c
                                  3                 :  *
                                  4                 :  *  controldata functions
                                  5                 :  *
                                  6                 :  *  Copyright (c) 2010-2023, PostgreSQL Global Development Group
                                  7                 :  *  src/bin/pg_upgrade/controldata.c
                                  8                 :  */
                                  9                 : 
                                 10                 : #include "postgres_fe.h"
                                 11                 : 
                                 12                 : #include <ctype.h>
                                 13                 : 
                                 14                 : #include "pg_upgrade.h"
                                 15                 : #include "common/string.h"
                                 16                 : 
                                 17                 : 
                                 18                 : /*
                                 19                 :  * get_control_data()
                                 20                 :  *
                                 21                 :  * gets pg_control information in "ctrl". Assumes that bindir and
                                 22                 :  * datadir are valid absolute paths to postgresql bin and pgdata
                                 23                 :  * directories respectively *and* pg_resetwal is version compatible
                                 24                 :  * with datadir. The main purpose of this function is to get pg_control
                                 25                 :  * data in a version independent manner.
                                 26                 :  *
                                 27                 :  * The approach taken here is to invoke pg_resetwal with -n option
                                 28                 :  * and then pipe its output. With little string parsing we get the
                                 29                 :  * pg_control data.  pg_resetwal cannot be run while the server is running
                                 30                 :  * so we use pg_controldata;  pg_controldata doesn't provide all the fields
                                 31                 :  * we need to actually perform the upgrade, but it provides enough for
                                 32                 :  * check mode.  We do not implement pg_resetwal -n because it is hard to
                                 33                 :  * return valid xid data for a running server.
                                 34                 :  */
                                 35                 : void
 4555 bruce                      36 GIC           4 : get_control_data(ClusterInfo *cluster, bool live_check)
                                 37                 : {
 4715 bruce                      38 ECB             :     char        cmd[MAXPGPATH];
                                 39                 :     char        bufin[MAX_STRING];
                                 40                 :     FILE       *output;
                                 41                 :     char       *p;
 2735 bruce                      42 GIC           4 :     bool        got_tli = false;
                                 43               4 :     bool        got_log_id = false;
 2735 bruce                      44 CBC           4 :     bool        got_log_seg = false;
 4715                            45               4 :     bool        got_xid = false;
                                 46               4 :     bool        got_oid = false;
 3728 alvherre                   47               4 :     bool        got_multi = false;
                                 48               4 :     bool        got_oldestmulti = false;
  622 bruce                      49               4 :     bool        got_oldestxid = false;
 2735                            50               4 :     bool        got_mxoff = false;
                                 51               4 :     bool        got_nextxlogfile = false;
                                 52               4 :     bool        got_float8_pass_by_value = false;
 4715                            53               4 :     bool        got_align = false;
                                 54               4 :     bool        got_blocksz = false;
                                 55               4 :     bool        got_largesz = false;
                                 56               4 :     bool        got_walsz = false;
                                 57               4 :     bool        got_walseg = false;
                                 58               4 :     bool        got_ident = false;
                                 59               4 :     bool        got_index = false;
                                 60               4 :     bool        got_toast = false;
 3133                            61               4 :     bool        got_large_object = false;
 4715                            62               4 :     bool        got_date_is_int = false;
 3631 simon                      63               4 :     bool        got_data_checksum_version = false;
 1716 bruce                      64               4 :     bool        got_cluster_state = false;
 4597                            65               4 :     char       *lc_collate = NULL;
                                 66               4 :     char       *lc_ctype = NULL;
                                 67               4 :     char       *lc_monetary = NULL;
                                 68               4 :     char       *lc_numeric = NULL;
                                 69               4 :     char       *lc_time = NULL;
 4715                            70               4 :     char       *lang = NULL;
 4597                            71               4 :     char       *language = NULL;
                                 72               4 :     char       *lc_all = NULL;
                                 73               4 :     char       *lc_messages = NULL;
 2735                            74               4 :     uint32      tli = 0;
 3939 heikki.linnakangas         75               4 :     uint32      logid = 0;
                                 76               4 :     uint32      segno = 0;
 2244 rhaas                      77 ECB             :     char       *resetwal_bin;
                                 78                 :     int         rc;
                                 79                 : 
                                 80                 :     /*
                                 81                 :      * Because we test the pg_resetwal output as strings, it has to be in
                                 82                 :      * English.  Copied from pg_regress.c.
                                 83                 :      */
 4597 bruce                      84 GIC           4 :     if (getenv("LC_COLLATE"))
 4555 bruce                      85 UIC           0 :         lc_collate = pg_strdup(getenv("LC_COLLATE"));
 4597 bruce                      86 CBC           4 :     if (getenv("LC_CTYPE"))
 4555 bruce                      87 UBC           0 :         lc_ctype = pg_strdup(getenv("LC_CTYPE"));
 4597 bruce                      88 CBC           4 :     if (getenv("LC_MONETARY"))
 4555 bruce                      89 UBC           0 :         lc_monetary = pg_strdup(getenv("LC_MONETARY"));
 4597 bruce                      90 CBC           4 :     if (getenv("LC_NUMERIC"))
 4555 bruce                      91 UBC           0 :         lc_numeric = pg_strdup(getenv("LC_NUMERIC"));
 4597 bruce                      92 CBC           4 :     if (getenv("LC_TIME"))
 4555 bruce                      93 UBC           0 :         lc_time = pg_strdup(getenv("LC_TIME"));
 4715 bruce                      94 CBC           4 :     if (getenv("LANG"))
 4555 bruce                      95 GBC           4 :         lang = pg_strdup(getenv("LANG"));
 4597 bruce                      96 CBC           4 :     if (getenv("LANGUAGE"))
 4555 bruce                      97 LBC           0 :         language = pg_strdup(getenv("LANGUAGE"));
 4597 bruce                      98 CBC           4 :     if (getenv("LC_ALL"))
 4555 bruce                      99 UBC           0 :         lc_all = pg_strdup(getenv("LC_ALL"));
 4597 bruce                     100 CBC           4 :     if (getenv("LC_MESSAGES"))
 4555 bruce                     101 GBC           4 :         lc_messages = pg_strdup(getenv("LC_MESSAGES"));
 4555 bruce                     102 ECB             : 
  830 tgl                       103 CBC           4 :     unsetenv("LC_COLLATE");
  830 tgl                       104 GIC           4 :     unsetenv("LC_CTYPE");
  830 tgl                       105 CBC           4 :     unsetenv("LC_MONETARY");
                                106               4 :     unsetenv("LC_NUMERIC");
                                107               4 :     unsetenv("LC_TIME");
 4715 bruce                     108 ECB             : #ifndef WIN32
  830 tgl                       109 CBC           4 :     unsetenv("LANG");
                                110                 : #else
 1401 noah                      111 ECB             :     /* On Windows the default locale may not be English, so force it */
                                112                 :     setenv("LANG", "en", 1);
                                113                 : #endif
  830 tgl                       114 GIC           4 :     unsetenv("LANGUAGE");
                                115               4 :     unsetenv("LC_ALL");
  830 tgl                       116 CBC           4 :     setenv("LC_MESSAGES", "C", 1);
 4597 bruce                     117 ECB             : 
 1713                           118                 :     /*
                                119                 :      * Check for clean shutdown
                                120                 :      */
 1713 bruce                     121 GIC           4 :     if (!live_check || cluster == &new_cluster)
                                122                 :     {
 1713 bruce                     123 ECB             :         /* only pg_controldata outputs the cluster state */
 1713 bruce                     124 GIC           4 :         snprintf(cmd, sizeof(cmd), "\"%s/pg_controldata\" \"%s\"",
                                125                 :                  cluster->bindir, cluster->pgdata);
  223 tgl                       126 GNC           4 :         fflush(NULL);
 1713 bruce                     127 ECB             : 
 1713 bruce                     128 GIC           4 :         if ((output = popen(cmd, "r")) == NULL)
  271 tgl                       129 UNC           0 :             pg_fatal("could not get control data using %s: %s",
 1713 bruce                     130 UBC           0 :                      cmd, strerror(errno));
 1713 bruce                     131 EUB             : 
                                132                 :         /* we have the result of cmd in "output". so parse it line by line now */
 1713 bruce                     133 GIC         204 :         while (fgets(bufin, sizeof(bufin), output))
 1713 bruce                     134 ECB             :         {
 1713 bruce                     135 GIC         200 :             if ((p = strstr(bufin, "Database cluster state:")) != NULL)
 1713 bruce                     136 ECB             :             {
 1713 bruce                     137 GIC           4 :                 p = strchr(p, ':');
 1713 bruce                     138 ECB             : 
 1713 bruce                     139 GIC           4 :                 if (p == NULL || strlen(p) <= 1)
  271 tgl                       140 UNC           0 :                     pg_fatal("%d: database cluster state problem", __LINE__);
 1713 bruce                     141 EUB             : 
 1418 tgl                       142 GIC           4 :                 p++;            /* remove ':' char */
 1713 bruce                     143 ECB             : 
                                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 leading spaces */
 1713 bruce                     153 GIC          64 :                 while (*p == ' ')
 1713 bruce                     154 CBC          60 :                     p++;
 1696                           155               4 :                 if (strcmp(p, "shut down in recovery\n") == 0)
 1696 bruce                     156 ECB             :                 {
 1696 bruce                     157 UIC           0 :                     if (cluster == &old_cluster)
  271 tgl                       158 UNC           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.");
 1696 bruce                     159 EUB             :                     else
  271 tgl                       160 UNC           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.");
 1696 bruce                     161 EUB             :                 }
 1696 bruce                     162 GIC           4 :                 else if (strcmp(p, "shut down\n") != 0)
 1713 bruce                     163 ECB             :                 {
 1713 bruce                     164 UIC           0 :                     if (cluster == &old_cluster)
  271 tgl                       165 UNC           0 :                         pg_fatal("The source cluster was not shut down cleanly.");
 1713 bruce                     166 EUB             :                     else
  271 tgl                       167 UNC           0 :                         pg_fatal("The target cluster was not shut down cleanly.");
 1713 bruce                     168 EUB             :                 }
 1713 bruce                     169 GIC           4 :                 got_cluster_state = true;
 1713 bruce                     170 ECB             :             }
                                171                 :         }
                                172                 : 
  145 peter                     173 GNC           4 :         rc = pclose(output);
                                174               4 :         if (rc != 0)
  145 peter                     175 UNC           0 :             pg_fatal("could not get control data using %s: %s",
                                176                 :                      cmd, wait_result_to_str(rc));
 1713 bruce                     177 ECB             : 
 1713 bruce                     178 CBC           4 :         if (!got_cluster_state)
 1713 bruce                     179 EUB             :         {
 1713 bruce                     180 UIC           0 :             if (cluster == &old_cluster)
  271 tgl                       181 UNC           0 :                 pg_fatal("The source cluster lacks cluster state information:");
 1713 bruce                     182 ECB             :             else
  271 tgl                       183 UNC           0 :                 pg_fatal("The target cluster lacks cluster state information:");
 1713 bruce                     184 EUB             :         }
                                185                 :     }
                                186                 : 
 2244 rhaas                     187                 :     /* pg_resetxlog has been renamed to pg_resetwal in version 10 */
  915 bruce                     188 GIC           4 :     if (GET_MAJOR_VERSION(cluster->bin_version) <= 906)
 2244 rhaas                     189 UIC           0 :         resetwal_bin = "pg_resetxlog\" -n";
                                190                 :     else
 2244 rhaas                     191 GIC           4 :         resetwal_bin = "pg_resetwal\" -n";
 3261 heikki.linnakangas        192 CBC           4 :     snprintf(cmd, sizeof(cmd), "\"%s/%s \"%s\"",
 4713 tgl                       193 EUB             :              cluster->bindir,
                                194                 :              live_check ? "pg_controldata\"" : resetwal_bin,
 4713 tgl                       195 ECB             :              cluster->pgdata);
  223 tgl                       196 GNC           4 :     fflush(NULL);
                                197                 : 
 4715 bruce                     198 GIC           4 :     if ((output = popen(cmd, "r")) == NULL)
  271 tgl                       199 UNC           0 :         pg_fatal("could not get control data using %s: %s",
 2382 tgl                       200 UIC           0 :                  cmd, strerror(errno));
 4715 bruce                     201 ECB             : 
 3670 simon                     202 EUB             :     /* Only in <= 9.2 */
 3670 simon                     203 GBC           4 :     if (GET_MAJOR_VERSION(cluster->major_version) <= 902)
                                204                 :     {
 3631 simon                     205 UIC           0 :         cluster->controldata.data_checksum_version = 0;
 3631 simon                     206 LBC           0 :         got_data_checksum_version = true;
                                207                 :     }
 3670 simon                     208 EUB             : 
 4715 bruce                     209                 :     /* we have the result of cmd in "output". so parse it line by line now */
 4715 bruce                     210 GIC         144 :     while (fgets(bufin, sizeof(bufin), output))
                                211                 :     {
                                212                 :         /* In verbose mode, log each line */
  271 tgl                       213 GNC         140 :         pg_strip_crlf(bufin);
 4045 bruce                     214 GIC         140 :         pg_log(PG_VERBOSE, "%s", bufin);
 4715 bruce                     215 ECB             : 
 4715 bruce                     216 GIC         140 :         if ((p = strstr(bufin, "pg_control version number:")) != NULL)
                                217                 :         {
 4715 bruce                     218 CBC           4 :             p = strchr(p, ':');
 4715 bruce                     219 ECB             : 
 4715 bruce                     220 GIC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       221 UNC           0 :                 pg_fatal("%d: pg_resetwal problem", __LINE__);
                                222                 : 
 3132 bruce                     223 CBC           4 :             p++;                /* remove ':' char */
 4576 bruce                     224 GIC           4 :             cluster->controldata.ctrl_ver = str2uint(p);
 4715 bruce                     225 ECB             :         }
 4715 bruce                     226 GBC         136 :         else if ((p = strstr(bufin, "Catalog version number:")) != NULL)
                                227                 :         {
 4715 bruce                     228 CBC           4 :             p = strchr(p, ':');
 4715 bruce                     229 ECB             : 
 4715 bruce                     230 GIC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       231 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                232                 : 
 3132 bruce                     233 CBC           4 :             p++;                /* remove ':' char */
 4576 bruce                     234 GIC           4 :             cluster->controldata.cat_ver = str2uint(p);
 4715 bruce                     235 ECB             :         }
 2735 bruce                     236 GBC         132 :         else if ((p = strstr(bufin, "Latest checkpoint's TimeLineID:")) != NULL)
                                237                 :         {
 4715 bruce                     238 CBC           4 :             p = strchr(p, ':');
 4715 bruce                     239 ECB             : 
 4715 bruce                     240 GIC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       241 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                242                 : 
 3132 bruce                     243 CBC           4 :             p++;                /* remove ':' char */
 2735 bruce                     244 GIC           4 :             tli = str2uint(p);
 2735 bruce                     245 CBC           4 :             got_tli = true;
 4715 bruce                     246 EUB             :         }
 2735 bruce                     247 GIC         128 :         else if ((p = strstr(bufin, "First log file ID after reset:")) != NULL)
 4715 bruce                     248 ECB             :         {
 4715 bruce                     249 LBC           0 :             p = strchr(p, ':');
 4715 bruce                     250 ECB             : 
 4715 bruce                     251 UIC           0 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       252 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                253                 : 
 3132 bruce                     254 UBC           0 :             p++;                /* remove ':' char */
 2735 bruce                     255 UIC           0 :             logid = str2uint(p);
 2735 bruce                     256 UBC           0 :             got_log_id = true;
 4715 bruce                     257 EUB             :         }
 2735 bruce                     258 GIC         128 :         else if ((p = strstr(bufin, "First log file segment after reset:")) != NULL)
 4715 bruce                     259 EUB             :         {
 4715 bruce                     260 UBC           0 :             p = strchr(p, ':');
 4715 bruce                     261 EUB             : 
 4715 bruce                     262 UIC           0 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       263 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                264                 : 
 3132 bruce                     265 UBC           0 :             p++;                /* remove ':' char */
 2735 bruce                     266 UIC           0 :             segno = str2uint(p);
 2735 bruce                     267 UBC           0 :             got_log_seg = true;
 4715 bruce                     268 EUB             :         }
 4715 bruce                     269 GIC         128 :         else if ((p = strstr(bufin, "Latest checkpoint's NextXID:")) != NULL)
 4715 bruce                     270 EUB             :         {
 3138 bruce                     271 GBC           4 :             p = strchr(p, ':');
 3138 bruce                     272 EUB             : 
 3138 bruce                     273 GIC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       274 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                275                 : 
 3132 bruce                     276 CBC           4 :             p++;                /* remove ':' char */
 3138 bruce                     277 GIC           4 :             cluster->controldata.chkpnt_nxtepoch = str2uint(p);
 4715 bruce                     278 ECB             : 
 2613 bruce                     279 EUB             :             /*
                                280                 :              * Delimiter changed from '/' to ':' in 9.6.  We don't test for
 2613 bruce                     281 ECB             :              * the catalog version of the change because the catalog version
 2495 rhaas                     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                 :              */
 2613 mail                      285 GIC           4 :             if (strchr(p, '/') != NULL)
 2613 mail                      286 UIC           0 :                 p = strchr(p, '/');
 2613 mail                      287 GIC           4 :             else if (GET_MAJOR_VERSION(cluster->major_version) >= 906)
                                288               4 :                 p = strchr(p, ':');
                                289                 :             else
 2613 mail                      290 LBC           0 :                 p = NULL;
 2613 mail                      291 EUB             : 
 3138 bruce                     292 CBC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       293 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                294                 : 
 2613 mail                      295 GBC           4 :             p++;                /* remove '/' or ':' char */
 3138 bruce                     296 GIC           4 :             cluster->controldata.chkpnt_nxtxid = str2uint(p);
 4715 bruce                     297 CBC           4 :             got_xid = true;
 4715 bruce                     298 EUB             :         }
 4715 bruce                     299 GIC         124 :         else if ((p = strstr(bufin, "Latest checkpoint's NextOID:")) != NULL)
 4715 bruce                     300 ECB             :         {
 4715 bruce                     301 CBC           4 :             p = strchr(p, ':');
 4715 bruce                     302 ECB             : 
 4715 bruce                     303 GIC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       304 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                305                 : 
 3132 bruce                     306 CBC           4 :             p++;                /* remove ':' char */
 4576 bruce                     307 GIC           4 :             cluster->controldata.chkpnt_nxtoid = str2uint(p);
 4715 bruce                     308 CBC           4 :             got_oid = true;
 4715 bruce                     309 EUB             :         }
 3728 alvherre                  310 GIC         120 :         else if ((p = strstr(bufin, "Latest checkpoint's NextMultiXactId:")) != NULL)
 3728 alvherre                  311 ECB             :         {
 3728 alvherre                  312 CBC           4 :             p = strchr(p, ':');
 3728 alvherre                  313 ECB             : 
 3728 alvherre                  314 GIC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       315 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                316                 : 
 3132 bruce                     317 CBC           4 :             p++;                /* remove ':' char */
 3728 alvherre                  318 GIC           4 :             cluster->controldata.chkpnt_nxtmulti = str2uint(p);
 3728 alvherre                  319 CBC           4 :             got_multi = true;
 3728 alvherre                  320 EUB             :         }
  622 bruce                     321 GIC         116 :         else if ((p = strstr(bufin, "Latest checkpoint's oldestXID:")) != NULL)
  622 bruce                     322 ECB             :         {
  622 bruce                     323 CBC           4 :             p = strchr(p, ':');
  622 bruce                     324 ECB             : 
  622 bruce                     325 GIC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       326 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                327                 : 
  622 bruce                     328 CBC           4 :             p++;                /* remove ':' char */
  622 bruce                     329 GIC           4 :             cluster->controldata.chkpnt_oldstxid = str2uint(p);
  622 bruce                     330 CBC           4 :             got_oldestxid = true;
  622 bruce                     331 EUB             :         }
 3728 alvherre                  332 GIC         112 :         else if ((p = strstr(bufin, "Latest checkpoint's oldestMultiXid:")) != NULL)
 3728 alvherre                  333 ECB             :         {
 3728 alvherre                  334 CBC           4 :             p = strchr(p, ':');
 3728 alvherre                  335 ECB             : 
 3728 alvherre                  336 GIC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       337 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                338                 : 
 3132 bruce                     339 CBC           4 :             p++;                /* remove ':' char */
 3728 alvherre                  340 GIC           4 :             cluster->controldata.chkpnt_oldstMulti = str2uint(p);
 3728 alvherre                  341 CBC           4 :             got_oldestmulti = true;
 3728 alvherre                  342 EUB             :         }
 3728 alvherre                  343 GIC         108 :         else if ((p = strstr(bufin, "Latest checkpoint's NextMultiOffset:")) != NULL)
 3728 alvherre                  344 ECB             :         {
 3728 alvherre                  345 CBC           4 :             p = strchr(p, ':');
 3728 alvherre                  346 ECB             : 
 3728 alvherre                  347 GIC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       348 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                349                 : 
 3132 bruce                     350 CBC           4 :             p++;                /* remove ':' char */
 3728 alvherre                  351 GIC           4 :             cluster->controldata.chkpnt_nxtmxoff = str2uint(p);
 3728 alvherre                  352 CBC           4 :             got_mxoff = true;
 3728 alvherre                  353 EUB             :         }
  206 tgl                       354 GIC         104 :         else if ((p = strstr(bufin, "First log segment after reset:")) != NULL)
 2887 bruce                     355 ECB             :         {
                                356                 :             /* Skip the colon and any whitespace after it */
 2887 bruce                     357 CBC           4 :             p = strchr(p, ':');
 2887 bruce                     358 GIC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       359 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
 2887 bruce                     360 GIC           4 :             p = strpbrk(p, "01234567890ABCDEF");
                                361               4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       362 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
 2887 bruce                     363 ECB             : 
 2887 bruce                     364 EUB             :             /* Make sure it looks like a valid WAL file name */
 2887 bruce                     365 CBC           4 :             if (strspn(p, "0123456789ABCDEF") != 24)
  271 tgl                       366 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
 2887 bruce                     367 EUB             : 
 2887 bruce                     368 GIC           4 :             strlcpy(cluster->controldata.nextxlogfile, p, 25);
                                369               4 :             got_nextxlogfile = true;
 2887 bruce                     370 ECB             :         }
 2735 bruce                     371 GBC         100 :         else if ((p = strstr(bufin, "Float8 argument passing:")) != NULL)
                                372                 :         {
 2735 bruce                     373 CBC           4 :             p = strchr(p, ':');
 2735 bruce                     374 ECB             : 
 2735 bruce                     375 GIC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       376 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                377                 : 
 2735 bruce                     378 CBC           4 :             p++;                /* remove ':' char */
                                379                 :             /* used later for contrib check */
                                380               4 :             cluster->controldata.float8_pass_by_value = strstr(p, "by value") != NULL;
 2735 bruce                     381 GBC           4 :             got_float8_pass_by_value = true;
                                382                 :         }
 4715 bruce                     383 CBC          96 :         else if ((p = strstr(bufin, "Maximum data alignment:")) != NULL)
                                384                 :         {
                                385               4 :             p = strchr(p, ':');
 4715 bruce                     386 ECB             : 
 4715 bruce                     387 GIC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       388 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                389                 : 
 3132 bruce                     390 CBC           4 :             p++;                /* remove ':' char */
 4576 bruce                     391 GIC           4 :             cluster->controldata.align = str2uint(p);
 4715 bruce                     392 CBC           4 :             got_align = true;
 4715 bruce                     393 EUB             :         }
 4715 bruce                     394 GIC          92 :         else if ((p = strstr(bufin, "Database block size:")) != NULL)
 4715 bruce                     395 ECB             :         {
 4715 bruce                     396 CBC           4 :             p = strchr(p, ':');
 4715 bruce                     397 ECB             : 
 4715 bruce                     398 GIC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       399 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                400                 : 
 3132 bruce                     401 CBC           4 :             p++;                /* remove ':' char */
 4576 bruce                     402 GIC           4 :             cluster->controldata.blocksz = str2uint(p);
 4715 bruce                     403 CBC           4 :             got_blocksz = true;
 4715 bruce                     404 EUB             :         }
 4715 bruce                     405 GIC          88 :         else if ((p = strstr(bufin, "Blocks per segment of large relation:")) != NULL)
 4715 bruce                     406 ECB             :         {
 4715 bruce                     407 CBC           4 :             p = strchr(p, ':');
 4715 bruce                     408 ECB             : 
 4715 bruce                     409 GIC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       410 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                411                 : 
 3132 bruce                     412 CBC           4 :             p++;                /* remove ':' char */
 4576 bruce                     413 GIC           4 :             cluster->controldata.largesz = str2uint(p);
 4715 bruce                     414 CBC           4 :             got_largesz = true;
 4715 bruce                     415 EUB             :         }
 4715 bruce                     416 GIC          84 :         else if ((p = strstr(bufin, "WAL block size:")) != NULL)
 4715 bruce                     417 ECB             :         {
 4715 bruce                     418 CBC           4 :             p = strchr(p, ':');
 4715 bruce                     419 ECB             : 
 4715 bruce                     420 GIC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       421 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                422                 : 
 3132 bruce                     423 CBC           4 :             p++;                /* remove ':' char */
 4576 bruce                     424 GIC           4 :             cluster->controldata.walsz = str2uint(p);
 4715 bruce                     425 CBC           4 :             got_walsz = true;
 4715 bruce                     426 EUB             :         }
 4715 bruce                     427 GIC          80 :         else if ((p = strstr(bufin, "Bytes per WAL segment:")) != NULL)
 4715 bruce                     428 ECB             :         {
 4715 bruce                     429 CBC           4 :             p = strchr(p, ':');
 4715 bruce                     430 ECB             : 
 4715 bruce                     431 GIC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       432 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                433                 : 
 3132 bruce                     434 CBC           4 :             p++;                /* remove ':' char */
 4576 bruce                     435 GIC           4 :             cluster->controldata.walseg = str2uint(p);
 4715 bruce                     436 CBC           4 :             got_walseg = true;
 4715 bruce                     437 EUB             :         }
 4715 bruce                     438 GIC          76 :         else if ((p = strstr(bufin, "Maximum length of identifiers:")) != NULL)
 4715 bruce                     439 ECB             :         {
 4715 bruce                     440 CBC           4 :             p = strchr(p, ':');
 4715 bruce                     441 ECB             : 
 4715 bruce                     442 GIC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       443 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                444                 : 
 3132 bruce                     445 CBC           4 :             p++;                /* remove ':' char */
 4576 bruce                     446 GIC           4 :             cluster->controldata.ident = str2uint(p);
 4715 bruce                     447 CBC           4 :             got_ident = true;
 4715 bruce                     448 EUB             :         }
 4715 bruce                     449 GIC          72 :         else if ((p = strstr(bufin, "Maximum columns in an index:")) != NULL)
 4715 bruce                     450 ECB             :         {
 4715 bruce                     451 CBC           4 :             p = strchr(p, ':');
 4715 bruce                     452 ECB             : 
 4715 bruce                     453 GIC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       454 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                455                 : 
 3132 bruce                     456 CBC           4 :             p++;                /* remove ':' char */
 4576 bruce                     457 GIC           4 :             cluster->controldata.index = str2uint(p);
 4715 bruce                     458 CBC           4 :             got_index = true;
 4715 bruce                     459 EUB             :         }
 4715 bruce                     460 GIC          68 :         else if ((p = strstr(bufin, "Maximum size of a TOAST chunk:")) != NULL)
 4715 bruce                     461 ECB             :         {
 4715 bruce                     462 CBC           4 :             p = strchr(p, ':');
 4715 bruce                     463 ECB             : 
 4715 bruce                     464 GIC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       465 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                466                 : 
 3132 bruce                     467 CBC           4 :             p++;                /* remove ':' char */
 4576 bruce                     468 GIC           4 :             cluster->controldata.toast = str2uint(p);
 4715 bruce                     469 CBC           4 :             got_toast = true;
 4715 bruce                     470 EUB             :         }
 3133 bruce                     471 GIC          64 :         else if ((p = strstr(bufin, "Size of a large-object chunk:")) != NULL)
 3133 bruce                     472 ECB             :         {
 3133 bruce                     473 CBC           4 :             p = strchr(p, ':');
 3133 bruce                     474 ECB             : 
 3133 bruce                     475 GIC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       476 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                477                 : 
 3132 bruce                     478 CBC           4 :             p++;                /* remove ':' char */
 3133 bruce                     479 GIC           4 :             cluster->controldata.large_object = str2uint(p);
 3133 bruce                     480 CBC           4 :             got_large_object = true;
 3133 bruce                     481 EUB             :         }
 4715 bruce                     482 GIC          60 :         else if ((p = strstr(bufin, "Date/time type storage:")) != NULL)
 4715 bruce                     483 ECB             :         {
 4715 bruce                     484 CBC           4 :             p = strchr(p, ':');
 4715 bruce                     485 ECB             : 
 4715 bruce                     486 GIC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       487 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                488                 : 
 3132 bruce                     489 CBC           4 :             p++;                /* remove ':' char */
 4715 bruce                     490 GIC           4 :             cluster->controldata.date_is_int = strstr(p, "64-bit integers") != NULL;
 4715 bruce                     491 CBC           4 :             got_date_is_int = true;
 4715 bruce                     492 EUB             :         }
 3631 simon                     493 GIC          56 :         else if ((p = strstr(bufin, "checksum")) != NULL)
 3670 simon                     494 ECB             :         {
 3670 simon                     495 CBC           4 :             p = strchr(p, ':');
 3670 simon                     496 ECB             : 
 3670 simon                     497 GIC           4 :             if (p == NULL || strlen(p) <= 1)
  271 tgl                       498 UNC           0 :                 pg_fatal("%d: controldata retrieval problem", __LINE__);
                                499                 : 
 3132 bruce                     500 CBC           4 :             p++;                /* remove ':' char */
 3631 simon                     501 GIC           4 :             cluster->controldata.data_checksum_version = str2uint(p);
 3631 simon                     502 CBC           4 :             got_data_checksum_version = true;
 3670 simon                     503 EUB             :         }
                                504                 :     }
 4715 bruce                     505 ECB             : 
  145 peter                     506 GNC           4 :     rc = pclose(output);
                                507               4 :     if (rc != 0)
  145 peter                     508 UNC           0 :         pg_fatal("could not get control data using %s: %s",
                                509                 :                  cmd, wait_result_to_str(rc));
 4715 bruce                     510 ECB             : 
                                511                 :     /*
                                512                 :      * Restore environment variables.  Note all but LANG and LC_MESSAGES were
                                513                 :      * unset above.
 4597                           514                 :      */
  830 tgl                       515 CBC           4 :     if (lc_collate)
  830 tgl                       516 UBC           0 :         setenv("LC_COLLATE", lc_collate, 1);
  830 tgl                       517 GIC           4 :     if (lc_ctype)
  830 tgl                       518 UIC           0 :         setenv("LC_CTYPE", lc_ctype, 1);
  830 tgl                       519 GIC           4 :     if (lc_monetary)
  830 tgl                       520 UIC           0 :         setenv("LC_MONETARY", lc_monetary, 1);
  830 tgl                       521 GIC           4 :     if (lc_numeric)
  830 tgl                       522 UIC           0 :         setenv("LC_NUMERIC", lc_numeric, 1);
  830 tgl                       523 CBC           4 :     if (lc_time)
  830 tgl                       524 UBC           0 :         setenv("LC_TIME", lc_time, 1);
  830 tgl                       525 CBC           4 :     if (lang)
  830 tgl                       526 GBC           4 :         setenv("LANG", lang, 1);
  830 tgl                       527 ECB             :     else
  830 tgl                       528 UBC           0 :         unsetenv("LANG");
  830 tgl                       529 CBC           4 :     if (language)
  830 tgl                       530 UBC           0 :         setenv("LANGUAGE", language, 1);
  830 tgl                       531 CBC           4 :     if (lc_all)
  830 tgl                       532 UBC           0 :         setenv("LC_ALL", lc_all, 1);
  830 tgl                       533 CBC           4 :     if (lc_messages)
                                534               4 :         setenv("LC_MESSAGES", lc_messages, 1);
                                535                 :     else
  830 tgl                       536 UBC           0 :         unsetenv("LC_MESSAGES");
 4597 bruce                     537 ECB             : 
 4597 bruce                     538 GBC           4 :     pg_free(lc_collate);
 4597 bruce                     539 CBC           4 :     pg_free(lc_ctype);
 4597 bruce                     540 GBC           4 :     pg_free(lc_monetary);
 4597 bruce                     541 CBC           4 :     pg_free(lc_numeric);
                                542               4 :     pg_free(lc_time);
 4597 bruce                     543 GIC           4 :     pg_free(lang);
 4597 bruce                     544 GBC           4 :     pg_free(language);
 4597 bruce                     545 GIC           4 :     pg_free(lc_all);
 4597 bruce                     546 CBC           4 :     pg_free(lc_messages);
 4555 bruce                     547 ECB             : 
 3939 heikki.linnakangas        548                 :     /*
 2250 rhaas                     549                 :      * Before 9.3, pg_resetwal reported the xlogid and segno of the first log
 3602 bruce                     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.
 3939 heikki.linnakangas        553                 :      */
 3939 heikki.linnakangas        554 CBC           4 :     if (GET_MAJOR_VERSION(cluster->major_version) <= 902)
                                555                 :     {
 2887 bruce                     556 UIC           0 :         if (got_tli && got_log_id && got_log_seg)
                                557                 :         {
 3937 alvherre                  558               0 :             snprintf(cluster->controldata.nextxlogfile, 25, "%08X%08X%08X",
                                559                 :                      tli, logid, segno);
 3939 heikki.linnakangas        560               0 :             got_nextxlogfile = true;
                                561                 :         }
 3939 heikki.linnakangas        562 ECB             :     }
                                563                 : 
 4715 bruce                     564 EUB             :     /* verify that we got all the mandatory pg_control data */
 4715 bruce                     565 GIC           4 :     if (!got_xid || !got_oid ||
  622 bruce                     566 GBC           4 :         !got_multi || !got_oldestxid ||
 3692 alvherre                  567 GIC           4 :         (!got_oldestmulti &&
 3692 alvherre                  568 UBC           0 :          cluster->controldata.cat_ver >= MULTIXACT_FORMATCHANGE_CAT_VER) ||
 2887 bruce                     569 GIC           4 :         !got_mxoff || (!live_check && !got_nextxlogfile) ||
 2735                           570               4 :         !got_float8_pass_by_value || !got_align || !got_blocksz ||
                                571               4 :         !got_largesz || !got_walsz || !got_walseg || !got_ident ||
                                572               4 :         !got_index || !got_toast ||
 3133 bruce                     573 CBC           4 :         (!got_large_object &&
 3133 bruce                     574 LBC           0 :          cluster->controldata.ctrl_ver >= LARGE_OBJECT_SIZE_PG_CONTROL_VER) ||
  833 bruce                     575 CBC           4 :         !got_date_is_int || !got_data_checksum_version)
 4715 bruce                     576 EUB             :     {
 2095 alvherre                  577 LBC           0 :         if (cluster == &old_cluster)
                                578               0 :             pg_log(PG_REPORT,
                                579                 :                    "The source cluster lacks some required control information:");
 2095 alvherre                  580 ECB             :         else
 2095 alvherre                  581 LBC           0 :             pg_log(PG_REPORT,
                                582                 :                    "The target cluster lacks some required control information:");
 4715 bruce                     583 ECB             : 
 4715 bruce                     584 UIC           0 :         if (!got_xid)
  271 tgl                       585 UNC           0 :             pg_log(PG_REPORT, "  checkpoint next XID");
 4715 bruce                     586 EUB             : 
 4715 bruce                     587 UIC           0 :         if (!got_oid)
  271 tgl                       588 UNC           0 :             pg_log(PG_REPORT, "  latest checkpoint next OID");
 4715 bruce                     589 EUB             : 
 3728 alvherre                  590 UIC           0 :         if (!got_multi)
  271 tgl                       591 UNC           0 :             pg_log(PG_REPORT, "  latest checkpoint next MultiXactId");
 3728 alvherre                  592 EUB             : 
 3692 alvherre                  593 UBC           0 :         if (!got_oldestmulti &&
 3692 alvherre                  594 UIC           0 :             cluster->controldata.cat_ver >= MULTIXACT_FORMATCHANGE_CAT_VER)
  271 tgl                       595 UNC           0 :             pg_log(PG_REPORT, "  latest checkpoint oldest MultiXactId");
 3728 alvherre                  596 EUB             : 
  622 bruce                     597 UIC           0 :         if (!got_oldestxid)
  271 tgl                       598 UNC           0 :             pg_log(PG_REPORT, "  latest checkpoint oldestXID");
  622 bruce                     599 EUB             : 
 2887 bruce                     600 UIC           0 :         if (!got_mxoff)
  271 tgl                       601 UNC           0 :             pg_log(PG_REPORT, "  latest checkpoint next MultiXactOffset");
 2887 bruce                     602 EUB             : 
 3939 heikki.linnakangas        603 UBC           0 :         if (!live_check && !got_nextxlogfile)
  271 tgl                       604 UNC           0 :             pg_log(PG_REPORT, "  first WAL segment after reset");
 4715 bruce                     605 EUB             : 
 2735 bruce                     606 UBC           0 :         if (!got_float8_pass_by_value)
  271 tgl                       607 UNC           0 :             pg_log(PG_REPORT, "  float8 argument passing method");
 2735 bruce                     608 EUB             : 
 4715 bruce                     609 UBC           0 :         if (!got_align)
  271 tgl                       610 UNC           0 :             pg_log(PG_REPORT, "  maximum alignment");
 4715 bruce                     611 EUB             : 
 4715 bruce                     612 UBC           0 :         if (!got_blocksz)
  271 tgl                       613 UNC           0 :             pg_log(PG_REPORT, "  block size");
 4715 bruce                     614 EUB             : 
 4715 bruce                     615 UBC           0 :         if (!got_largesz)
  271 tgl                       616 UNC           0 :             pg_log(PG_REPORT, "  large relation segment size");
 4715 bruce                     617 EUB             : 
 4715 bruce                     618 UBC           0 :         if (!got_walsz)
  271 tgl                       619 UNC           0 :             pg_log(PG_REPORT, "  WAL block size");
 4715 bruce                     620 EUB             : 
 4715 bruce                     621 UBC           0 :         if (!got_walseg)
  271 tgl                       622 UNC           0 :             pg_log(PG_REPORT, "  WAL segment size");
 4715 bruce                     623 EUB             : 
 4715 bruce                     624 UBC           0 :         if (!got_ident)
  271 tgl                       625 UNC           0 :             pg_log(PG_REPORT, "  maximum identifier length");
 4715 bruce                     626 EUB             : 
 4715 bruce                     627 UBC           0 :         if (!got_index)
  271 tgl                       628 UNC           0 :             pg_log(PG_REPORT, "  maximum number of indexed columns");
 4715 bruce                     629 EUB             : 
 4715 bruce                     630 UBC           0 :         if (!got_toast)
  271 tgl                       631 UNC           0 :             pg_log(PG_REPORT, "  maximum TOAST chunk size");
 4715 bruce                     632 EUB             : 
 3133 bruce                     633 UBC           0 :         if (!got_large_object &&
 3133 bruce                     634 UIC           0 :             cluster->controldata.ctrl_ver >= LARGE_OBJECT_SIZE_PG_CONTROL_VER)
  271 tgl                       635 UNC           0 :             pg_log(PG_REPORT, "  large-object chunk size");
 3133 bruce                     636 EUB             : 
 4715 bruce                     637 UIC           0 :         if (!got_date_is_int)
  271 tgl                       638 UNC           0 :             pg_log(PG_REPORT, "  dates/times are integers?");
 4715 bruce                     639 EUB             : 
                                640                 :         /* value added in Postgres 9.3 */
 3631 simon                     641 UBC           0 :         if (!got_data_checksum_version)
  271 tgl                       642 UNC           0 :             pg_log(PG_REPORT, "  data checksum version");
 3670 simon                     643 EUB             : 
  271 tgl                       644 UNC           0 :         pg_fatal("Cannot continue without required control information, terminating");
 4715 bruce                     645 EUB             :     }
 4715 bruce                     646 GBC           4 : }
                                647                 : 
                                648                 : 
 4715 bruce                     649 EUB             : /*
                                650                 :  * check_control_data()
                                651                 :  *
                                652                 :  * check to make sure the control data settings are compatible
                                653                 :  */
 4715 bruce                     654 ECB             : void
 4555 bruce                     655 GIC           2 : check_control_data(ControlData *oldctrl,
                                656                 :                    ControlData *newctrl)
                                657                 : {
 4715                           658               2 :     if (oldctrl->align == 0 || oldctrl->align != newctrl->align)
  271 tgl                       659 UNC           0 :         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                 : 
 4715 bruce                     662 GIC           2 :     if (oldctrl->blocksz == 0 || oldctrl->blocksz != newctrl->blocksz)
  271 tgl                       663 UNC           0 :         pg_fatal("old and new pg_controldata block sizes are invalid or do not match");
                                664                 : 
 4715 bruce                     665 GIC           2 :     if (oldctrl->largesz == 0 || oldctrl->largesz != newctrl->largesz)
  271 tgl                       666 UNC           0 :         pg_fatal("old and new pg_controldata maximum relation segment sizes are invalid or do not match");
 4715 bruce                     667 EUB             : 
 4715 bruce                     668 GIC           2 :     if (oldctrl->walsz == 0 || oldctrl->walsz != newctrl->walsz)
  271 tgl                       669 UNC           0 :         pg_fatal("old and new pg_controldata WAL block sizes are invalid or do not match");
 4715 bruce                     670 ECB             : 
 4715 bruce                     671 GBC           2 :     if (oldctrl->walseg == 0 || oldctrl->walseg != newctrl->walseg)
  271 tgl                       672 UNC           0 :         pg_fatal("old and new pg_controldata WAL segment sizes are invalid or do not match");
 4715 bruce                     673 ECB             : 
 4715 bruce                     674 GBC           2 :     if (oldctrl->ident == 0 || oldctrl->ident != newctrl->ident)
  271 tgl                       675 UNC           0 :         pg_fatal("old and new pg_controldata maximum identifier lengths are invalid or do not match");
 4715 bruce                     676 ECB             : 
 4715 bruce                     677 GBC           2 :     if (oldctrl->index == 0 || oldctrl->index != newctrl->index)
  271 tgl                       678 UNC           0 :         pg_fatal("old and new pg_controldata maximum indexed columns are invalid or do not match");
 4715 bruce                     679 ECB             : 
 4715 bruce                     680 GBC           2 :     if (oldctrl->toast == 0 || oldctrl->toast != newctrl->toast)
  271 tgl                       681 UNC           0 :         pg_fatal("old and new pg_controldata maximum TOAST chunk sizes are invalid or do not match");
 4715 bruce                     682 ECB             : 
 3133 bruce                     683 EUB             :     /* large_object added in 9.5, so it might not exist in the old cluster */
 3133 bruce                     684 GIC           2 :     if (oldctrl->large_object != 0 &&
 3133 bruce                     685 CBC           2 :         oldctrl->large_object != newctrl->large_object)
  271 tgl                       686 UNC           0 :         pg_fatal("old and new pg_controldata large-object chunk sizes are invalid or do not match");
                                687                 : 
 4715 bruce                     688 CBC           2 :     if (oldctrl->date_is_int != newctrl->date_is_int)
  271 tgl                       689 UNC           0 :         pg_fatal("old and new pg_controldata date/time storage types do not match");
                                690                 : 
                                691                 :     /*
 2735 bruce                     692 ECB             :      * float8_pass_by_value does not need to match, but is used in
                                693                 :      * check_for_isn_and_int8_passing_mismatch().
 2735 bruce                     694 EUB             :      */
                                695                 : 
 3602 bruce                     696 ECB             :     /*
 3602 bruce                     697 EUB             :      * We might eventually allow upgrades from checksum to no-checksum
                                698                 :      * clusters.
                                699                 :      */
 2979 bruce                     700 GIC           2 :     if (oldctrl->data_checksum_version == 0 &&
                                701               2 :         newctrl->data_checksum_version != 0)
  271 tgl                       702 UNC           0 :         pg_fatal("old cluster does not use data checksums but the new one does");
 2979 bruce                     703 GIC           2 :     else if (oldctrl->data_checksum_version != 0 &&
 2979 bruce                     704 UIC           0 :              newctrl->data_checksum_version == 0)
  271 tgl                       705 UNC           0 :         pg_fatal("old cluster uses data checksums but the new one does not");
 2979 bruce                     706 GIC           2 :     else if (oldctrl->data_checksum_version != newctrl->data_checksum_version)
  271 tgl                       707 UNC           0 :         pg_fatal("old and new cluster pg_controldata checksum versions do not match");
 4715 bruce                     708 CBC           2 : }
 4715 bruce                     709 ECB             : 
 4715 bruce                     710 EUB             : 
 4715 bruce                     711 ECB             : void
 4052 bruce                     712 UBC           0 : disable_old_cluster(void)
 4715 bruce                     713 EUB             : {
 4715 bruce                     714 ECB             :     char        old_path[MAXPGPATH],
 4715 bruce                     715 EUB             :                 new_path[MAXPGPATH];
 4715 bruce                     716 ECB             : 
                                717                 :     /* rename pg_control so old server cannot be accidentally started */
 4555 bruce                     718 UIC           0 :     prep_status("Adding \".old\" suffix to old global/pg_control");
                                719                 : 
 4555 bruce                     720 UBC           0 :     snprintf(old_path, sizeof(old_path), "%s/global/pg_control", old_cluster.pgdata);
 4555 bruce                     721 UIC           0 :     snprintf(new_path, sizeof(new_path), "%s/global/pg_control.old", old_cluster.pgdata);
 4715                           722               0 :     if (pg_mv_file(old_path, new_path) != 0)
  271 tgl                       723 UNC           0 :         pg_fatal("could not rename file \"%s\" to \"%s\": %m",
                                724                 :                  old_path, new_path);
 4555 bruce                     725 UIC           0 :     check_ok();
                                726                 : 
 4052 bruce                     727 UBC           0 :     pg_log(PG_REPORT, "\n"
                                728                 :            "If you want to start the old cluster, you will need to remove\n"
 4052 bruce                     729 EUB             :            "the \".old\" suffix from %s/global/pg_control.old.\n"
 2118 tgl                       730                 :            "Because \"link\" mode was used, the old cluster cannot be safely\n"
                                731                 :            "started once the new cluster has been started.",
                                732                 :            old_cluster.pgdata);
 4715 bruce                     733 UBC           0 : }
        

Generated by: LCOV version v1.16-55-g56c0a2a