Remove analyze_new_cluster script from pg_upgrade
authorMagnus Hagander <magnus@hagander.net>
Mon, 9 Nov 2020 11:14:59 +0000 (12:14 +0100)
committerMagnus Hagander <magnus@hagander.net>
Mon, 9 Nov 2020 11:15:48 +0000 (12:15 +0100)
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

src/bin/pg_upgrade/.gitignore
src/bin/pg_upgrade/Makefile
src/bin/pg_upgrade/check.c
src/bin/pg_upgrade/pg_upgrade.c
src/bin/pg_upgrade/pg_upgrade.h
src/bin/pg_upgrade/test.sh
src/tools/msvc/vcregress.pl

index 9edea5c98f05bbf7897a0c41410cdb68c841b65c..2d3bfeaa502137899a761835e692f60674277bd9 100644 (file)
@@ -1,9 +1,7 @@
 /pg_upgrade
 # Generated by test suite
 /pg_upgrade_internal.log
-/analyze_new_cluster.sh
 /delete_old_cluster.sh
-/analyze_new_cluster.bat
 /delete_old_cluster.bat
 /reindex_hash.sql
 /loadable_libraries.txt
index 0360c37bf904ec52ed775630c4187953777c8e95..44d06be5a61bab3c5b4c35f39efac686d01f4b01 100644 (file)
@@ -44,7 +44,7 @@ uninstall:
 
 clean distclean maintainer-clean:
    rm -f pg_upgrade$(X) $(OBJS)
-   rm -rf analyze_new_cluster.sh delete_old_cluster.sh log/ tmp_check/ \
+   rm -rf delete_old_cluster.sh log/ tmp_check/ \
           loadable_libraries.txt reindex_hash.sql \
           pg_upgrade_dump_globals.sql \
           pg_upgrade_dump_*.custom pg_upgrade_*.log
index 05e6bf7f2c3493013529d9d620db46ce1cfd0bbf..6685d517ffb27022db5f4634db084dcac727f800 100644 (file)
@@ -234,13 +234,22 @@ issue_warnings_and_set_wal_level(void)
 
 
 void
-output_completion_banner(char *analyze_script_file_name,
-                        char *deletion_script_file_name)
+output_completion_banner(char *deletion_script_file_name)
 {
+   PQExpBufferData user_specification;
+
+   initPQExpBuffer(&user_specification);
+   if (os_info.user_specified)
+   {
+       appendPQExpBufferStr(&user_specification, "-U ");
+       appendShellString(&user_specification, os_info.user);
+       appendPQExpBufferChar(&user_specification, ' ');
+   }
+
    pg_log(PG_REPORT,
           "Optimizer statistics are not transferred by pg_upgrade so,\n"
           "once you start the new server, consider running:\n"
-          "    %s\n\n", analyze_script_file_name);
+          "    %s/vacuumdb %s--all --analyze-in-stages\n\n", new_cluster.bindir, user_specification.data);
 
    if (deletion_script_file_name)
        pg_log(PG_REPORT,
@@ -253,6 +262,8 @@ output_completion_banner(char *analyze_script_file_name,
               "because user-defined tablespaces or the new cluster's data directory\n"
               "exist in the old cluster directory.  The old cluster's contents must\n"
               "be deleted manually.\n");
+
+   termPQExpBuffer(&user_specification);
 }
 
 
@@ -446,90 +457,6 @@ check_databases_are_compatible(void)
    }
 }
 
