Skip to content

Commit 8f11369

Browse files
committed
Remove analyze_new_cluster script from pg_upgrade
Since this script just runs vacuumdb anyway, remove the script and replace the instructions to run it with instructions to run vacuumdb directly. Reviewed-By: Michael Paquier Discussion: https://postgr.es/m/CABUevEwg5LDFzthhxzSj7sZGMiVsZe0VVNbzzwTQOHJ=rN7+5A@mail.gmail.com
1 parent 7e84dd2 commit 8f11369

File tree

7 files changed

+20
-106
lines changed

7 files changed

+20
-106
lines changed

src/bin/pg_upgrade/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/pg_upgrade
22
# Generated by test suite
33
/pg_upgrade_internal.log
4-
/analyze_new_cluster.sh
54
/delete_old_cluster.sh
6-
/analyze_new_cluster.bat
75
/delete_old_cluster.bat
86
/reindex_hash.sql
97
/loadable_libraries.txt

src/bin/pg_upgrade/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ uninstall:
4444

4545
clean distclean maintainer-clean:
4646
rm -f pg_upgrade$(X) $(OBJS)
47-
rm -rf analyze_new_cluster.sh delete_old_cluster.sh log/ tmp_check/ \
47+
rm -rf delete_old_cluster.sh log/ tmp_check/ \
4848
loadable_libraries.txt reindex_hash.sql \
4949
pg_upgrade_dump_globals.sql \
5050
pg_upgrade_dump_*.custom pg_upgrade_*.log

src/bin/pg_upgrade/check.c

Lines changed: 14 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,22 @@ issue_warnings_and_set_wal_level(void)
234234

235235

236236
void
237-
output_completion_banner(char *analyze_script_file_name,
238-
char *deletion_script_file_name)
237+
output_completion_banner(char *deletion_script_file_name)
239238
{
239+
PQExpBufferData user_specification;
240+
241+
initPQExpBuffer(&user_specification);
242+
if (os_info.user_specified)
243+
{
244+
appendPQExpBufferStr(&user_specification, "-U ");
245+
appendShellString(&user_specification, os_info.user);
246+
appendPQExpBufferChar(&user_specification, ' ');
247+
}
248+
240249
pg_log(PG_REPORT,
241250
"Optimizer statistics are not transferred by pg_upgrade so,\n"
242251
"once you start the new server, consider running:\n"
243-
" %s\n\n", analyze_script_file_name);
252+
" %s/vacuumdb %s--all --analyze-in-stages\n\n", new_cluster.bindir, user_specification.data);
244253

245254
if (deletion_script_file_name)
246255
pg_log(PG_REPORT,
@@ -253,6 +262,8 @@ output_completion_banner(char *analyze_script_file_name,
253262
"because user-defined tablespaces or the new cluster's data directory\n"
254263
"exist in the old cluster directory. The old cluster's contents must\n"
255264
"be deleted manually.\n");
265+
266+
termPQExpBuffer(&user_specification);
256267
}
257268

258269

@@ -446,90 +457,6 @@ check_databases_are_compatible(void)
446457
}
447458
}
448459

