Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit244142d

Browse files
committed
pg_upgrade: check for clean server shutdowns
Previously pg_upgrade checked for the pid file and started/stopped theserver to force a clean shutdown. However, "pg_ctl -m immediate"removes the pid file but doesn't do a clean shutdown, so checkpg_controldata for a clean shutdown too.Diagnosed-by: Vimalraj ADiscussion:https://postgr.es/m/CAFKBAK5e4Q-oTUuPPJ56EU_d2Rzodq6GWKS3ncAk3xo7hAsOZg@mail.gmail.comBackpatch-through: 9.3
1 parent60e3bd1 commit244142d

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

‎src/bin/pg_upgrade/controldata.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ get_control_data(ClusterInfo *cluster, bool live_check)
5858
boolgot_large_object= false;
5959
boolgot_date_is_int= false;
6060
boolgot_data_checksum_version= false;
61+
boolgot_cluster_state= false;
6162
char*lc_collate=NULL;
6263
char*lc_ctype=NULL;
6364
char*lc_monetary=NULL;
@@ -422,6 +423,64 @@ get_control_data(ClusterInfo *cluster, bool live_check)
422423

423424
pclose(output);
424425

426+
/*
427+
* Check for clean shutdown
428+
*/
429+
430+
/* only pg_controldata outputs the cluster state */
431+
snprintf(cmd,sizeof(cmd),"\"%s/pg_controldata\" \"%s\"",
432+
cluster->bindir,cluster->pgdata);
433+
fflush(stdout);
434+
fflush(stderr);
435+
436+
if ((output=popen(cmd,"r"))==NULL)
437+
pg_fatal("could not get control data using %s: %s\n",
438+
cmd,strerror(errno));
439+
440+
/* we have the result of cmd in "output". so parse it line by line now */
441+
while (fgets(bufin,sizeof(bufin),output))
442+
{
443+
if ((!live_check||cluster==&new_cluster)&&
444+
(p=strstr(bufin,"Database cluster state:"))!=NULL)
445+
{
446+
p=strchr(p,':');
447+
448+
if (p==NULL||strlen(p) <=1)
449+
pg_fatal("%d: database cluster state problem\n",__LINE__);
450+
451+
p++;/* remove ':' char */
452+
453+
/*
454+
* We checked earlier for a postmaster lock file, and if we found
455+
* one, we tried to start/stop the server to replay the WAL. However,
456+
* pg_ctl -m immediate doesn't leave a lock file, but does require
457+
* WAL replay, so we check here that the server was shut down cleanly,
458+
* from the controldata perspective.
459+
*/
460+
/* remove leading spaces */
461+
while (*p==' ')
462+
p++;
463+
if (strcmp(p,"shut down\n")!=0)
464+
{
465+
if (cluster==&old_cluster)
466+
pg_fatal("The source cluster was not shut down cleanly.\n");
467+
else
468+
pg_fatal("The target cluster was not shut down cleanly.\n");
469+
}
470+
got_cluster_state= true;
471+
}
472+
}
473+
474+
pclose(output);
475+
476+
if (!got_cluster_state)
477+
{
478+
if (cluster==&old_cluster)
479+
pg_fatal("The source cluster lacks cluster state information:\n");
480+
else
481+
pg_fatal("The target cluster lacks cluster state information:\n");
482+
}
483+
425484
/*
426485
* Restore environment variables
427486
*/

‎src/bin/pg_upgrade/pg_upgrade.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ setup(char *argv0, bool *live_check)
220220
* start, assume the server is running. If the pid file is left over
221221
* from a server crash, this also allows any committed transactions
222222
* stored in the WAL to be replayed so they are not lost, because WAL
223-
* files are not transferred from old to new servers.
223+
* files are not transferred from old to new servers. We later check
224+
* for a clean shutdown.
224225
*/
225226
if (start_postmaster(&old_cluster, false))
226227
stop_postmaster(false);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp