LCOV - code coverage report
Current view: top level - src/bin/pg_upgrade - controldata.c (source / functions) Hit Total Coverage
Test: PostgreSQL 13devel Lines: 263 394 66.8 %
Date: 2019-11-21 15:06:52 Functions: 2 3 66.7 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13