2010-05-12 10:19:11 +08:00
|
|
|
/*
|
|
|
|
* controldata.c
|
|
|
|
*
|
|
|
|
* controldata functions
|
2010-07-03 22:23:14 +08:00
|
|
|
*
|
2013-01-02 06:15:01 +08:00
|
|
|
* Copyright (c) 2010-2013, PostgreSQL Global Development Group
|
2010-09-21 04:08:53 +08:00
|
|
|
* contrib/pg_upgrade/controldata.c
|
2010-05-12 10:19:11 +08:00
|
|
|
*/
|
|
|
|
|
2011-08-27 09:16:24 +08:00
|
|
|
#include "postgres.h"
|
|
|
|
|
2010-05-12 10:19:11 +08:00
|
|
|
#include "pg_upgrade.h"
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get_control_data()
|
|
|
|
*
|
|
|
|
* gets pg_control information in "ctrl". Assumes that bindir and
|
|
|
|
* datadir are valid absolute paths to postgresql bin and pgdata
|
|
|
|
* directories respectively *and* pg_resetxlog is version compatible
|
|
|
|
* with datadir. The main purpose of this function is to get pg_control
|
|
|
|
* data in a version independent manner.
|
|
|
|
*
|
|
|
|
* The approach taken here is to invoke pg_resetxlog with -n option
|
|
|
|
* and then pipe its output. With little string parsing we get the
|
|
|
|
* pg_control data. pg_resetxlog cannot be run while the server is running
|
|
|
|
* so we use pg_controldata; pg_controldata doesn't provide all the fields
|
2010-12-15 20:11:31 +08:00
|
|
|
* we need to actually perform the upgrade, but it provides enough for
|
2010-05-12 10:19:11 +08:00
|
|
|
* check mode. We do not implement pg_resetxlog -n because it is hard to
|
|
|
|
* return valid xid data for a running server.
|
|
|
|
*/
|
|
|
|
void
|
2010-10-20 05:38:16 +08:00
|
|
|
get_control_data(ClusterInfo *cluster, bool live_check)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
|
|
|
char cmd[MAXPGPATH];
|
|
|
|
char bufin[MAX_STRING];
|
|
|
|
FILE *output;
|
|
|
|
char *p;
|
|
|
|
bool got_xid = false;
|
|
|
|
bool got_oid = false;
|
2012-06-26 12:35:57 +08:00
|
|
|
bool got_nextxlogfile = false;
|
Improve concurrency of foreign key locking
This patch introduces two additional lock modes for tuples: "SELECT FOR
KEY SHARE" and "SELECT FOR NO KEY UPDATE". These don't block each
other, in contrast with already existing "SELECT FOR SHARE" and "SELECT
FOR UPDATE". UPDATE commands that do not modify the values stored in
the columns that are part of the key of the tuple now grab a SELECT FOR
NO KEY UPDATE lock on the tuple, allowing them to proceed concurrently
with tuple locks of the FOR KEY SHARE variety.
Foreign key triggers now use FOR KEY SHARE instead of FOR SHARE; this
means the concurrency improvement applies to them, which is the whole
point of this patch.
The added tuple lock semantics require some rejiggering of the multixact
module, so that the locking level that each transaction is holding can
be stored alongside its Xid. Also, multixacts now need to persist
across server restarts and crashes, because they can now represent not
only tuple locks, but also tuple updates. This means we need more
careful tracking of lifetime of pg_multixact SLRU files; since they now
persist longer, we require more infrastructure to figure out when they
can be removed. pg_upgrade also needs to be careful to copy
pg_multixact files over from the old server to the new, or at least part
of multixact.c state, depending on the versions of the old and new
servers.
Tuple time qualification rules (HeapTupleSatisfies routines) need to be
careful not to consider tuples with the "is multi" infomask bit set as
being only locked; they might need to look up MultiXact values (i.e.
possibly do pg_multixact I/O) to find out the Xid that updated a tuple,
whereas they previously were assured to only use information readily
available from the tuple header. This is considered acceptable, because
the extra I/O would involve cases that would previously cause some
commands to block waiting for concurrent transactions to finish.
Another important change is the fact that locking tuples that have
previously been updated causes the future versions to be marked as
locked, too; this is essential for correctness of foreign key checks.
This causes additional WAL-logging, also (there was previously a single
WAL record for a locked tuple; now there are as many as updated copies
of the tuple there exist.)
With all this in place, contention related to tuples being checked by
foreign key rules should be much reduced.
As a bonus, the old behavior that a subtransaction grabbing a stronger
tuple lock than the parent (sub)transaction held on a given tuple and
later aborting caused the weaker lock to be lost, has been fixed.
Many new spec files were added for isolation tester framework, to ensure
overall behavior is sane. There's probably room for several more tests.
There were several reviewers of this patch; in particular, Noah Misch
and Andres Freund spent considerable time in it. Original idea for the
patch came from Simon Riggs, after a problem report by Joel Jacobson.
Most code is from me, with contributions from Marti Raudsepp, Alexander
Shulgin, Noah Misch and Andres Freund.
This patch was discussed in several pgsql-hackers threads; the most
important start at the following message-ids:
AANLkTimo9XVcEzfiBR-ut3KVNDkjm2Vxh+t8kAmWjPuv@mail.gmail.com
1290721684-sup-3951@alvh.no-ip.org
1294953201-sup-2099@alvh.no-ip.org
1320343602-sup-2290@alvh.no-ip.org
1339690386-sup-8927@alvh.no-ip.org
4FE5FF020200002500048A3D@gw.wicourts.gov
4FEAB90A0200002500048B7D@gw.wicourts.gov
2013-01-23 23:04:59 +08:00
|
|
|
bool got_multi = false;
|
|
|
|
bool got_mxoff = false;
|
|
|
|
bool got_oldestmulti = false;
|
2010-05-12 10:19:11 +08:00
|
|
|
bool got_log_id = false;
|
|
|
|
bool got_log_seg = false;
|
|
|
|
bool got_tli = false;
|
|
|
|
bool got_align = false;
|
|
|
|
bool got_blocksz = false;
|
|
|
|
bool got_largesz = false;
|
|
|
|
bool got_walsz = false;
|
|
|
|
bool got_walseg = false;
|
|
|
|
bool got_ident = false;
|
|
|
|
bool got_index = false;
|
|
|
|
bool got_toast = false;
|
|
|
|
bool got_date_is_int = false;
|
|
|
|
bool got_float8_pass_by_value = false;
|
2010-09-07 22:10:30 +08:00
|
|
|
char *lc_collate = NULL;
|
|
|
|
char *lc_ctype = NULL;
|
|
|
|
char *lc_monetary = NULL;
|
|
|
|
char *lc_numeric = NULL;
|
|
|
|
char *lc_time = NULL;
|
2010-05-12 10:19:11 +08:00
|
|
|
char *lang = NULL;
|
2010-09-07 22:10:30 +08:00
|
|
|
char *language = NULL;
|
|
|
|
char *lc_all = NULL;
|
|
|
|
char *lc_messages = NULL;
|
2012-06-26 12:35:57 +08:00
|
|
|
uint32 logid = 0;
|
|
|
|
uint32 segno = 0;
|
|
|
|
uint32 tli = 0;
|
|
|
|
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
/*
|
2010-09-07 22:10:30 +08:00
|
|
|
* Because we test the pg_resetxlog output as strings, it has to be in
|
|
|
|
* English. Copied from pg_regress.c.
|
2010-05-12 10:19:11 +08:00
|
|
|
*/
|
2010-09-07 22:10:30 +08:00
|
|
|
if (getenv("LC_COLLATE"))
|
2010-10-20 05:38:16 +08:00
|
|
|
lc_collate = pg_strdup(getenv("LC_COLLATE"));
|
2010-09-07 22:10:30 +08:00
|
|
|
if (getenv("LC_CTYPE"))
|
2010-10-20 05:38:16 +08:00
|
|
|
lc_ctype = pg_strdup(getenv("LC_CTYPE"));
|
2010-09-07 22:10:30 +08:00
|
|
|
if (getenv("LC_MONETARY"))
|
2010-10-20 05:38:16 +08:00
|
|
|
lc_monetary = pg_strdup(getenv("LC_MONETARY"));
|
2010-09-07 22:10:30 +08:00
|
|
|
if (getenv("LC_NUMERIC"))
|
2010-10-20 05:38:16 +08:00
|
|
|
lc_numeric = pg_strdup(getenv("LC_NUMERIC"));
|
2010-09-07 22:10:30 +08:00
|
|
|
if (getenv("LC_TIME"))
|
2010-10-20 05:38:16 +08:00
|
|
|
lc_time = pg_strdup(getenv("LC_TIME"));
|
2010-05-12 10:19:11 +08:00
|
|
|
if (getenv("LANG"))
|
2010-10-20 05:38:16 +08:00
|
|
|
lang = pg_strdup(getenv("LANG"));
|
2010-09-07 22:10:30 +08:00
|
|
|
if (getenv("LANGUAGE"))
|
2010-10-20 05:38:16 +08:00
|
|
|
language = pg_strdup(getenv("LANGUAGE"));
|
2010-09-07 22:10:30 +08:00
|
|
|
if (getenv("LC_ALL"))
|
2010-10-20 05:38:16 +08:00
|
|
|
lc_all = pg_strdup(getenv("LC_ALL"));
|
2010-09-07 22:10:30 +08:00
|
|
|
if (getenv("LC_MESSAGES"))
|
2010-10-20 05:38:16 +08:00
|
|
|
lc_messages = pg_strdup(getenv("LC_MESSAGES"));
|
|
|
|
|
2011-05-16 22:46:52 +08:00
|
|
|
pg_putenv("LC_COLLATE", NULL);
|
|
|
|
pg_putenv("LC_CTYPE", NULL);
|
|
|
|
pg_putenv("LC_MONETARY", NULL);
|
|
|
|
pg_putenv("LC_NUMERIC", NULL);
|
|
|
|
pg_putenv("LC_TIME", NULL);
|
|
|
|
pg_putenv("LANG",
|
2010-05-12 10:19:11 +08:00
|
|
|
#ifndef WIN32
|
2011-06-10 02:32:50 +08:00
|
|
|
NULL);
|
2010-05-12 10:19:11 +08:00
|
|
|
#else
|
2010-10-20 06:37:04 +08:00
|
|
|
/* On Windows the default locale cannot be English, so force it */
|
2011-06-10 02:32:50 +08:00
|
|
|
"en");
|
2010-05-12 10:19:11 +08:00
|
|
|
#endif
|
2011-05-16 22:46:52 +08:00
|
|
|
pg_putenv("LANGUAGE", NULL);
|
|
|
|
pg_putenv("LC_ALL", NULL);
|
|
|
|
pg_putenv("LC_MESSAGES", "C");
|
2010-09-07 22:10:30 +08:00
|
|
|
|
2010-05-14 08:32:21 +08:00
|
|
|
snprintf(cmd, sizeof(cmd), SYSTEMQUOTE "\"%s/%s \"%s\"" SYSTEMQUOTE,
|
|
|
|
cluster->bindir,
|
|
|
|
live_check ? "pg_controldata\"" : "pg_resetxlog\" -n",
|
|
|
|
cluster->pgdata);
|
2010-05-12 10:19:11 +08:00
|
|
|
fflush(stdout);
|
|
|
|
fflush(stderr);
|
|
|
|
|
|
|
|
if ((output = popen(cmd, "r")) == NULL)
|
2011-10-07 07:37:29 +08:00
|
|
|
pg_log(PG_FATAL, "Could not get control data using %s: %s\n",
|
|
|
|
cmd, getErrorText(errno));
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
/* Only pre-8.4 has these so if they are not set below we will check later */
|
|
|
|
cluster->controldata.lc_collate = NULL;
|
|
|
|
cluster->controldata.lc_ctype = NULL;
|
|
|
|
|
|
|
|
/* Only in <= 8.3 */
|
|
|
|
if (GET_MAJOR_VERSION(cluster->major_version) <= 803)
|
|
|
|
{
|
|
|
|
cluster->controldata.float8_pass_by_value = false;
|
|
|
|
got_float8_pass_by_value = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we have the result of cmd in "output". so parse it line by line now */
|
|
|
|
while (fgets(bufin, sizeof(bufin), output))
|
|
|
|
{
|
2012-03-13 07:47:54 +08:00
|
|
|
pg_log(PG_VERBOSE, "%s", bufin);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
#ifdef WIN32
|
2012-06-11 03:20:04 +08:00
|
|
|
|
2010-05-12 10:19:11 +08:00
|
|
|
/*
|
|
|
|
* Due to an installer bug, LANG=C doesn't work for PG 8.3.3, but does
|
|
|
|
* work 8.2.6 and 8.3.7, so check for non-ASCII output and suggest a
|
|
|
|
* minor upgrade.
|
|
|
|
*/
|
|
|
|
if (GET_MAJOR_VERSION(cluster->major_version) <= 803)
|
|
|
|
{
|
|
|
|
for (p = bufin; *p; p++)
|
|
|
|
if (!isascii(*p))
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL,
|
2010-05-12 10:19:11 +08:00
|
|
|
"The 8.3 cluster's pg_controldata is incapable of outputting ASCII, even\n"
|
2011-07-06 03:32:12 +08:00
|
|
|
"with LANG=C. You must upgrade this cluster to a newer version of PostgreSQL\n"
|
|
|
|
"8.3 to fix this bug. PostgreSQL 8.3.7 and later are known to work properly.\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ((p = strstr(bufin, "pg_control version number:")) != NULL)
|
|
|
|
{
|
|
|
|
p = strchr(p, ':');
|
|
|
|
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL, "%d: pg_resetxlog problem\n", __LINE__);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
p++; /* removing ':' char */
|
2010-09-29 05:41:03 +08:00
|
|
|
cluster->controldata.ctrl_ver = str2uint(p);
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
else if ((p = strstr(bufin, "Catalog version number:")) != NULL)
|
|
|
|
{
|
|
|
|
p = strchr(p, ':');
|
|
|
|
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
p++; /* removing ':' char */
|
2010-09-29 05:41:03 +08:00
|
|
|
cluster->controldata.cat_ver = str2uint(p);
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
2012-06-26 12:35:57 +08:00
|
|
|
else if ((p = strstr(bufin, "First log segment after reset:")) != NULL)
|
|
|
|
{
|
|
|
|
/* Skip the colon and any whitespace after it */
|
|
|
|
p = strchr(p, ':');
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
|
|
|
p = strpbrk(p, "01234567890ABCDEF");
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
|
|
|
|
|
|
|
/* Make sure it looks like a valid WAL file name */
|
|
|
|
if (strspn(p, "0123456789ABCDEF") != 24)
|
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
|
|
|
|
|
|
|
strlcpy(cluster->controldata.nextxlogfile, p, 25);
|
|
|
|
got_nextxlogfile = true;
|
|
|
|
}
|
2010-05-14 06:51:00 +08:00
|
|
|
else if ((p = strstr(bufin, "First log file ID after reset:")) != NULL)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
|
|
|
p = strchr(p, ':');
|
|
|
|
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
p++; /* removing ':' char */
|
2012-06-26 12:35:57 +08:00
|
|
|
logid = str2uint(p);
|
2010-05-12 10:19:11 +08:00
|
|
|
got_log_id = true;
|
|
|
|
}
|
2010-05-14 06:51:00 +08:00
|
|
|
else if ((p = strstr(bufin, "First log file segment after reset:")) != NULL)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
|
|
|
p = strchr(p, ':');
|
|
|
|
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
p++; /* removing ':' char */
|
2012-06-26 12:35:57 +08:00
|
|
|
segno = str2uint(p);
|
2010-05-12 10:19:11 +08:00
|
|
|
got_log_seg = true;
|
|
|
|
}
|
|
|
|
else if ((p = strstr(bufin, "Latest checkpoint's TimeLineID:")) != NULL)
|
|
|
|
{
|
|
|
|
p = strchr(p, ':');
|
|
|
|
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
p++; /* removing ':' char */
|
2010-09-29 05:41:03 +08:00
|
|
|
cluster->controldata.chkpnt_tli = str2uint(p);
|
2010-05-12 10:19:11 +08:00
|
|
|
got_tli = true;
|
|
|
|
}
|
|
|
|
else if ((p = strstr(bufin, "Latest checkpoint's NextXID:")) != NULL)
|
|
|
|
{
|
|
|
|
char *op = strchr(p, '/');
|
|
|
|
|
|
|
|
if (op == NULL)
|
|
|
|
op = strchr(p, ':');
|
|
|
|
|
|
|
|
if (op == NULL || strlen(op) <= 1)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
op++; /* removing ':' char */
|
2010-09-29 05:41:03 +08:00
|
|
|
cluster->controldata.chkpnt_nxtxid = str2uint(op);
|
2010-05-12 10:19:11 +08:00
|
|
|
got_xid = true;
|
|
|
|
}
|
|
|
|
else if ((p = strstr(bufin, "Latest checkpoint's NextOID:")) != NULL)
|
|
|
|
{
|
|
|
|
p = strchr(p, ':');
|
|
|
|
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
p++; /* removing ':' char */
|
2010-09-29 05:41:03 +08:00
|
|
|
cluster->controldata.chkpnt_nxtoid = str2uint(p);
|
2010-05-12 10:19:11 +08:00
|
|
|
got_oid = true;
|
|
|
|
}
|
Improve concurrency of foreign key locking
This patch introduces two additional lock modes for tuples: "SELECT FOR
KEY SHARE" and "SELECT FOR NO KEY UPDATE". These don't block each
other, in contrast with already existing "SELECT FOR SHARE" and "SELECT
FOR UPDATE". UPDATE commands that do not modify the values stored in
the columns that are part of the key of the tuple now grab a SELECT FOR
NO KEY UPDATE lock on the tuple, allowing them to proceed concurrently
with tuple locks of the FOR KEY SHARE variety.
Foreign key triggers now use FOR KEY SHARE instead of FOR SHARE; this
means the concurrency improvement applies to them, which is the whole
point of this patch.
The added tuple lock semantics require some rejiggering of the multixact
module, so that the locking level that each transaction is holding can
be stored alongside its Xid. Also, multixacts now need to persist
across server restarts and crashes, because they can now represent not
only tuple locks, but also tuple updates. This means we need more
careful tracking of lifetime of pg_multixact SLRU files; since they now
persist longer, we require more infrastructure to figure out when they
can be removed. pg_upgrade also needs to be careful to copy
pg_multixact files over from the old server to the new, or at least part
of multixact.c state, depending on the versions of the old and new
servers.
Tuple time qualification rules (HeapTupleSatisfies routines) need to be
careful not to consider tuples with the "is multi" infomask bit set as
being only locked; they might need to look up MultiXact values (i.e.
possibly do pg_multixact I/O) to find out the Xid that updated a tuple,
whereas they previously were assured to only use information readily
available from the tuple header. This is considered acceptable, because
the extra I/O would involve cases that would previously cause some
commands to block waiting for concurrent transactions to finish.
Another important change is the fact that locking tuples that have
previously been updated causes the future versions to be marked as
locked, too; this is essential for correctness of foreign key checks.
This causes additional WAL-logging, also (there was previously a single
WAL record for a locked tuple; now there are as many as updated copies
of the tuple there exist.)
With all this in place, contention related to tuples being checked by
foreign key rules should be much reduced.
As a bonus, the old behavior that a subtransaction grabbing a stronger
tuple lock than the parent (sub)transaction held on a given tuple and
later aborting caused the weaker lock to be lost, has been fixed.
Many new spec files were added for isolation tester framework, to ensure
overall behavior is sane. There's probably room for several more tests.
There were several reviewers of this patch; in particular, Noah Misch
and Andres Freund spent considerable time in it. Original idea for the
patch came from Simon Riggs, after a problem report by Joel Jacobson.
Most code is from me, with contributions from Marti Raudsepp, Alexander
Shulgin, Noah Misch and Andres Freund.
This patch was discussed in several pgsql-hackers threads; the most
important start at the following message-ids:
AANLkTimo9XVcEzfiBR-ut3KVNDkjm2Vxh+t8kAmWjPuv@mail.gmail.com
1290721684-sup-3951@alvh.no-ip.org
1294953201-sup-2099@alvh.no-ip.org
1320343602-sup-2290@alvh.no-ip.org
1339690386-sup-8927@alvh.no-ip.org
4FE5FF020200002500048A3D@gw.wicourts.gov
4FEAB90A0200002500048B7D@gw.wicourts.gov
2013-01-23 23:04:59 +08:00
|
|
|
else if ((p = strstr(bufin, "Latest checkpoint's NextMultiXactId:")) != NULL)
|
|
|
|
{
|
|
|
|
p = strchr(p, ':');
|
|
|
|
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
|
|
|
|
|
|
|
p++; /* removing ':' char */
|
|
|
|
cluster->controldata.chkpnt_nxtmulti = str2uint(p);
|
|
|
|
got_multi = true;
|
|
|
|
}
|
|
|
|
else if ((p = strstr(bufin, "Latest checkpoint's oldestMultiXid:")) != NULL)
|
|
|
|
{
|
|
|
|
p = strchr(p, ':');
|
|
|
|
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
|
|
|
|
|
|
|
p++; /* removing ':' char */
|
|
|
|
cluster->controldata.chkpnt_oldstMulti = str2uint(p);
|
|
|
|
got_oldestmulti = true;
|
|
|
|
}
|
|
|
|
else if ((p = strstr(bufin, "Latest checkpoint's NextMultiOffset:")) != NULL)
|
|
|
|
{
|
|
|
|
p = strchr(p, ':');
|
|
|
|
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
|
|
|
|
|
|
|
p++; /* removing ':' char */
|
|
|
|
cluster->controldata.chkpnt_nxtmxoff = str2uint(p);
|
|
|
|
got_mxoff = true;
|
|
|
|
}
|
2010-05-12 10:19:11 +08:00
|
|
|
else if ((p = strstr(bufin, "Maximum data alignment:")) != NULL)
|
|
|
|
{
|
|
|
|
p = strchr(p, ':');
|
|
|
|
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
p++; /* removing ':' char */
|
2010-09-29 05:41:03 +08:00
|
|
|
cluster->controldata.align = str2uint(p);
|
2010-05-12 10:19:11 +08:00
|
|
|
got_align = true;
|
|
|
|
}
|
|
|
|
else if ((p = strstr(bufin, "Database block size:")) != NULL)
|
|
|
|
{
|
|
|
|
p = strchr(p, ':');
|
|
|
|
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
p++; /* removing ':' char */
|
2010-09-29 05:41:03 +08:00
|
|
|
cluster->controldata.blocksz = str2uint(p);
|
2010-05-12 10:19:11 +08:00
|
|
|
got_blocksz = true;
|
|
|
|
}
|
|
|
|
else if ((p = strstr(bufin, "Blocks per segment of large relation:")) != NULL)
|
|
|
|
{
|
|
|
|
p = strchr(p, ':');
|
|
|
|
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
p++; /* removing ':' char */
|
2010-09-29 05:41:03 +08:00
|
|
|
cluster->controldata.largesz = str2uint(p);
|
2010-05-12 10:19:11 +08:00
|
|
|
got_largesz = true;
|
|
|
|
}
|
|
|
|
else if ((p = strstr(bufin, "WAL block size:")) != NULL)
|
|
|
|
{
|
|
|
|
p = strchr(p, ':');
|
|
|
|
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
p++; /* removing ':' char */
|
2010-09-29 05:41:03 +08:00
|
|
|
cluster->controldata.walsz = str2uint(p);
|
2010-05-12 10:19:11 +08:00
|
|
|
got_walsz = true;
|
|
|
|
}
|
|
|
|
else if ((p = strstr(bufin, "Bytes per WAL segment:")) != NULL)
|
|
|
|
{
|
|
|
|
p = strchr(p, ':');
|
|
|
|
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
p++; /* removing ':' char */
|
2010-09-29 05:41:03 +08:00
|
|
|
cluster->controldata.walseg = str2uint(p);
|
2010-05-12 10:19:11 +08:00
|
|
|
got_walseg = true;
|
|
|
|
}
|
|
|
|
else if ((p = strstr(bufin, "Maximum length of identifiers:")) != NULL)
|
|
|
|
{
|
|
|
|
p = strchr(p, ':');
|
|
|
|
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
p++; /* removing ':' char */
|
2010-09-29 05:41:03 +08:00
|
|
|
cluster->controldata.ident = str2uint(p);
|
2010-05-12 10:19:11 +08:00
|
|
|
got_ident = true;
|
|
|
|
}
|
|
|
|
else if ((p = strstr(bufin, "Maximum columns in an index:")) != NULL)
|
|
|
|
{
|
|
|
|
p = strchr(p, ':');
|
|
|
|
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
p++; /* removing ':' char */
|
2010-09-29 05:41:03 +08:00
|
|
|
cluster->controldata.index = str2uint(p);
|
2010-05-12 10:19:11 +08:00
|
|
|
got_index = true;
|
|
|
|
}
|
|
|
|
else if ((p = strstr(bufin, "Maximum size of a TOAST chunk:")) != NULL)
|
|
|
|
{
|
|
|
|
p = strchr(p, ':');
|
|
|
|
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
p++; /* removing ':' char */
|
2010-09-29 05:41:03 +08:00
|
|
|
cluster->controldata.toast = str2uint(p);
|
2010-05-12 10:19:11 +08:00
|
|
|
got_toast = true;
|
|
|
|
}
|
|
|
|
else if ((p = strstr(bufin, "Date/time type storage:")) != NULL)
|
|
|
|
{
|
|
|
|
p = strchr(p, ':');
|
|
|
|
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
p++; /* removing ':' char */
|
|
|
|
cluster->controldata.date_is_int = strstr(p, "64-bit integers") != NULL;
|
|
|
|
got_date_is_int = true;
|
|
|
|
}
|
|
|
|
else if ((p = strstr(bufin, "Float8 argument passing:")) != NULL)
|
|
|
|
{
|
|
|
|
p = strchr(p, ':');
|
|
|
|
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
p++; /* removing ':' char */
|
2011-05-19 05:30:31 +08:00
|
|
|
/* used later for contrib check */
|
2010-05-12 10:19:11 +08:00
|
|
|
cluster->controldata.float8_pass_by_value = strstr(p, "by value") != NULL;
|
|
|
|
got_float8_pass_by_value = true;
|
|
|
|
}
|
|
|
|
/* In pre-8.4 only */
|
|
|
|
else if ((p = strstr(bufin, "LC_COLLATE:")) != NULL)
|
|
|
|
{
|
|
|
|
p = strchr(p, ':');
|
|
|
|
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
p++; /* removing ':' char */
|
|
|
|
/* skip leading spaces and remove trailing newline */
|
|
|
|
p += strspn(p, " ");
|
|
|
|
if (strlen(p) > 0 && *(p + strlen(p) - 1) == '\n')
|
|
|
|
*(p + strlen(p) - 1) = '\0';
|
2010-10-20 05:38:16 +08:00
|
|
|
cluster->controldata.lc_collate = pg_strdup(p);
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
/* In pre-8.4 only */
|
|
|
|
else if ((p = strstr(bufin, "LC_CTYPE:")) != NULL)
|
|
|
|
{
|
|
|
|
p = strchr(p, ':');
|
|
|
|
|
|
|
|
if (p == NULL || strlen(p) <= 1)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL, "%d: controldata retrieval problem\n", __LINE__);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
p++; /* removing ':' char */
|
|
|
|
/* skip leading spaces and remove trailing newline */
|
|
|
|
p += strspn(p, " ");
|
|
|
|
if (strlen(p) > 0 && *(p + strlen(p) - 1) == '\n')
|
|
|
|
*(p + strlen(p) - 1) = '\0';
|
2010-10-20 05:38:16 +08:00
|
|
|
cluster->controldata.lc_ctype = pg_strdup(p);
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (output)
|
|
|
|
pclose(output);
|
|
|
|
|
2010-09-07 22:10:30 +08:00
|
|
|
/*
|
2010-10-20 06:37:04 +08:00
|
|
|
* Restore environment variables
|
2010-09-07 22:10:30 +08:00
|
|
|
*/
|
2011-05-16 22:46:52 +08:00
|
|
|
pg_putenv("LC_COLLATE", lc_collate);
|
|
|
|
pg_putenv("LC_CTYPE", lc_ctype);
|
|
|
|
pg_putenv("LC_MONETARY", lc_monetary);
|
|
|
|
pg_putenv("LC_NUMERIC", lc_numeric);
|
|
|
|
pg_putenv("LC_TIME", lc_time);
|
|
|
|
pg_putenv("LANG", lang);
|
|
|
|
pg_putenv("LANGUAGE", language);
|
|
|
|
pg_putenv("LC_ALL", lc_all);
|
|
|
|
pg_putenv("LC_MESSAGES", lc_messages);
|
2010-09-07 22:10:30 +08:00
|
|
|
|
|
|
|
pg_free(lc_collate);
|
|
|
|
pg_free(lc_ctype);
|
|
|
|
pg_free(lc_monetary);
|
|
|
|
pg_free(lc_numeric);
|
|
|
|
pg_free(lc_time);
|
|
|
|
pg_free(lang);
|
|
|
|
pg_free(language);
|
|
|
|
pg_free(lc_all);
|
|
|
|
pg_free(lc_messages);
|
2010-10-20 06:37:04 +08:00
|
|
|
|
2012-06-26 12:35:57 +08:00
|
|
|
/*
|
|
|
|
* Before 9.3, pg_resetxlog reported the xlogid and segno of the first
|
|
|
|
* log file after reset as separate lines. Starting with 9.3, it reports
|
|
|
|
* the WAL file name. If the old cluster is older than 9.3, we construct
|
|
|
|
* the WAL file name from the xlogid and segno.
|
|
|
|
*/
|
|
|
|
if (GET_MAJOR_VERSION(cluster->major_version) <= 902)
|
|
|
|
{
|
|
|
|
if (got_log_id && got_log_seg)
|
|
|
|
{
|
2012-06-29 11:37:27 +08:00
|
|
|
snprintf(cluster->controldata.nextxlogfile, 25, "%08X%08X%08X",
|
2012-06-26 12:35:57 +08:00
|
|
|
tli, logid, segno);
|
|
|
|
got_nextxlogfile = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-12 10:19:11 +08:00
|
|
|
/* verify that we got all the mandatory pg_control data */
|
|
|
|
if (!got_xid || !got_oid ||
|
2013-01-24 22:53:15 +08:00
|
|
|
!got_multi || !got_mxoff ||
|
2013-01-24 23:25:48 +08:00
|
|
|
(!got_oldestmulti && cluster->controldata.cat_ver >= MULTIXACT_FORMATCHANGE_CAT_VER) ||
|
2012-06-26 12:35:57 +08:00
|
|
|
(!live_check && !got_nextxlogfile) ||
|
2010-05-12 10:19:11 +08:00
|
|
|
!got_tli ||
|
|
|
|
!got_align || !got_blocksz || !got_largesz || !got_walsz ||
|
|
|
|
!got_walseg || !got_ident || !got_index || !got_toast ||
|
|
|
|
!got_date_is_int || !got_float8_pass_by_value)
|
|
|
|
{
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_REPORT,
|
2013-01-24 21:35:57 +08:00
|
|
|
"The %s cluster lacks some required control information:\n",
|
|
|
|
CLUSTER_NAME(cluster));
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
if (!got_xid)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_REPORT, " checkpoint next XID\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
if (!got_oid)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_REPORT, " latest checkpoint next OID\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
|
Improve concurrency of foreign key locking
This patch introduces two additional lock modes for tuples: "SELECT FOR
KEY SHARE" and "SELECT FOR NO KEY UPDATE". These don't block each
other, in contrast with already existing "SELECT FOR SHARE" and "SELECT
FOR UPDATE". UPDATE commands that do not modify the values stored in
the columns that are part of the key of the tuple now grab a SELECT FOR
NO KEY UPDATE lock on the tuple, allowing them to proceed concurrently
with tuple locks of the FOR KEY SHARE variety.
Foreign key triggers now use FOR KEY SHARE instead of FOR SHARE; this
means the concurrency improvement applies to them, which is the whole
point of this patch.
The added tuple lock semantics require some rejiggering of the multixact
module, so that the locking level that each transaction is holding can
be stored alongside its Xid. Also, multixacts now need to persist
across server restarts and crashes, because they can now represent not
only tuple locks, but also tuple updates. This means we need more
careful tracking of lifetime of pg_multixact SLRU files; since they now
persist longer, we require more infrastructure to figure out when they
can be removed. pg_upgrade also needs to be careful to copy
pg_multixact files over from the old server to the new, or at least part
of multixact.c state, depending on the versions of the old and new
servers.
Tuple time qualification rules (HeapTupleSatisfies routines) need to be
careful not to consider tuples with the "is multi" infomask bit set as
being only locked; they might need to look up MultiXact values (i.e.
possibly do pg_multixact I/O) to find out the Xid that updated a tuple,
whereas they previously were assured to only use information readily
available from the tuple header. This is considered acceptable, because
the extra I/O would involve cases that would previously cause some
commands to block waiting for concurrent transactions to finish.
Another important change is the fact that locking tuples that have
previously been updated causes the future versions to be marked as
locked, too; this is essential for correctness of foreign key checks.
This causes additional WAL-logging, also (there was previously a single
WAL record for a locked tuple; now there are as many as updated copies
of the tuple there exist.)
With all this in place, contention related to tuples being checked by
foreign key rules should be much reduced.
As a bonus, the old behavior that a subtransaction grabbing a stronger
tuple lock than the parent (sub)transaction held on a given tuple and
later aborting caused the weaker lock to be lost, has been fixed.
Many new spec files were added for isolation tester framework, to ensure
overall behavior is sane. There's probably room for several more tests.
There were several reviewers of this patch; in particular, Noah Misch
and Andres Freund spent considerable time in it. Original idea for the
patch came from Simon Riggs, after a problem report by Joel Jacobson.
Most code is from me, with contributions from Marti Raudsepp, Alexander
Shulgin, Noah Misch and Andres Freund.
This patch was discussed in several pgsql-hackers threads; the most
important start at the following message-ids:
AANLkTimo9XVcEzfiBR-ut3KVNDkjm2Vxh+t8kAmWjPuv@mail.gmail.com
1290721684-sup-3951@alvh.no-ip.org
1294953201-sup-2099@alvh.no-ip.org
1320343602-sup-2290@alvh.no-ip.org
1339690386-sup-8927@alvh.no-ip.org
4FE5FF020200002500048A3D@gw.wicourts.gov
4FEAB90A0200002500048B7D@gw.wicourts.gov
2013-01-23 23:04:59 +08:00
|
|
|
if (!got_multi)
|
|
|
|
pg_log(PG_REPORT, " latest checkpoint next MultiXactId\n");
|
|
|
|
|
|
|
|
if (!got_mxoff)
|
|
|
|
pg_log(PG_REPORT, " latest checkpoint next MultiXactOffset\n");
|
|
|
|
|
2013-01-24 23:25:48 +08:00
|
|
|
if (!got_oldestmulti && cluster->controldata.cat_ver >= MULTIXACT_FORMATCHANGE_CAT_VER)
|
Improve concurrency of foreign key locking
This patch introduces two additional lock modes for tuples: "SELECT FOR
KEY SHARE" and "SELECT FOR NO KEY UPDATE". These don't block each
other, in contrast with already existing "SELECT FOR SHARE" and "SELECT
FOR UPDATE". UPDATE commands that do not modify the values stored in
the columns that are part of the key of the tuple now grab a SELECT FOR
NO KEY UPDATE lock on the tuple, allowing them to proceed concurrently
with tuple locks of the FOR KEY SHARE variety.
Foreign key triggers now use FOR KEY SHARE instead of FOR SHARE; this
means the concurrency improvement applies to them, which is the whole
point of this patch.
The added tuple lock semantics require some rejiggering of the multixact
module, so that the locking level that each transaction is holding can
be stored alongside its Xid. Also, multixacts now need to persist
across server restarts and crashes, because they can now represent not
only tuple locks, but also tuple updates. This means we need more
careful tracking of lifetime of pg_multixact SLRU files; since they now
persist longer, we require more infrastructure to figure out when they
can be removed. pg_upgrade also needs to be careful to copy
pg_multixact files over from the old server to the new, or at least part
of multixact.c state, depending on the versions of the old and new
servers.
Tuple time qualification rules (HeapTupleSatisfies routines) need to be
careful not to consider tuples with the "is multi" infomask bit set as
being only locked; they might need to look up MultiXact values (i.e.
possibly do pg_multixact I/O) to find out the Xid that updated a tuple,
whereas they previously were assured to only use information readily
available from the tuple header. This is considered acceptable, because
the extra I/O would involve cases that would previously cause some
commands to block waiting for concurrent transactions to finish.
Another important change is the fact that locking tuples that have
previously been updated causes the future versions to be marked as
locked, too; this is essential for correctness of foreign key checks.
This causes additional WAL-logging, also (there was previously a single
WAL record for a locked tuple; now there are as many as updated copies
of the tuple there exist.)
With all this in place, contention related to tuples being checked by
foreign key rules should be much reduced.
As a bonus, the old behavior that a subtransaction grabbing a stronger
tuple lock than the parent (sub)transaction held on a given tuple and
later aborting caused the weaker lock to be lost, has been fixed.
Many new spec files were added for isolation tester framework, to ensure
overall behavior is sane. There's probably room for several more tests.
There were several reviewers of this patch; in particular, Noah Misch
and Andres Freund spent considerable time in it. Original idea for the
patch came from Simon Riggs, after a problem report by Joel Jacobson.
Most code is from me, with contributions from Marti Raudsepp, Alexander
Shulgin, Noah Misch and Andres Freund.
This patch was discussed in several pgsql-hackers threads; the most
important start at the following message-ids:
AANLkTimo9XVcEzfiBR-ut3KVNDkjm2Vxh+t8kAmWjPuv@mail.gmail.com
1290721684-sup-3951@alvh.no-ip.org
1294953201-sup-2099@alvh.no-ip.org
1320343602-sup-2290@alvh.no-ip.org
1339690386-sup-8927@alvh.no-ip.org
4FE5FF020200002500048A3D@gw.wicourts.gov
4FEAB90A0200002500048B7D@gw.wicourts.gov
2013-01-23 23:04:59 +08:00
|
|
|
pg_log(PG_REPORT, " latest checkpoint oldest MultiXactId\n");
|
|
|
|
|
2012-06-26 12:35:57 +08:00
|
|
|
if (!live_check && !got_nextxlogfile)
|
|
|
|
pg_log(PG_REPORT, " first WAL segment after reset\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
if (!got_tli)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_REPORT, " latest checkpoint timeline ID\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
if (!got_align)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_REPORT, " maximum alignment\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
if (!got_blocksz)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_REPORT, " block size\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
if (!got_largesz)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_REPORT, " large relation segment size\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
if (!got_walsz)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_REPORT, " WAL block size\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
if (!got_walseg)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_REPORT, " WAL segment size\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
if (!got_ident)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_REPORT, " maximum identifier length\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
if (!got_index)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_REPORT, " maximum number of indexed columns\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
if (!got_toast)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_REPORT, " maximum TOAST chunk size\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
if (!got_date_is_int)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_REPORT, " dates/times are integers?\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
/* value added in Postgres 8.4 */
|
|
|
|
if (!got_float8_pass_by_value)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_REPORT, " float8 argument passing method\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL,
|
2011-07-12 12:13:51 +08:00
|
|
|
"Cannot continue without required control information, terminating\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check_control_data()
|
|
|
|
*
|
|
|
|
* check to make sure the control data settings are compatible
|
|
|
|
*/
|
|
|
|
void
|
2010-10-20 05:38:16 +08:00
|
|
|
check_control_data(ControlData *oldctrl,
|
2010-05-12 10:19:11 +08:00
|
|
|
ControlData *newctrl)
|
|
|
|
{
|
|
|
|
if (oldctrl->align == 0 || oldctrl->align != newctrl->align)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL,
|
2013-01-18 22:26:18 +08:00
|
|
|
"old and new pg_controldata alignments are invalid or do not match\n"
|
|
|
|
"Likely one cluster is a 32-bit install, the other 64-bit\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
if (oldctrl->blocksz == 0 || oldctrl->blocksz != newctrl->blocksz)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL,
|
2010-05-12 10:19:11 +08:00
|
|
|
"old and new pg_controldata block sizes are invalid or do not match\n");
|
|
|
|
|
|
|
|
if (oldctrl->largesz == 0 || oldctrl->largesz != newctrl->largesz)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL,
|
2010-05-12 10:19:11 +08:00
|
|
|
"old and new pg_controldata maximum relation segement sizes are invalid or do not match\n");
|
|
|
|
|
|
|
|
if (oldctrl->walsz == 0 || oldctrl->walsz != newctrl->walsz)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL,
|
2010-05-12 10:19:11 +08:00
|
|
|
"old and new pg_controldata WAL block sizes are invalid or do not match\n");
|
|
|
|
|
|
|
|
if (oldctrl->walseg == 0 || oldctrl->walseg != newctrl->walseg)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL,
|
2010-05-12 10:19:11 +08:00
|
|
|
"old and new pg_controldata WAL segment sizes are invalid or do not match\n");
|
|
|
|
|
|
|
|
if (oldctrl->ident == 0 || oldctrl->ident != newctrl->ident)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL,
|
2010-05-12 10:19:11 +08:00
|
|
|
"old and new pg_controldata maximum identifier lengths are invalid or do not match\n");
|
|
|
|
|
|
|
|
if (oldctrl->index == 0 || oldctrl->index != newctrl->index)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL,
|
2010-05-12 10:19:11 +08:00
|
|
|
"old and new pg_controldata maximum indexed columns are invalid or do not match\n");
|
|
|
|
|
|
|
|
if (oldctrl->toast == 0 || oldctrl->toast != newctrl->toast)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL,
|
2010-05-12 10:19:11 +08:00
|
|
|
"old and new pg_controldata maximum TOAST chunk sizes are invalid or do not match\n");
|
|
|
|
|
|
|
|
if (oldctrl->date_is_int != newctrl->date_is_int)
|
|
|
|
{
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_WARNING,
|
2010-05-12 10:19:11 +08:00
|
|
|
"\nOld and new pg_controldata date/time storage types do not match.\n");
|
|
|
|
|
|
|
|
/*
|
2011-04-10 23:42:00 +08:00
|
|
|
* This is a common 8.3 -> 8.4 upgrade problem, so we are more verbose
|
2010-05-12 10:19:11 +08:00
|
|
|
*/
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL,
|
2012-06-11 03:20:04 +08:00
|
|
|
"You will need to rebuild the new server with configure option\n"
|
2011-07-12 12:13:51 +08:00
|
|
|
"--disable-integer-datetimes or get server binaries built with those\n"
|
|
|
|
"options.\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2012-03-06 10:19:54 +08:00
|
|
|
disable_old_cluster(void)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
|
|
|
char old_path[MAXPGPATH],
|
|
|
|
new_path[MAXPGPATH];
|
|
|
|
|
2012-03-06 10:19:54 +08:00
|
|
|
/* rename pg_control so old server cannot be accidentally started */
|
2010-10-20 05:38:16 +08:00
|
|
|
prep_status("Adding \".old\" suffix to old global/pg_control");
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
snprintf(old_path, sizeof(old_path), "%s/global/pg_control", old_cluster.pgdata);
|
|
|
|
snprintf(new_path, sizeof(new_path), "%s/global/pg_control.old", old_cluster.pgdata);
|
2010-05-12 10:19:11 +08:00
|
|
|
if (pg_mv_file(old_path, new_path) != 0)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_FATAL, "Unable to rename %s to %s.\n", old_path, new_path);
|
|
|
|
check_ok();
|
2012-03-06 10:19:54 +08:00
|
|
|
|
|
|
|
pg_log(PG_REPORT, "\n"
|
|
|
|
"If you want to start the old cluster, you will need to remove\n"
|
|
|
|
"the \".old\" suffix from %s/global/pg_control.old.\n"
|
2012-06-11 03:20:04 +08:00
|
|
|
"Because \"link\" mode was used, the old cluster cannot be safely\n"
|
|
|
|
"started once the new cluster has been started.\n\n", old_cluster.pgdata);
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|