-
-/*
- * create_script_for_cluster_analyze()
- *
- * This incrementally generates better optimizer statistics
- */
-void
-create_script_for_cluster_analyze(char **analyze_script_file_name)
-{
-   FILE       *script = NULL;
-   PQExpBufferData user_specification;
-
-   prep_status("Creating script to analyze new cluster");
-
-   initPQExpBuffer(&user_specification);
-   if (os_info.user_specified)
-   {
-       appendPQExpBufferStr(&user_specification, "-U ");
-       appendShellString(&user_specification, os_info.user);
-       appendPQExpBufferChar(&user_specification, ' ');
-   }
-
-   *analyze_script_file_name = psprintf("%sanalyze_new_cluster.%s",
-                                        SCRIPT_PREFIX, SCRIPT_EXT);
-
-   if ((script = fopen_priv(*analyze_script_file_name, "w")) == NULL)
-       pg_fatal("could not open file \"%s\": %s\n",
-                *analyze_script_file_name, strerror(errno));
-
-#ifndef WIN32
-   /* add shebang header */
-   fprintf(script, "#!/bin/sh\n\n");
-#else
-   /* suppress command echoing */
-   fprintf(script, "@echo off\n");
-#endif
-
-   fprintf(script, "echo %sThis script will generate minimal optimizer statistics rapidly%s\n",
-           ECHO_QUOTE, ECHO_QUOTE);
-   fprintf(script, "echo %sso your system is usable, and then gather statistics twice more%s\n",
-           ECHO_QUOTE, ECHO_QUOTE);
-   fprintf(script, "echo %swith increasing accuracy.  When it is done, your system will%s\n",
-           ECHO_QUOTE, ECHO_QUOTE);
-   fprintf(script, "echo %shave the default level of optimizer statistics.%s\n",
-           ECHO_QUOTE, ECHO_QUOTE);
-   fprintf(script, "echo%s\n\n", ECHO_BLANK);
-
-   fprintf(script, "echo %sIf you have used ALTER TABLE to modify the statistics target for%s\n",
-           ECHO_QUOTE, ECHO_QUOTE);
-   fprintf(script, "echo %sany tables, you might want to remove them and restore them after%s\n",
-           ECHO_QUOTE, ECHO_QUOTE);
-   fprintf(script, "echo %srunning this script because they will delay fast statistics generation.%s\n",
-           ECHO_QUOTE, ECHO_QUOTE);
-   fprintf(script, "echo%s\n\n", ECHO_BLANK);
-
-   fprintf(script, "echo %sIf you would like default statistics as quickly as possible, cancel%s\n",
-           ECHO_QUOTE, ECHO_QUOTE);
-   fprintf(script, "echo %sthis script and run:%s\n",
-           ECHO_QUOTE, ECHO_QUOTE);
-   fprintf(script, "echo %s    \"%s/vacuumdb\" %s--all --analyze-only%s\n", ECHO_QUOTE,
-           new_cluster.bindir, user_specification.data, ECHO_QUOTE);
-   fprintf(script, "echo%s\n\n", ECHO_BLANK);
-
-   fprintf(script, "\"%s/vacuumdb\" %s--all --analyze-in-stages\n",
-           new_cluster.bindir, user_specification.data);
-
-   fprintf(script, "echo%s\n\n", ECHO_BLANK);
-   fprintf(script, "echo %sDone%s\n",
-           ECHO_QUOTE, ECHO_QUOTE);
-
-   fclose(script);
-
-#ifndef WIN32
-   if (chmod(*analyze_script_file_name, S_IRWXU) != 0)
-       pg_fatal("could not add execute permission to file \"%s\": %s\n",
-                *analyze_script_file_name, strerror(errno));
-#endif
-
-   termPQExpBuffer(&user_specification);
-
-   check_ok();
-}
-
-
 /*
  * A previous run of pg_upgrade might have failed and the new cluster
  * directory recreated, but they might have forgotten to remove
index 1bc86e4205de43502805583cf817d2a3735c44df..e2253ecd5d068006c8c93980a8f7a5d6f5dbd1f9 100644 (file)
@@ -75,7 +75,6 @@ char     *output_files[] = {
 int
 main(int argc, char **argv)
 {
-   char       *analyze_script_file_name = NULL;
    char       *deletion_script_file_name = NULL;
    bool        live_check = false;
 
@@ -176,7 +175,6 @@ main(int argc, char **argv)
              new_cluster.pgdata);
    check_ok();
 
-   create_script_for_cluster_analyze(&analyze_script_file_name);
    create_script_for_old_cluster_deletion(&deletion_script_file_name);
 
    issue_warnings_and_set_wal_level();
@@ -186,10 +184,8 @@ main(int argc, char **argv)
           "Upgrade Complete\n"
           "----------------\n");
 
-   output_completion_banner(analyze_script_file_name,
-                            deletion_script_file_name);
+   output_completion_banner(deletion_script_file_name);
 
-   pg_free(analyze_script_file_name);
    pg_free(deletion_script_file_name);
 
    cleanup();
index 19c64513b06a8f84bf2239ae1955fceed0109b17..ee70243c2e946eeaf14d500f3e89e96fd1952bb9 100644 (file)
@@ -334,12 +334,10 @@ void      check_and_dump_old_cluster(bool live_check);
 void       check_new_cluster(void);
 void       report_clusters_compatible(void);
 void       issue_warnings_and_set_wal_level(void);
-void       output_completion_banner(char *analyze_script_file_name,
-                                    char *deletion_script_file_name);
+void       output_completion_banner(char *deletion_script_file_name);
 void       check_cluster_versions(void);
 void       check_cluster_compatibility(bool live_check);
 void       create_script_for_old_cluster_deletion(char **deletion_script_file_name);
-void       create_script_for_cluster_analyze(char **analyze_script_file_name);
 
 
 /* controldata.c */
index 7ff06de6d182b1030d4474f21a279182958644ce..551ac8a5c266938cbb73ec79cc2ac247e663d322 100644 (file)
@@ -243,13 +243,7 @@ esac
 
 pg_ctl start -l "$logdir/postmaster2.log" -o "$POSTMASTER_OPTS" -w
 
-# In the commands below we inhibit msys2 from converting the "/c" switch
-# in "cmd /c" to a file system path.
-
-case $testhost in
-   MINGW*) MSYS2_ARG_CONV_EXCL=/c cmd /c analyze_new_cluster.bat ;;
-   *)      sh ./analyze_new_cluster.sh ;;
-esac
+vacuumdb --all --analyze-in-stages
 
 pg_dumpall --no-sync -f "$temp_root"/dump2.sql || pg_dumpall2_status=$?
 pg_ctl -m fast stop
index 3365ee578c3dbd1d717c42ba47348d9a1b702724..9799c5f54b870b00b885cc2fbd76f3935c2e12cc 100644 (file)
@@ -607,7 +607,8 @@ sub upgradecheck
    @args = ('pg_ctl', '-l', "$logdir/postmaster2.log", 'start');
    system(@args) == 0 or exit 1;
    print "\nSetting up stats on new cluster\n\n";
-   system(".\\analyze_new_cluster.bat") == 0 or exit 1;
+   @args = ('vacuumdb', '--all', '--analyze-in-stages');
+   system(@args) == 0 or exit 1;
    print "\nDumping new cluster\n\n";
    @args = ('pg_dumpall', '-f', "$tmp_root/dump2.sql");
    system(@args) == 0 or exit 1;