Skip to content

Commit f851361

Browse files
committed
pg_upgrade: pass username to analyze script
If -U (user) is specified, pass the username into the created analyze script. Per request from Ray Stell
1 parent e029275 commit f851361

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

contrib/pg_upgrade/check.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,13 @@ void
459459
create_script_for_cluster_analyze(char **analyze_script_file_name)
460460
{
461461
FILE *script = NULL;
462+
char *user_specification = "";
463+
464+
if (os_info.user_specified)
465+
{
466+
user_specification = pg_malloc(strlen(os_info.user) + 7);
467+
sprintf(user_specification, "-U \"%s\" ", os_info.user);
468+
}
462469

463470
*analyze_script_file_name = pg_malloc(MAXPGPATH);
464471

@@ -501,7 +508,8 @@ create_script_for_cluster_analyze(char **analyze_script_file_name)
501508
ECHO_QUOTE, ECHO_QUOTE);
502509
fprintf(script, "echo %sthis script and run:%s\n",
503510
ECHO_QUOTE, ECHO_QUOTE);
504-
fprintf(script, "echo %s \"%s/vacuumdb\" --all %s%s\n", ECHO_QUOTE, new_cluster.bindir,
511+
fprintf(script, "echo %s \"%s/vacuumdb\" %s--all %s%s\n", ECHO_QUOTE,
512+
new_cluster.bindir, user_specification,
505513
/* Did we copy the free space files? */
506514
(GET_MAJOR_VERSION(old_cluster.major_version) >= 804) ?
507515
"--analyze-only" : "--analyze", ECHO_QUOTE);
@@ -522,7 +530,8 @@ create_script_for_cluster_analyze(char **analyze_script_file_name)
522530
ECHO_QUOTE, ECHO_QUOTE);
523531
fprintf(script, "echo %s--------------------------------------------------%s\n",
524532
ECHO_QUOTE, ECHO_QUOTE);
525-
fprintf(script, "\"%s/vacuumdb\" --all --analyze-only\n", new_cluster.bindir);
533+
fprintf(script, "\"%s/vacuumdb\" %s--all --analyze-only\n",
534+
new_cluster.bindir, user_specification);
526535
fprintf(script, "echo%s\n", ECHO_BLANK);
527536
fprintf(script, "echo %sThe server is now available with minimal optimizer statistics.%s\n",
528537
ECHO_QUOTE, ECHO_QUOTE);
@@ -543,7 +552,8 @@ create_script_for_cluster_analyze(char **analyze_script_file_name)
543552
ECHO_QUOTE, ECHO_QUOTE);
544553
fprintf(script, "echo %s---------------------------------------------------%s\n",
545554
ECHO_QUOTE, ECHO_QUOTE);
546-
fprintf(script, "\"%s/vacuumdb\" --all --analyze-only\n", new_cluster.bindir);
555+
fprintf(script, "\"%s/vacuumdb\" %s--all --analyze-only\n",
556+
new_cluster.bindir, user_specification);
547557
fprintf(script, "echo%s\n\n", ECHO_BLANK);
548558

549559
#ifndef WIN32
@@ -556,7 +566,8 @@ create_script_for_cluster_analyze(char **analyze_script_file_name)
556566
ECHO_QUOTE, ECHO_QUOTE);
557567
fprintf(script, "echo %s-------------------------------------------------------------%s\n",
558568
ECHO_QUOTE, ECHO_QUOTE);
559-
fprintf(script, "\"%s/vacuumdb\" --all %s\n", new_cluster.bindir,
569+
fprintf(script, "\"%s/vacuumdb\" %s--all %s\n", new_cluster.bindir,
570+
user_specification,
560571
/* Did we copy the free space files? */
561572
(GET_MAJOR_VERSION(old_cluster.major_version) >= 804) ?
562573
"--analyze-only" : "--analyze");
@@ -573,6 +584,9 @@ create_script_for_cluster_analyze(char **analyze_script_file_name)
573584
*analyze_script_file_name, getErrorText(errno));
574585
#endif
575586

587+
if (os_info.user_specified)
588+
pg_free(user_specification);
589+
576590
check_ok();
577591
}
578592

contrib/pg_upgrade/option.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ parseCommandLine(int argc, char *argv[])
172172
case 'U':
173173
pg_free(os_info.user);
174174
os_info.user = pg_strdup(optarg);
175+
os_info.user_specified = true;
175176

176177
/*
177178
* Push the user name into the environment so pre-9.1

contrib/pg_upgrade/pg_upgrade.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ typedef struct
291291
const char *progname; /* complete pathname for this program */
292292
char *exec_path; /* full path to my executable */
293293
char *user; /* username for clusters */
294+
bool user_specified; /* user specified on command-line */
294295
char **old_tablespaces; /* tablespaces */
295296
int num_old_tablespaces;
296297
char **libraries; /* loadable libraries */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy