mirror of
https://github.com/postgres/postgres.git
synced 2025-06-08 22:02:03 +03:00
pg_upgrade: fix --check for live source server checks
Fix for commit 244142d32afd02e7408a2ef1f249b00393983822. Backpatch-through: 9.3
This commit is contained in:
parent
88adf1add2
commit
12dd070081
@ -111,6 +111,65 @@ get_control_data(ClusterInfo *cluster, bool live_check)
|
||||
pg_putenv("LC_ALL", NULL);
|
||||
pg_putenv("LC_MESSAGES", "C");
|
||||
|
||||
/*
|
||||
* Check for clean shutdown
|
||||
*/
|
||||
if (!live_check || cluster == &new_cluster)
|
||||
{
|
||||
/* only pg_controldata outputs the cluster state */
|
||||
snprintf(cmd, sizeof(cmd), "\"%s/pg_controldata\" \"%s\"",
|
||||
cluster->bindir, cluster->pgdata);
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
|
||||
if ((output = popen(cmd, "r")) == NULL)
|
||||
pg_fatal("could not get control data using %s: %s\n",
|
||||
cmd, strerror(errno));
|
||||
|
||||
/* we have the result of cmd in "output". so parse it line by line now */
|
||||
while (fgets(bufin, sizeof(bufin), output))
|
||||
{
|
||||
if ((p = strstr(bufin, "Database cluster state:")) != NULL)
|
||||
{
|
||||
p = strchr(p, ':');
|
||||
|
||||
if (p == NULL || strlen(p) <= 1)
|
||||
pg_fatal("%d: database cluster state problem\n", __LINE__);
|
||||
|
||||
p++; /* remove ':' char */
|
||||
|
||||
/*
|
||||
* We checked earlier for a postmaster lock file, and if we found
|
||||
* one, we tried to start/stop the server to replay the WAL. However,
|
||||
* pg_ctl -m immediate doesn't leave a lock file, but does require
|
||||
* WAL replay, so we check here that the server was shut down cleanly,
|
||||
* from the controldata perspective.
|
||||
*/
|
||||
/* remove leading spaces */
|
||||
while (*p == ' ')
|
||||
p++;
|
||||
if (strcmp(p, "shut down\n") != 0)
|
||||
{
|
||||
if (cluster == &old_cluster)
|
||||
pg_fatal("The source cluster was not shut down cleanly.\n");
|
||||
else
|
||||
pg_fatal("The target cluster was not shut down cleanly.\n");
|
||||
}
|
||||
got_cluster_state = true;
|
||||
}
|
||||
}
|
||||
|
||||
pclose(output);
|
||||
|
||||
if (!got_cluster_state)
|
||||
{
|
||||
if (cluster == &old_cluster)
|
||||
pg_fatal("The source cluster lacks cluster state information:\n");
|
||||
else
|
||||
pg_fatal("The target cluster lacks cluster state information:\n");
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(cmd, sizeof(cmd), "\"%s/%s \"%s\"",
|
||||
cluster->bindir,
|
||||
live_check ? "pg_controldata\"" : "pg_resetxlog\" -n",
|
||||
@ -452,64 +511,6 @@ get_control_data(ClusterInfo *cluster, bool live_check)
|
||||
if (output)
|
||||
pclose(output);
|
||||
|
||||
/*
|
||||
* Check for clean shutdown
|
||||
*/
|
||||
|
||||
/* only pg_controldata outputs the cluster state */
|
||||
snprintf(cmd, sizeof(cmd), "\"%s/pg_controldata\" \"%s\"",
|
||||
cluster->bindir, cluster->pgdata);
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
|
||||
if ((output = popen(cmd, "r")) == NULL)
|
||||
pg_fatal("could not get control data using %s: %s\n",
|
||||
cmd, strerror(errno));
|
||||
|
||||
/* we have the result of cmd in "output". so parse it line by line now */
|
||||
while (fgets(bufin, sizeof(bufin), output))
|
||||
{
|
||||
if ((!live_check || cluster == &new_cluster) &&
|
||||
(p = strstr(bufin, "Database cluster state:")) != NULL)
|
||||
{
|
||||
p = strchr(p, ':');
|
||||
|
||||
if (p == NULL || strlen(p) <= 1)
|
||||
pg_fatal("%d: database cluster state problem\n", __LINE__);
|
||||
|
||||
p++; /* remove ':' char */
|
||||
|
||||
/*
|
||||
* We checked earlier for a postmaster lock file, and if we found
|
||||
* one, we tried to start/stop the server to replay the WAL. However,
|
||||
* pg_ctl -m immediate doesn't leave a lock file, but does require
|
||||
* WAL replay, so we check here that the server was shut down cleanly,
|
||||
* from the controldata perspective.
|
||||
*/
|
||||
/* remove leading spaces */
|
||||
while (*p == ' ')
|
||||
p++;
|
||||
if (strcmp(p, "shut down\n") != 0)
|
||||
{
|
||||
if (cluster == &old_cluster)
|
||||
pg_fatal("The source cluster was not shut down cleanly.\n");
|
||||
else
|
||||
pg_fatal("The target cluster was not shut down cleanly.\n");
|
||||
}
|
||||
got_cluster_state = true;
|
||||
}
|
||||
}
|
||||
|
||||
pclose(output);
|
||||
|
||||
if (!got_cluster_state)
|
||||
{
|
||||
if (cluster == &old_cluster)
|
||||
pg_fatal("The source cluster lacks cluster state information:\n");
|
||||
else
|
||||
pg_fatal("The target cluster lacks cluster state information:\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Restore environment variables
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user