449-
450-
/*
451-
* create_script_for_cluster_analyze()
452-
*
453-
* This incrementally generates better optimizer statistics
454-
*/
455-
void
456-
create_script_for_cluster_analyze(char **analyze_script_file_name)
457-
{
458-
FILE *script = NULL;
459-
PQExpBufferData user_specification;
460-
461-
prep_status("Creating script to analyze new cluster");
462-
463-
initPQExpBuffer(&user_specification);
464-
if (os_info.user_specified)
465-
{
466-
appendPQExpBufferStr(&user_specification, "-U ");
467-
appendShellString(&user_specification, os_info.user);
468-
appendPQExpBufferChar(&user_specification, ' ');
469-
}
470-
471-
*analyze_script_file_name = psprintf("%sanalyze_new_cluster.%s",
472-
SCRIPT_PREFIX, SCRIPT_EXT);
473-
474-
if ((script = fopen_priv(*analyze_script_file_name, "w")) == NULL)
475-
pg_fatal("could not open file \"%s\": %s\n",
476-
*analyze_script_file_name, strerror(errno));
477-
478-
#ifndef WIN32
479-
/* add shebang header */
480-
fprintf(script, "#!/bin/sh\n\n");
481-
#else
482-
/* suppress command echoing */
483-
fprintf(script, "@echo off\n");
484-
#endif
485-
486-
fprintf(script, "echo %sThis script will generate minimal optimizer statistics rapidly%s\n",
487-
ECHO_QUOTE, ECHO_QUOTE);
488-
fprintf(script, "echo %sso your system is usable, and then gather statistics twice more%s\n",
489-
ECHO_QUOTE, ECHO_QUOTE);
490-
fprintf(script, "echo %swith increasing accuracy. When it is done, your system will%s\n",
491-
ECHO_QUOTE, ECHO_QUOTE);
492-
fprintf(script, "echo %shave the default level of optimizer statistics.%s\n",
493-
ECHO_QUOTE, ECHO_QUOTE);
494-
fprintf(script, "echo%s\n\n", ECHO_BLANK);
495-
496-
fprintf(script, "echo %sIf you have used ALTER TABLE to modify the statistics target for%s\n",
497-
ECHO_QUOTE, ECHO_QUOTE);
498-
fprintf(script, "echo %sany tables, you might want to remove them and restore them after%s\n",
499-
ECHO_QUOTE, ECHO_QUOTE);
500-
fprintf(script, "echo %srunning this script because they will delay fast statistics generation.%s\n",
501-
ECHO_QUOTE, ECHO_QUOTE);
502-
fprintf(script, "echo%s\n\n", ECHO_BLANK);
503-
504-
fprintf(script, "echo %sIf you would like default statistics as quickly as possible, cancel%s\n",
505-
ECHO_QUOTE, ECHO_QUOTE);
506-
fprintf(script, "echo %sthis script and run:%s\n",
507-
ECHO_QUOTE, ECHO_QUOTE);
508-
fprintf(script, "echo %s \"%s/vacuumdb\" %s--all --analyze-only%s\n", ECHO_QUOTE,
509-
new_cluster.bindir, user_specification.data, ECHO_QUOTE);
510-
fprintf(script, "echo%s\n\n", ECHO_BLANK);
511-
512-
fprintf(script, "\"%s/vacuumdb\" %s--all --analyze-in-stages\n",
513-
new_cluster.bindir, user_specification.data);
514-
515-
fprintf(script, "echo%s\n\n", ECHO_BLANK);
516-
fprintf(script, "echo %sDone%s\n",
517-
ECHO_QUOTE, ECHO_QUOTE);
518-
519-
fclose(script);
520-
521-
#ifndef WIN32
522-
if (chmod(*analyze_script_file_name, S_IRWXU) != 0)
523-
pg_fatal("could not add execute permission to file \"%s\": %s\n",
524-
*analyze_script_file_name, strerror(errno));
525-
#endif
526-
527-
termPQExpBuffer(&user_specification);
528-
529-
check_ok();
530-
}
531-
532-
533460
/*
534461
* A previous run of pg_upgrade might have failed and the new cluster
535462
* directory recreated, but they might have forgotten to remove

src/bin/pg_upgrade/pg_upgrade.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ char *output_files[] = {
7575
int
7676
main(int argc, char **argv)
7777
{
78-
char *analyze_script_file_name = NULL;
7978
char *deletion_script_file_name = NULL;
8079
bool live_check = false;
8180

@@ -176,7 +175,6 @@ main(int argc, char **argv)
176175
new_cluster.pgdata);
177176
check_ok();
178177

179-
create_script_for_cluster_analyze(&analyze_script_file_name);
180178
create_script_for_old_cluster_deletion(&deletion_script_file_name);
181179

182180
issue_warnings_and_set_wal_level();
@@ -186,10 +184,8 @@ main(int argc, char **argv)
186184
"Upgrade Complete\n"
187185
"----------------\n");
188186

189-
output_completion_banner(analyze_script_file_name,
190-
deletion_script_file_name);
187+
output_completion_banner(deletion_script_file_name);
191188

192-
pg_free(analyze_script_file_name);
193189
pg_free(deletion_script_file_name);
194190

195191
cleanup();

src/bin/pg_upgrade/pg_upgrade.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,10 @@ void check_and_dump_old_cluster(bool live_check);
334334
void check_new_cluster(void);
335335
void report_clusters_compatible(void);
336336
void issue_warnings_and_set_wal_level(void);
337-
void output_completion_banner(char *analyze_script_file_name,
338-
char *deletion_script_file_name);
337+
void output_completion_banner(char *deletion_script_file_name);
339338
void check_cluster_versions(void);
340339
void check_cluster_compatibility(bool live_check);
341340
void create_script_for_old_cluster_deletion(char **deletion_script_file_name);
342-
void create_script_for_cluster_analyze(char **analyze_script_file_name);
343341

344342

345343
/* controldata.c */

src/bin/pg_upgrade/test.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,7 @@ esac
243243

244244
pg_ctl start -l "$logdir/postmaster2.log" -o "$POSTMASTER_OPTS" -w
245245

246-
# In the commands below we inhibit msys2 from converting the "/c" switch
247-
# in "cmd /c" to a file system path.
248-
249-
case $testhost in
250-
MINGW*) MSYS2_ARG_CONV_EXCL=/c cmd /c analyze_new_cluster.bat ;;
251-
*) sh ./analyze_new_cluster.sh ;;
252-
esac
246+
vacuumdb --all --analyze-in-stages
253247

254248
pg_dumpall --no-sync -f "$temp_root"/dump2.sql || pg_dumpall2_status=$?
255249
pg_ctl -m fast stop

src/tools/msvc/vcregress.pl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,8 @@ sub upgradecheck
607607
@args = ('pg_ctl', '-l', "$logdir/postmaster2.log", 'start');
608608
system(@args) == 0 or exit 1;
609609
print "\nSetting up stats on new cluster\n\n";
610-
system(".\\analyze_new_cluster.bat") == 0 or exit 1;
610+
@args = ('vacuumdb', '--all', '--analyze-in-stages');
611+
system(@args) == 0 or exit 1;
611612
print "\nDumping new cluster\n\n";
612613
@args = ('pg_dumpall', '-f', "$tmp_root/dump2.sql");
613614
system(@args) == 0 or exit 1;

0 commit comments

Comments
 (0)