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

Commita80b803

Browse files
committed
In pg_upgrade, pull the port number from postmaster.pid, like we do for
socket location. Also, prevent putting the socket in the currentdirectory for pre-9.1 servers in live check and non-live check mode,because pre-9.1 pg_ctl -w can't handle it.Backpatch to 9.2.
1 parent504aeea commita80b803

File tree

3 files changed

+62
-41
lines changed

3 files changed

+62
-41
lines changed

‎contrib/pg_upgrade/check.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ output_check_banner(bool *live_check)
5858
if (user_opts.check&&is_server_running(old_cluster.pgdata))
5959
{
6060
*live_check= true;
61-
if (old_cluster.port==DEF_PGUPORT)
62-
pg_log(PG_FATAL,"When checking a live old server, "
63-
"you must specify the old server's port number.\n");
64-
if (old_cluster.port==new_cluster.port)
65-
pg_log(PG_FATAL,"When checking a live server, "
66-
"the old and new port numbers must be different.\n");
6761
pg_log(PG_REPORT,"Performing Consistency Checks on Old Live Server\n");
6862
pg_log(PG_REPORT,"------------------------------------------------\n");
6963
}
@@ -320,6 +314,16 @@ check_cluster_compatibility(bool live_check)
320314
new_cluster.controldata.cat_ver<TABLE_SPACE_SUBDIRS_CAT_VER)
321315
pg_log(PG_FATAL,"This utility can only upgrade to PostgreSQL version 9.0 after 2010-01-11\n"
322316
"because of backend API changes made during development.\n");
317+
318+
/* We read the real port number for PG >= 9.1 */
319+
if (live_check&&GET_MAJOR_VERSION(old_cluster.major_version)<901&&
320+
old_cluster.port==DEF_PGUPORT)
321+
pg_log(PG_FATAL,"When checking a pre-PG 9.1 live old server, "
322+
"you must specify the old server's port number.\n");
323+
324+
if (live_check&&old_cluster.port==new_cluster.port)
325+
pg_log(PG_FATAL,"When checking a live server, "
326+
"the old and new port numbers must be different.\n");
323327
}
324328

325329

‎contrib/pg_upgrade/option.c

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -392,49 +392,65 @@ void
392392
get_sock_dir(ClusterInfo*cluster,boollive_check)
393393
{
394394
#ifdefHAVE_UNIX_SOCKETS
395-
if (!live_check)
396-
{
397-
/* Use the current directory for the socket */
398-
cluster->sockdir=pg_malloc(MAXPGPATH);
399-
if (!getcwd(cluster->sockdir,MAXPGPATH))
400-
pg_log(PG_FATAL,"cannot find current directory\n");
401-
}
402-
else
395+
/*
396+
*sockdir and port were added to postmaster.pid in PG 9.1.
397+
*Pre-9.1 cannot process pg_ctl -w for sockets in non-default
398+
*locations.
399+
*/
400+
if (GET_MAJOR_VERSION(cluster->major_version) >=901)
403401
{
404-
/*
405-
*If we are doing a live check, we will use the old cluster's Unix
406-
*domain socket directory so we can connect to the live server.
407-
*/
408-
409-
/* sockdir was added to postmaster.pid in PG 9.1 */
410-
if (GET_MAJOR_VERSION(cluster->major_version) >=901)
402+
if (!live_check)
411403
{
412-
charfilename[MAXPGPATH];
404+
/* Use the current directory for the socket */
405+
cluster->sockdir=pg_malloc(MAXPGPATH);
406+
if (!getcwd(cluster->sockdir,MAXPGPATH))
407+
pg_log(PG_FATAL,"cannot find current directory\n");
408+
}
409+
else
410+
{
411+
/*
412+
*If we are doing a live check, we will use the old cluster's Unix
413+
*domain socket directory so we can connect to the live server.
414+
*/
415+
unsigned shortorig_port=cluster->port;
416+
charfilename[MAXPGPATH],line[MAXPGPATH];
413417
FILE*fp;
414-
inti;
415-
418+
intlineno;
419+
416420
snprintf(filename,sizeof(filename),"%s/postmaster.pid",
417421
cluster->pgdata);
418422
if ((fp=fopen(filename,"r"))==NULL)
419-
pg_log(PG_FATAL,"Could not get socket directory of the old server\n");
420-
421-
cluster->sockdir=pg_malloc(MAXPGPATH);
422-
for (i=0;i<LOCK_FILE_LINE_SOCKET_DIR;i++)
423-
if (fgets(cluster->sockdir,MAXPGPATH,fp)==NULL)
424-
pg_log(PG_FATAL,"Could not get socket directory of the old server\n");
425-
423+
pg_log(PG_FATAL,"Cannot open file %s: %m\n",filename);
424+
425+
for (lineno=1;
426+
lineno <=Max(LOCK_FILE_LINE_PORT,LOCK_FILE_LINE_SOCKET_DIR);
427+
lineno++)
428+
{
429+
if (fgets(line,sizeof(line),fp)==NULL)
430+
pg_log(PG_FATAL,"Cannot read line %d from %s: %m\n",lineno,filename);
431+
432+
/* potentially overwrite user-supplied value */
433+
if (lineno==LOCK_FILE_LINE_PORT)
434+
sscanf(line,"%hu",&old_cluster.port);
435+
if (lineno==LOCK_FILE_LINE_SOCKET_DIR)
436+
{
437+
cluster->sockdir=pg_malloc(MAXPGPATH);
438+
/* strip off newline */
439+
sscanf(line,"%s\n",cluster->sockdir);
440+
}
441+
}
426442
fclose(fp);
427-
428-
/* Remove trailing newline */
429-
if (strchr(cluster->sockdir,'\n')!=NULL)
430-
*strchr(cluster->sockdir,'\n')='\0';
431-
}
432-
else
433-
{
434-
/* Can't get live sockdir, so assume the default is OK. */
435-
cluster->sockdir=NULL;
443+
444+
/* warn of port number correction */
445+
if (orig_port!=DEF_PGUPORT&&old_cluster.port!=orig_port)
446+
pg_log(PG_WARNING,"User-supplied old port number %hu corrected to %hu\n",
447+
orig_port,cluster->port);
436448
}
437449
}
450+
else
451+
/* Can't get sockdir and pg_ctl -w can't use a non-default, use default */
452+
cluster->sockdir=NULL;
453+
438454
#else/* !HAVE_UNIX_SOCKETS */
439455
cluster->sockdir=NULL;
440456
#endif

‎contrib/pg_upgrade/pg_upgrade.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@ main(int argc, char **argv)
8686
setup(argv[0],live_check);
8787

8888
check_cluster_versions();
89-
check_cluster_compatibility(live_check);
9089

9190
get_sock_dir(&old_cluster,live_check);
9291
get_sock_dir(&new_cluster, false);
9392

93+
check_cluster_compatibility(live_check);
94+
9495
check_old_cluster(live_check,&sequence_script_file_name);
9596

9697

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp