1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Back-patch recent pg_upgrade fixes into 9.2.

This syncs contrib/pg_upgrade in the 9.2 branch with HEAD, except for the
HEAD changes related to converting XLogRecPtr to 64-bit int.  It includes
back-patching these commits:

666d494d19
pg_upgrade: abstract out copying of files from old cluster to new
7afa8bed65
pg_upgrade: Run the created scripts in the test suite
ab577e63fa
Remove analyze_new_cluster.sh on make clean, too
34c02044ed
Fix thinko in comment
088c065ce8
pg_upgrade: Fix exec_prog API to be less flaky
f763b77193
Fix pg_upgrade to cope with non-default unix_socket_directory scenarios.
This commit is contained in:
Tom Lane
2012-09-03 15:03:08 -04:00
parent b681a874d9
commit 5c7e91e9c3
11 changed files with 274 additions and 146 deletions

View File

@ -9,6 +9,8 @@
#include "postgres.h"
#include "miscadmin.h"
#include "pg_upgrade.h"
#include <getopt_long.h>
@ -376,3 +378,64 @@ adjust_data_dir(ClusterInfo *cluster)
check_ok();
}
/*
* get_sock_dir
*
* Identify the socket directory to use for this cluster. If we're doing
* a live check (old cluster only), we need to find out where the postmaster
* is listening. Otherwise, we're going to put the socket into the current
* directory.
*/
void
get_sock_dir(ClusterInfo *cluster, bool live_check)
{
#ifdef HAVE_UNIX_SOCKETS
if (!live_check)
{
/* Use the current directory for the socket */
cluster->sockdir = pg_malloc(MAXPGPATH);
if (!getcwd(cluster->sockdir, MAXPGPATH))
pg_log(PG_FATAL, "cannot find current directory\n");
}
else
{
/*
* If we are doing a live check, we will use the old cluster's Unix
* domain socket directory so we can connect to the live server.
*/
/* sockdir was added to postmaster.pid in PG 9.1 */
if (GET_MAJOR_VERSION(cluster->major_version) >= 901)
{
char filename[MAXPGPATH];
FILE *fp;
int i;
snprintf(filename, sizeof(filename), "%s/postmaster.pid",
cluster->pgdata);
if ((fp = fopen(filename, "r")) == NULL)
pg_log(PG_FATAL, "Could not get socket directory of the old server\n");
cluster->sockdir = pg_malloc(MAXPGPATH);
for (i = 0; i < LOCK_FILE_LINE_SOCKET_DIR; i++)
if (fgets(cluster->sockdir, MAXPGPATH, fp) == NULL)
pg_log(PG_FATAL, "Could not get socket directory of the old server\n");
fclose(fp);
/* Remove trailing newline */
if (strchr(cluster->sockdir, '\n') != NULL)
*strchr(cluster->sockdir, '\n') = '\0';
}
else
{
/* Can't get live sockdir, so assume the default is OK. */
cluster->sockdir = NULL;
}
}
#else /* !HAVE_UNIX_SOCKETS */
cluster->sockdir = NULL;
#endif
}