LCOV - code coverage report
Current view: top level - src/bin/scripts - vacuumdb.c (source / functions) Hit Total Coverage
Test: PostgreSQL 12beta2 Lines: 353 443 79.7 %
Date: 2019-06-18 07:06:57 Functions: 12 12 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*-------------------------------------------------------------------------
       2             :  *
       3             :  * vacuumdb
       4             :  *
       5             :  * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
       6             :  * Portions Copyright (c) 1994, Regents of the University of California
       7             :  *
       8             :  * src/bin/scripts/vacuumdb.c
       9             :  *
      10             :  *-------------------------------------------------------------------------
      11             :  */
      12             : 
      13             : #include "postgres_fe.h"
      14             : 
      15             : #ifdef HAVE_SYS_SELECT_H
      16             : #include <sys/select.h>
      17             : #endif
      18             : 
      19             : #include "catalog/pg_class_d.h"
      20             : 
      21             : #include "common.h"
      22             : #include "common/logging.h"
      23             : #include "fe_utils/connect.h"
      24             : #include "fe_utils/simple_list.h"
      25             : #include "fe_utils/string_utils.h"
      26             : 
      27             : 
      28             : #define ERRCODE_UNDEFINED_TABLE  "42P01"
      29             : 
      30             : /* Parallel vacuuming stuff */
      31             : typedef struct ParallelSlot
      32             : {
      33             :     PGconn     *connection;     /* One connection */
      34             :     bool        isFree;         /* Is it known to be idle? */
      35             : } ParallelSlot;
      36             : 
      37             : /* vacuum options controlled by user flags */
      38             : typedef struct vacuumingOptions
      39             : {
      40             :     bool        analyze_only;
      41             :     bool        verbose;
      42             :     bool        and_analyze;
      43             :     bool        full;
      44             :     bool        freeze;
      45             :     bool        disable_page_skipping;
      46             :     bool        skip_locked;
      47             :     int         min_xid_age;
      48             :     int         min_mxid_age;
      49             : } vacuumingOptions;
      50             : 
      51             : 
      52             : static void vacuum_one_database(const char *dbname, vacuumingOptions *vacopts,
      53             :                                 int stage,
      54             :                                 SimpleStringList *tables,
      55             :                                 const char *host, const char *port,
      56             :                                 const char *username, enum trivalue prompt_password,
      57             :                                 int concurrentCons,
      58             :                                 const char *progname, bool echo, bool quiet);
      59             : 
      60             : static void vacuum_all_databases(vacuumingOptions *vacopts,
      61             :                                  bool analyze_in_stages,
      62             :                                  const char *maintenance_db,
      63             :                                  const char *host, const char *port,
      64             :                                  const char *username, enum trivalue prompt_password,
      65             :                                  int concurrentCons,
      66             :                                  const char *progname, bool echo, bool quiet);
      67             : 
      68             : static void prepare_vacuum_command(PQExpBuffer sql, int serverVersion,
      69             :                                    vacuumingOptions *vacopts, const char *table);
      70             : 
      71             : static void run_vacuum_command(PGconn *conn, const char *sql, bool echo,
      72             :                                const char *table, const char *progname, bool async);
      73             : 
      74             : static ParallelSlot *GetIdleSlot(ParallelSlot slots[], int numslots,
      75             :                                  const char *progname);
      76             : 
      77             : static bool ProcessQueryResult(PGconn *conn, PGresult *result,
      78             :                                const char *progname);
      79             : 
      80             : static bool GetQueryResult(PGconn *conn, const char *progname);
      81             : 
      82             : static void DisconnectDatabase(ParallelSlot *slot);
      83             : 
      84             : static int  select_loop(int maxFd, fd_set *workerset, bool *aborting);
      85             : 
      86             : static void init_slot(ParallelSlot *slot, PGconn *conn);
      87             : 
      88             : static void help(const char *progname);
      89             : 
      90             : /* For analyze-in-stages mode */
      91             : #define ANALYZE_NO_STAGE    -1
      92             : #define ANALYZE_NUM_STAGES  3
      93             : 
      94             : 
      95             : int
      96          64 : main(int argc, char *argv[])
      97             : {
      98             :     static struct option long_options[] = {
      99             :         {"host", required_argument, NULL, 'h'},
     100             :         {"port", required_argument, NULL, 'p'},
     101             :         {"username", required_argument, NULL, 'U'},
     102             :         {"no-password", no_argument, NULL, 'w'},
     103             :         {"password", no_argument, NULL, 'W'},
     104             :         {"echo", no_argument, NULL, 'e'},
     105             :         {"quiet", no_argument, NULL, 'q'},
     106             :         {"dbname", required_argument, NULL, 'd'},
     107             :         {"analyze", no_argument, NULL, 'z'},
     108             :         {"analyze-only", no_argument, NULL, 'Z'},
     109             :         {"freeze", no_argument, NULL, 'F'},
     110             :         {"all", no_argument, NULL, 'a'},
     111             :         {"table", required_argument, NULL, 't'},
     112             :         {"full", no_argument, NULL, 'f'},
     113             :         {"verbose", no_argument, NULL, 'v'},
     114             :         {"jobs", required_argument, NULL, 'j'},
     115             :         {"maintenance-db", required_argument, NULL, 2},
     116             :         {"analyze-in-stages", no_argument, NULL, 3},
     117             :         {"disable-page-skipping", no_argument, NULL, 4},
     118             :         {"skip-locked", no_argument, NULL, 5},
     119             :         {"min-xid-age", required_argument, NULL, 6},
     120             :         {"min-mxid-age", required_argument, NULL, 7},
     121             :         {NULL, 0, NULL, 0}
     122             :     };
     123             : 
     124             :     const char *progname;
     125             :     int         optindex;
     126             :     int         c;
     127          64 :     const char *dbname = NULL;
     128          64 :     const char *maintenance_db = NULL;
     129          64 :     char       *host = NULL;
     130          64 :     char       *port = NULL;
     131          64 :     char       *username = NULL;
     132          64 :     enum trivalue prompt_password = TRI_DEFAULT;
     133          64 :     bool        echo = false;
     134          64 :     bool        quiet = false;
     135             :     vacuumingOptions vacopts;
     136          64 :     bool        analyze_in_stages = false;
     137          64 :     bool        alldb = false;
     138          64 :     SimpleStringList tables = {NULL, NULL};
     139          64 :     int         concurrentCons = 1;
     140          64 :     int         tbl_count = 0;
     141             : 
     142             :     /* initialize options to all false */
     143          64 :     memset(&vacopts, 0, sizeof(vacopts));
     144             : 
     145          64 :     pg_logging_init(argv[0]);
     146          64 :     progname = get_progname(argv[0]);
     147          64 :     set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts"));
     148             : 
     149          64 :     handle_help_version_opts(argc, argv, "vacuumdb", help);
     150             : 
     151          60 :     while ((c = getopt_long(argc, argv, "h:p:U:wWeqd:zZFat:fvj:", long_options, &optindex)) != -1)
     152             :     {
     153         112 :         switch (c)
     154             :         {
     155             :             case 'h':
     156           4 :                 host = pg_strdup(optarg);
     157           4 :                 break;
     158             :             case 'p':
     159           4 :                 port = pg_strdup(optarg);
     160           4 :                 break;
     161             :             case 'U':
     162           4 :                 username = pg_strdup(optarg);
     163           4 :                 break;
     164             :             case 'w':
     165           0 :                 prompt_password = TRI_NO;
     166           0 :                 break;
     167             :             case 'W':
     168           0 :                 prompt_password = TRI_YES;
     169           0 :                 break;
     170             :             case 'e':
     171           2 :                 echo = true;
     172           2 :                 break;
     173             :             case 'q':
     174           0 :                 quiet = true;
     175           0 :                 break;
     176             :             case 'd':
     177           0 :                 dbname = pg_strdup(optarg);
     178           0 :                 break;
     179             :             case 'z':
     180          10 :                 vacopts.and_analyze = true;
     181          10 :                 break;
     182             :             case 'Z':
     183          20 :                 vacopts.analyze_only = true;
     184          20 :                 break;
     185             :             case 'F':
     186           4 :                 vacopts.freeze = true;
     187           4 :                 break;
     188             :             case 'a':
     189          12 :                 alldb = true;
     190          12 :                 break;
     191             :             case 't':
     192             :                 {
     193          24 :                     simple_string_list_append(&tables, optarg);
     194          24 :                     tbl_count++;
     195          24 :                     break;
     196             :                 }
     197             :             case 'f':
     198           2 :                 vacopts.full = true;
     199           2 :                 break;
     200             :             case 'v':
     201           0 :                 vacopts.verbose = true;
     202           0 :                 break;
     203             :             case 'j':
     204           2 :                 concurrentCons = atoi(optarg);
     205           2 :                 if (concurrentCons <= 0)
     206             :                 {
     207           0 :                     pg_log_error("number of parallel jobs must be at least 1");
     208           0 :                     exit(1);
     209             :                 }
     210           2 :                 if (concurrentCons > FD_SETSIZE - 1)
     211             :                 {
     212           0 :                     pg_log_error("too many parallel jobs requested (maximum: %d)",
     213             :                                  FD_SETSIZE - 1);
     214           0 :                     exit(1);
     215             :                 }
     216           2 :                 break;
     217             :             case 2:
     218           0 :                 maintenance_db = pg_strdup(optarg);
     219           0 :                 break;
     220             :             case 3:
     221           6 :                 analyze_in_stages = vacopts.analyze_only = true;
     222           6 :                 break;
     223             :             case 4:
     224           4 :                 vacopts.disable_page_skipping = true;
     225           4 :                 break;
     226             :             case 5:
     227           4 :                 vacopts.skip_locked = true;
     228           4 :                 break;
     229             :             case 6:
     230           4 :                 vacopts.min_xid_age = atoi(optarg);
     231           4 :                 if (vacopts.min_xid_age <= 0)
     232             :                 {
     233           2 :                     pg_log_error("minimum transaction ID age must be at least 1");
     234           2 :                     exit(1);
     235             :                 }
     236           2 :                 break;
     237             :             case 7:
     238           4 :                 vacopts.min_mxid_age = atoi(optarg);
     239           4 :                 if (vacopts.min_mxid_age <= 0)
     240             :                 {
     241           2 :                     pg_log_error("minimum multixact ID age must be at least 1");
     242           2 :                     exit(1);
     243             :                 }
     244           2 :                 break;
     245             :             default:
     246           2 :                 fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
     247           2 :                 exit(1);
     248             :         }
     249             :     }
     250             : 
     251             :     /*
     252             :      * Non-option argument specifies database name as long as it wasn't
     253             :      * already specified with -d / --dbname
     254             :      */
     255          54 :     if (optind < argc && dbname == NULL)
     256             :     {
     257          42 :         dbname = argv[optind];
     258          42 :         optind++;
     259             :     }
     260             : 
     261          54 :     if (optind < argc)
     262             :     {
     263           0 :         pg_log_error("too many command-line arguments (first is \"%s\")",
     264             :                      argv[optind]);
     265           0 :         fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
     266           0 :         exit(1);
     267             :     }
     268             : 
     269          54 :     if (vacopts.analyze_only)
     270             :     {
     271          26 :         if (vacopts.full)
     272             :         {
     273           0 :             pg_log_error("cannot use the \"%s\" option when performing only analyze",
     274             :                          "full");
     275           0 :             exit(1);
     276             :         }
     277          26 :         if (vacopts.freeze)
     278             :         {
     279           0 :             pg_log_error("cannot use the \"%s\" option when performing only analyze",
     280             :                          "freeze");
     281           0 :             exit(1);
     282             :         }
     283          26 :         if (vacopts.disable_page_skipping)
     284             :         {
     285           2 :             pg_log_error("cannot use the \"%s\" option when performing only analyze",
     286             :                          "disable-page-skipping");
     287           2 :             exit(1);
     288             :         }
     289             :         /* allow 'and_analyze' with 'analyze_only' */
     290             :     }
     291             : 
     292          52 :     setup_cancel_handler();
     293             : 
     294             :     /* Avoid opening extra connections. */
     295          52 :     if (tbl_count && (concurrentCons > tbl_count))
     296           0 :         concurrentCons = tbl_count;
     297             : 
     298          52 :     if (alldb)
     299             :     {
     300          12 :         if (dbname)
     301             :         {
     302           0 :             pg_log_error("cannot vacuum all databases and a specific one at the same time");
     303           0 :             exit(1);
     304             :         }
     305          12 :         if (tables.head != NULL)
     306             :         {
     307           0 :             pg_log_error("cannot vacuum specific table(s) in all databases");
     308           0 :             exit(1);
     309             :         }
     310             : 
     311          12 :         vacuum_all_databases(&vacopts,
     312             :                              analyze_in_stages,
     313             :                              maintenance_db,
     314             :                              host, port, username, prompt_password,
     315             :                              concurrentCons,
     316             :                              progname, echo, quiet);
     317             :     }
     318             :     else
     319             :     {
     320          40 :         if (dbname == NULL)
     321             :         {
     322           0 :             if (getenv("PGDATABASE"))
     323           0 :                 dbname = getenv("PGDATABASE");
     324           0 :             else if (getenv("PGUSER"))
     325           0 :                 dbname = getenv("PGUSER");
     326             :             else
     327           0 :                 dbname = get_user_name_or_exit(progname);
     328             :         }
     329             : 
     330          40 :         if (analyze_in_stages)
     331             :         {
     332             :             int         stage;
     333             : 
     334           8 :             for (stage = 0; stage < ANALYZE_NUM_STAGES; stage++)
     335             :             {
     336           6 :                 vacuum_one_database(dbname, &vacopts,
     337             :                                     stage,
     338             :                                     &tables,
     339             :                                     host, port, username, prompt_password,
     340             :                                     concurrentCons,
     341             :                                     progname, echo, quiet);
     342             :             }
     343             :         }
     344             :         else
     345          38 :             vacuum_one_database(dbname, &vacopts,
     346             :                                 ANALYZE_NO_STAGE,
     347             :                                 &tables,
     348             :                                 host, port, username, prompt_password,
     349             :                                 concurrentCons,
     350             :                                 progname, echo, quiet);
     351             :     }
     352             : 
     353          46 :     exit(0);
     354             : }
     355             : 
     356             : /*
     357             :  * vacuum_one_database
     358             :  *
     359             :  * Process tables in the given database.  If the 'tables' list is empty,
     360             :  * process all tables in the database.
     361             :  *
     362             :  * Note that this function is only concerned with running exactly one stage
     363             :  * when in analyze-in-stages mode; caller must iterate on us if necessary.
     364             :  *
     365             :  * If concurrentCons is > 1, multiple connections are used to vacuum tables
     366             :  * in parallel.  In this case and if the table list is empty, we first obtain
     367             :  * a list of tables from the database.
     368             :  */
     369             : static void
     370         118 : vacuum_one_database(const char *dbname, vacuumingOptions *vacopts,
     371             :                     int stage,
     372             :                     SimpleStringList *tables,
     373             :                     const char *host, const char *port,
     374             :                     const char *username, enum trivalue prompt_password,
     375             :                     int concurrentCons,
     376             :                     const char *progname, bool echo, bool quiet)
     377             : {
     378             :     PQExpBufferData sql;
     379             :     PQExpBufferData buf;
     380             :     PQExpBufferData catalog_query;
     381             :     PGresult   *res;
     382             :     PGconn     *conn;
     383             :     SimpleStringListCell *cell;
     384             :     ParallelSlot *slots;
     385         118 :     SimpleStringList dbtables = {NULL, NULL};
     386             :     int         i;
     387             :     int         ntups;
     388         118 :     bool        failed = false;
     389         118 :     bool        parallel = concurrentCons > 1;
     390         118 :     bool        tables_listed = false;
     391         118 :     bool        has_where = false;
     392         118 :     const char *stage_commands[] = {
     393             :         "SET default_statistics_target=1; SET vacuum_cost_delay=0;",
     394             :         "SET default_statistics_target=10; RESET vacuum_cost_delay;",
     395             :         "RESET default_statistics_target;"
     396             :     };
     397         118 :     const char *stage_messages[] = {
     398             :         gettext_noop("Generating minimal optimizer statistics (1 target)"),
     399             :         gettext_noop("Generating medium optimizer statistics (10 targets)"),
     400             :         gettext_noop("Generating default (full) optimizer statistics")
     401             :     };
     402             : 
     403             :     Assert(stage == ANALYZE_NO_STAGE ||
     404             :            (stage >= 0 && stage < ANALYZE_NUM_STAGES));
     405             : 
     406         118 :     conn = connectDatabase(dbname, host, port, username, prompt_password,
     407             :                            progname, echo, false, true);
     408             : 
     409         118 :     if (vacopts->disable_page_skipping && PQserverVersion(conn) < 90600)
     410             :     {
     411           0 :         PQfinish(conn);
     412           0 :         pg_log_error("cannot use the \"%s\" option on server versions older than PostgreSQL %s",
     413             :                      "disable-page-skipping", "9.6");
     414           0 :         exit(1);
     415             :     }
     416             : 
     417         118 :     if (vacopts->skip_locked && PQserverVersion(conn) < 120000)
     418             :     {
     419           0 :         PQfinish(conn);
     420           0 :         pg_log_error("cannot use the \"%s\" option on server versions older than PostgreSQL %s",
     421             :                      "skip-locked", "12");
     422           0 :         exit(1);
     423             :     }
     424             : 
     425         118 :     if (vacopts->min_xid_age != 0 && PQserverVersion(conn) < 90600)
     426             :     {
     427           0 :         pg_log_error("cannot use the \"%s\" option on server versions older than PostgreSQL %s",
     428             :                      "--min-xid-age", "9.6");
     429           0 :         exit(1);
     430             :     }
     431             : 
     432         118 :     if (vacopts->min_mxid_age != 0 && PQserverVersion(conn) < 90600)
     433             :     {
     434           0 :         pg_log_error("cannot use the \"%s\" option on server versions older than PostgreSQL %s",
     435             :                      "--min-mxid-age", "9.6");
     436           0 :         exit(1);
     437             :     }
     438             : 
     439         118 :     if (!quiet)
     440             :     {
     441         118 :         if (stage != ANALYZE_NO_STAGE)
     442          54 :             printf(_("%s: processing database \"%s\": %s\n"),
     443             :                    progname, PQdb(conn), _(stage_messages[stage]));
     444             :         else
     445          64 :             printf(_("%s: vacuuming database \"%s\"\n"),
     446             :                    progname, PQdb(conn));
     447         118 :         fflush(stdout);
     448             :     }
     449             : 
     450             :     /*
     451             :      * Prepare the list of tables to process by querying the catalogs.
     452             :      *
     453             :      * Since we execute the constructed query with the default search_path
     454             :      * (which could be unsafe), everything in this query MUST be fully
     455             :      * qualified.
     456             :      *
     457             :      * First, build a WITH clause for the catalog query if any tables were
     458             :      * specified, with a set of values made of relation names and their
     459             :      * optional set of columns.  This is used to match any provided column
     460             :      * lists with the generated qualified identifiers and to filter for the
     461             :      * tables provided via --table.  If a listed table does not exist, the
     462             :      * catalog query will fail.
     463             :      */
     464         118 :     initPQExpBuffer(&catalog_query);
     465         138 :     for (cell = tables ? tables->head : NULL; cell; cell = cell->next)
     466             :     {
     467             :         char       *just_table;
     468             :         const char *just_columns;
     469             : 
     470             :         /*
     471             :          * Split relation and column names given by the user, this is used to
     472             :          * feed the CTE with values on which are performed pre-run validity
     473             :          * checks as well.  For now these happen only on the relation name.
     474             :          */
     475          20 :         splitTableColumnsSpec(cell->val, PQclientEncoding(conn),
     476             :                               &just_table, &just_columns);
     477             : 
     478          20 :         if (!tables_listed)
     479             :         {
     480          20 :             appendPQExpBuffer(&catalog_query,
     481             :                               "WITH listed_tables (table_oid, column_list) "
     482             :                               "AS (\n  VALUES (");
     483          20 :             tables_listed = true;
     484             :         }
     485             :         else
     486           0 :             appendPQExpBuffer(&catalog_query, ",\n  (");
     487             : 
     488          20 :         appendStringLiteralConn(&catalog_query, just_table, conn);
     489          20 :         appendPQExpBuffer(&catalog_query, "::pg_catalog.regclass, ");
     490             : 
     491          20 :         if (just_columns && just_columns[0] != '\0')
     492          10 :             appendStringLiteralConn(&catalog_query, just_columns, conn);
     493             :         else
     494          10 :             appendPQExpBufferStr(&catalog_query, "NULL");
     495             : 
     496          20 :         appendPQExpBufferStr(&catalog_query, "::pg_catalog.text)");
     497             : 
     498          20 :         pg_free(just_table);
     499             :     }
     500             : 
     501             :     /* Finish formatting the CTE */
     502         118 :     if (tables_listed)
     503          20 :         appendPQExpBuffer(&catalog_query, "\n)\n");
     504             : 
     505         118 :     appendPQExpBuffer(&catalog_query, "SELECT c.relname, ns.nspname");
     506             : 
     507         118 :     if (tables_listed)
     508          20 :         appendPQExpBuffer(&catalog_query, ", listed_tables.column_list");
     509             : 
     510         118 :     appendPQExpBuffer(&catalog_query,
     511             :                       " FROM pg_catalog.pg_class c\n"
     512             :                       " JOIN pg_catalog.pg_namespace ns"
     513             :                       " ON c.relnamespace OPERATOR(pg_catalog.=) ns.oid\n"
     514             :                       " LEFT JOIN pg_catalog.pg_class t"
     515             :                       " ON c.reltoastrelid OPERATOR(pg_catalog.=) t.oid\n");
     516             : 
     517             :     /* Used to match the tables listed by the user */
     518         118 :     if (tables_listed)
     519          20 :         appendPQExpBuffer(&catalog_query, " JOIN listed_tables"
     520             :                           " ON listed_tables.table_oid OPERATOR(pg_catalog.=) c.oid\n");
     521             : 
     522             :     /*
     523             :      * If no tables were listed, filter for the relevant relation types.  If
     524             :      * tables were given via --table, don't bother filtering by relation type.
     525             :      * Instead, let the server decide whether a given relation can be
     526             :      * processed in which case the user will know about it.
     527             :      */
     528         118 :     if (!tables_listed)
     529             :     {
     530          98 :         appendPQExpBuffer(&catalog_query, " WHERE c.relkind OPERATOR(pg_catalog.=) ANY (array["
     531             :                           CppAsString2(RELKIND_RELATION) ", "
     532             :                           CppAsString2(RELKIND_MATVIEW) "])\n");
     533          98 :         has_where = true;
     534             :     }
     535             : 
     536             :     /*
     537             :      * For --min-xid-age and --min-mxid-age, the age of the relation is the
     538             :      * greatest of the ages of the main relation and its associated TOAST
     539             :      * table.  The commands generated by vacuumdb will also process the TOAST
     540             :      * table for the relation if necessary, so it does not need to be
     541             :      * considered separately.
     542             :      */
     543         118 :     if (vacopts->min_xid_age != 0)
     544             :     {
     545           2 :         appendPQExpBuffer(&catalog_query,
     546             :                           " %s GREATEST(pg_catalog.age(c.relfrozenxid),"
     547             :                           " pg_catalog.age(t.relfrozenxid)) "
     548             :                           " OPERATOR(pg_catalog.>=) '%d'::pg_catalog.int4\n"
     549             :                           " AND c.relfrozenxid OPERATOR(pg_catalog.!=)"
     550             :                           " '0'::pg_catalog.xid\n",
     551             :                           has_where ? "AND" : "WHERE", vacopts->min_xid_age);
     552           2 :         has_where = true;
     553             :     }
     554             : 
     555         118 :     if (vacopts->min_mxid_age != 0)
     556             :     {
     557           2 :         appendPQExpBuffer(&catalog_query,
     558             :                           " %s GREATEST(pg_catalog.mxid_age(c.relminmxid),"
     559             :                           " pg_catalog.mxid_age(t.relminmxid)) OPERATOR(pg_catalog.>=)"
     560             :                           " '%d'::pg_catalog.int4\n"
     561             :                           " AND c.relminmxid OPERATOR(pg_catalog.!=)"
     562             :                           " '0'::pg_catalog.xid\n",
     563             :                           has_where ? "AND" : "WHERE", vacopts->min_mxid_age);
     564           2 :         has_where = true;
     565             :     }
     566             : 
     567             :     /*
     568             :      * Execute the catalog query.  We use the default search_path for this
     569             :      * query for consistency with table lookups done elsewhere by the user.
     570             :      */
     571         118 :     appendPQExpBuffer(&catalog_query, " ORDER BY c.relpages DESC;");
     572         118 :     executeCommand(conn, "RESET search_path;", progname, echo);
     573         118 :     res = executeQuery(conn, catalog_query.data, progname, echo);
     574         116 :     termPQExpBuffer(&catalog_query);
     575         116 :     PQclear(executeQuery(conn, ALWAYS_SECURE_SEARCH_PATH_SQL,
     576             :                          progname, echo));
     577             : 
     578             :     /*
     579             :      * If no rows are returned, there are no matching tables, so we are done.
     580             :      */
     581         116 :     ntups = PQntuples(res);
     582         116 :     if (ntups == 0)
     583             :     {
     584           4 :         PQclear(res);
     585           4 :         PQfinish(conn);
     586           4 :         return;
     587             :     }
     588             : 
     589             :     /*
     590             :      * Build qualified identifiers for each table, including the column list
     591             :      * if given.
     592             :      */
     593         112 :     initPQExpBuffer(&buf);
     594        9620 :     for (i = 0; i < ntups; i++)
     595             :     {
     596        9508 :         appendPQExpBufferStr(&buf,
     597        9508 :                              fmtQualifiedId(PQgetvalue(res, i, 1),
     598        9508 :                                             PQgetvalue(res, i, 0)));
     599             : 
     600        9508 :         if (tables_listed && !PQgetisnull(res, i, 2))
     601          10 :             appendPQExpBufferStr(&buf, PQgetvalue(res, i, 2));
     602             : 
     603        9508 :         simple_string_list_append(&dbtables, buf.data);
     604        9508 :         resetPQExpBuffer(&buf);
     605             :     }
     606         112 :     termPQExpBuffer(&buf);
     607         112 :     PQclear(res);
     608             : 
     609             :     /*
     610             :      * If there are more connections than vacuumable relations, we don't need
     611             :      * to use them all.
     612             :      */
     613         112 :     if (parallel)
     614             :     {
     615           2 :         if (concurrentCons > ntups)
     616           0 :             concurrentCons = ntups;
     617           2 :         if (concurrentCons <= 1)
     618           0 :             parallel = false;
     619             :     }
     620             : 
     621             :     /*
     622             :      * Setup the database connections. We reuse the connection we already have
     623             :      * for the first slot.  If not in parallel mode, the first slot in the
     624             :      * array contains the connection.
     625             :      */
     626         112 :     if (concurrentCons <= 0)
     627           0 :         concurrentCons = 1;
     628         112 :     slots = (ParallelSlot *) pg_malloc(sizeof(ParallelSlot) * concurrentCons);
     629         112 :     init_slot(slots, conn);
     630         112 :     if (parallel)
     631             :     {
     632           4 :         for (i = 1; i < concurrentCons; i++)
     633             :         {
     634           2 :             conn = connectDatabase(dbname, host, port, username, prompt_password,
     635             :                                    progname, echo, false, true);
     636           2 :             init_slot(slots + i, conn);
     637             :         }
     638             :     }
     639             : 
     640             :     /*
     641             :      * Prepare all the connections to run the appropriate analyze stage, if
     642             :      * caller requested that mode.
     643             :      */
     644         112 :     if (stage != ANALYZE_NO_STAGE)
     645             :     {
     646             :         int         j;
     647             : 
     648             :         /* We already emitted the message above */
     649             : 
     650         108 :         for (j = 0; j < concurrentCons; j++)
     651          54 :             executeCommand((slots + j)->connection,
     652             :                            stage_commands[stage], progname, echo);
     653             :     }
     654             : 
     655         112 :     initPQExpBuffer(&sql);
     656             : 
     657         112 :     cell = dbtables.head;
     658             :     do
     659             :     {
     660        9508 :         const char *tabname = cell->val;
     661             :         ParallelSlot *free_slot;
     662             : 
     663        9508 :         if (CancelRequested)
     664             :         {
     665           0 :             failed = true;
     666           0 :             goto finish;
     667             :         }
     668             : 
     669             :         /*
     670             :          * Get the connection slot to use.  If in parallel mode, here we wait
     671             :          * for one connection to become available if none already is.  In
     672             :          * non-parallel mode we simply use the only slot we have, which we
     673             :          * know to be free.
     674             :          */
     675        9508 :         if (parallel)
     676             :         {
     677             :             /*
     678             :              * Get a free slot, waiting until one becomes free if none
     679             :              * currently is.
     680             :              */
     681         140 :             free_slot = GetIdleSlot(slots, concurrentCons, progname);
     682         140 :             if (!free_slot)
     683             :             {
     684           0 :                 failed = true;
     685           0 :                 goto finish;
     686             :             }
     687             : 
     688         140 :             free_slot->isFree = false;
     689             :         }
     690             :         else
     691        9368 :             free_slot = slots;
     692             : 
     693        9508 :         prepare_vacuum_command(&sql, PQserverVersion(free_slot->connection),
     694             :                                vacopts, tabname);
     695             : 
     696             :         /*
     697             :          * Execute the vacuum.  If not in parallel mode, this terminates the
     698             :          * program in case of an error.  (The parallel case handles query
     699             :          * errors in ProcessQueryResult through GetIdleSlot.)
     700             :          */
     701        9508 :         run_vacuum_command(free_slot->connection, sql.data,
     702             :                            echo, tabname, progname, parallel);
     703             : 
     704        9504 :         cell = cell->next;
     705        9504 :     } while (cell != NULL);
     706             : 
     707         108 :     if (parallel)
     708             :     {
     709             :         int         j;
     710             : 
     711             :         /* wait for all connections to finish */
     712           6 :         for (j = 0; j < concurrentCons; j++)
     713             :         {
     714           4 :             if (!GetQueryResult((slots + j)->connection, progname))
     715             :             {
     716           0 :                 failed = true;
     717           0 :                 goto finish;
     718             :             }
     719             :         }
     720             :     }
     721             : 
     722             : finish:
     723         218 :     for (i = 0; i < concurrentCons; i++)
     724         110 :         DisconnectDatabase(slots + i);
     725         108 :     pfree(slots);
     726             : 
     727         108 :     termPQExpBuffer(&sql);
     728             : 
     729         108 :     if (failed)
     730           0 :         exit(1);
     731             : }
     732             : 
     733             : /*
     734             :  * Vacuum/analyze all connectable databases.
     735             :  *
     736             :  * In analyze-in-stages mode, we process all databases in one stage before
     737             :  * moving on to the next stage.  That ensure minimal stats are available
     738             :  * quickly everywhere before generating more detailed ones.
     739             :  */
     740             : static void
     741          12 : vacuum_all_databases(vacuumingOptions *vacopts,
     742             :                      bool analyze_in_stages,
     743             :                      const char *maintenance_db, const char *host,
     744             :                      const char *port, const char *username,
     745             :                      enum trivalue prompt_password,
     746             :                      int concurrentCons,
     747             :                      const char *progname, bool echo, bool quiet)
     748             : {
     749             :     PGconn     *conn;
     750             :     PGresult   *result;
     751             :     PQExpBufferData connstr;
     752             :     int         stage;
     753             :     int         i;
     754             : 
     755          12 :     conn = connectMaintenanceDatabase(maintenance_db, host, port, username,
     756             :                                       prompt_password, progname, echo);
     757          12 :     result = executeQuery(conn,
     758             :                           "SELECT datname FROM pg_database WHERE datallowconn ORDER BY 1;",
     759             :                           progname, echo);
     760          12 :     PQfinish(conn);
     761             : 
     762          12 :     initPQExpBuffer(&connstr);
     763          12 :     if (analyze_in_stages)
     764             :     {
     765             :         /*
     766             :          * When analyzing all databases in stages, we analyze them all in the
     767             :          * fastest stage first, so that initial statistics become available
     768             :          * for all of them as soon as possible.
     769             :          *
     770             :          * This means we establish several times as many connections, but
     771             :          * that's a secondary consideration.
     772             :          */
     773          16 :         for (stage = 0; stage < ANALYZE_NUM_STAGES; stage++)
     774             :         {
     775          60 :             for (i = 0; i < PQntuples(result); i++)
     776             :             {
     777          48 :                 resetPQExpBuffer(&connstr);
     778          48 :                 appendPQExpBuffer(&connstr, "dbname=");
     779          48 :                 appendConnStrVal(&connstr, PQgetvalue(result, i, 0));
     780             : 
     781          48 :                 vacuum_one_database(connstr.data, vacopts,
     782             :                                     stage,
     783             :                                     NULL,
     784             :                                     host, port, username, prompt_password,
     785             :                                     concurrentCons,
     786             :                                     progname, echo, quiet);
     787             :             }
     788             :         }
     789             :     }
     790             :     else
     791             :     {
     792          34 :         for (i = 0; i < PQntuples(result); i++)
     793             :         {
     794          26 :             resetPQExpBuffer(&connstr);
     795          26 :             appendPQExpBuffer(&connstr, "dbname=");
     796          26 :             appendConnStrVal(&connstr, PQgetvalue(result, i, 0));
     797             : 
     798          26 :             vacuum_one_database(connstr.data, vacopts,
     799             :                                 ANALYZE_NO_STAGE,
     800             :                                 NULL,
     801             :                                 host, port, username, prompt_password,
     802             :                                 concurrentCons,
     803             :                                 progname, echo, quiet);
     804             :         }
     805             :     }
     806          12 :     termPQExpBuffer(&connstr);
     807             : 
     808          12 :     PQclear(result);
     809          12 : }
     810             : 
     811             : /*
     812             :  * Construct a vacuum/analyze command to run based on the given options, in the
     813             :  * given string buffer, which may contain previous garbage.
     814             :  *
     815             :  * The table name used must be already properly quoted.  The command generated
     816             :  * depends on the server version involved and it is semicolon-terminated.
     817             :  */
     818             : static void
     819        9508 : prepare_vacuum_command(PQExpBuffer sql, int serverVersion,
     820             :                        vacuumingOptions *vacopts, const char *table)
     821             : {
     822        9508 :     const char *paren = " (";
     823        9508 :     const char *comma = ", ";
     824        9508 :     const char *sep = paren;
     825             : 
     826        9508 :     resetPQExpBuffer(sql);
     827             : 
     828        9508 :     if (vacopts->analyze_only)
     829             :     {
     830        7822 :         appendPQExpBufferStr(sql, "ANALYZE");
     831             : 
     832             :         /* parenthesized grammar of ANALYZE is supported since v11 */
     833        7822 :         if (serverVersion >= 110000)
     834             :         {
     835        7822 :             if (vacopts->skip_locked)
     836             :             {
     837             :                 /* SKIP_LOCKED is supported since v12 */
     838             :                 Assert(serverVersion >= 120000);
     839         140 :                 appendPQExpBuffer(sql, "%sSKIP_LOCKED", sep);
     840         140 :                 sep = comma;
     841             :             }
     842        7822 :             if (vacopts->verbose)
     843             :             {
     844           0 :                 appendPQExpBuffer(sql, "%sVERBOSE", sep);
     845           0 :                 sep = comma;
     846             :             }
     847        7822 :             if (sep != paren)
     848         140 :                 appendPQExpBufferChar(sql, ')');
     849             :         }
     850             :         else
     851             :         {
     852           0 :             if (vacopts->verbose)
     853           0 :                 appendPQExpBufferStr(sql, " VERBOSE");
     854             :         }
     855             :     }
     856             :     else
     857             :     {
     858        1686 :         appendPQExpBufferStr(sql, "VACUUM");
     859             : 
     860             :         /* parenthesized grammar of VACUUM is supported since v9.0 */
     861        1686 :         if (serverVersion >= 90000)
     862             :         {
     863        1686 :             if (vacopts->disable_page_skipping)
     864             :             {
     865             :                 /* DISABLE_PAGE_SKIPPING is supported since v9.6 */
     866             :                 Assert(serverVersion >= 90600);
     867         140 :                 appendPQExpBuffer(sql, "%sDISABLE_PAGE_SKIPPING", sep);
     868         140 :                 sep = comma;
     869             :             }
     870        1686 :             if (vacopts->skip_locked)
     871             :             {
     872             :                 /* SKIP_LOCKED is supported since v12 */
     873             :                 Assert(serverVersion >= 120000);
     874         140 :                 appendPQExpBuffer(sql, "%sSKIP_LOCKED", sep);
     875         140 :                 sep = comma;
     876             :             }
     877        1686 :             if (vacopts->full)
     878             :             {
     879         140 :                 appendPQExpBuffer(sql, "%sFULL", sep);
     880         140 :                 sep = comma;
     881             :             }
     882        1686 :             if (vacopts->freeze)
     883             :             {
     884         420 :                 appendPQExpBuffer(sql, "%sFREEZE", sep);
     885         420 :                 sep = comma;
     886             :             }
     887        1686 :             if (vacopts->verbose)
     888             :             {
     889           0 :                 appendPQExpBuffer(sql, "%sVERBOSE", sep);
     890           0 :                 sep = comma;
     891             :             }
     892        1686 :             if (vacopts->and_analyze)
     893             :             {
     894         426 :                 appendPQExpBuffer(sql, "%sANALYZE", sep);
     895         426 :                 sep = comma;
     896             :             }
     897        1686 :             if (sep != paren)
     898        1266 :                 appendPQExpBufferChar(sql, ')');
     899             :         }
     900             :         else
     901             :         {
     902           0 :             if (vacopts->full)
     903           0 :                 appendPQExpBufferStr(sql, " FULL");
     904           0 :             if (vacopts->freeze)
     905           0 :                 appendPQExpBufferStr(sql, " FREEZE");
     906           0 :             if (vacopts->verbose)
     907           0 :                 appendPQExpBufferStr(sql, " VERBOSE");
     908           0 :             if (vacopts->and_analyze)
     909           0 :                 appendPQExpBufferStr(sql, " ANALYZE");
     910             :         }
     911             :     }
     912             : 
     913        9508 :     appendPQExpBuffer(sql, " %s;", table);
     914        9508 : }
     915             : 
     916             : /*
     917             :  * Send a vacuum/analyze command to the server.  In async mode, return after
     918             :  * sending the command; else, wait for it to finish.
     919             :  *
     920             :  * Any errors during command execution are reported to stderr.  If async is
     921             :  * false, this function exits the program after reporting the error.
     922             :  */
     923             : static void
     924        9508 : run_vacuum_command(PGconn *conn, const char *sql, bool echo,
     925             :                    const char *table, const char *progname, bool async)
     926             : {
     927             :     bool        status;
     928             : 
     929        9508 :     if (async)
     930             :     {
     931         140 :         if (echo)
     932           0 :             printf("%s\n", sql);
     933             : 
     934         140 :         status = PQsendQuery(conn, sql) == 1;
     935             :     }
     936             :     else
     937        9368 :         status = executeMaintenanceCommand(conn, sql, echo);
     938             : 
     939        9508 :     if (!status)
     940             :     {
     941           4 :         if (table)
     942           4 :             pg_log_error("vacuuming of table \"%s\" in database \"%s\" failed: %s",
     943             :                          table, PQdb(conn), PQerrorMessage(conn));
     944             :         else
     945           0 :             pg_log_error("vacuuming of database \"%s\" failed: %s",
     946             :                          PQdb(conn), PQerrorMessage(conn));
     947             : 
     948           4 :         if (!async)
     949             :         {
     950           4 :             PQfinish(conn);
     951           4 :             exit(1);
     952             :         }
     953             :     }
     954        9504 : }
     955             : 
     956             : /*
     957             :  * GetIdleSlot
     958             :  *      Return a connection slot that is ready to execute a command.
     959             :  *
     960             :  * We return the first slot we find that is marked isFree, if one is;
     961             :  * otherwise, we loop on select() until one socket becomes available.  When
     962             :  * this happens, we read the whole set and mark as free all sockets that become
     963             :  * available.
     964             :  *
     965             :  * If an error occurs, NULL is returned.
     966             :  */
     967             : static ParallelSlot *
     968         140 : GetIdleSlot(ParallelSlot slots[], int numslots,
     969             :             const char *progname)
     970             : {
     971             :     int         i;
     972         140 :     int         firstFree = -1;
     973             : 
     974             :     /* Any connection already known free? */
     975         414 :     for (i = 0; i < numslots; i++)
     976             :     {
     977         278 :         if (slots[i].isFree)
     978           4 :             return slots + i;
     979             :     }
     980             : 
     981             :     /*
     982             :      * No free slot found, so wait until one of the connections has finished
     983             :      * its task and return the available slot.
     984             :      */
     985         408 :     while (firstFree < 0)
     986             :     {
     987             :         fd_set      slotset;
     988         136 :         int         maxFd = 0;
     989             :         bool        aborting;
     990             : 
     991             :         /* We must reconstruct the fd_set for each call to select_loop */
     992         136 :         FD_ZERO(&slotset);
     993             : 
     994         408 :         for (i = 0; i < numslots; i++)
     995             :         {
     996         272 :             int         sock = PQsocket(slots[i].connection);
     997             : 
     998             :             /*
     999             :              * We don't really expect any connections to lose their sockets
    1000             :              * after startup, but just in case, cope by ignoring them.
    1001             :              */
    1002         272 :             if (sock < 0)
    1003           0 :                 continue;
    1004             : 
    1005         272 :             FD_SET(sock, &slotset);
    1006         272 :             if (sock > maxFd)
    1007         272 :                 maxFd = sock;
    1008             :         }
    1009             : 
    1010         136 :         SetCancelConn(slots->connection);
    1011         136 :         i = select_loop(maxFd, &slotset, &aborting);
    1012         136 :         ResetCancelConn();
    1013             : 
    1014         136 :         if (aborting)
    1015             :         {
    1016             :             /*
    1017             :              * We set the cancel-receiving connection to the one in the zeroth
    1018             :              * slot above, so fetch the error from there.
    1019             :              */
    1020           0 :             GetQueryResult(slots->connection, progname);
    1021           0 :             return NULL;
    1022             :         }
    1023             :         Assert(i != 0);
    1024             : 
    1025         408 :         for (i = 0; i < numslots; i++)
    1026             :         {
    1027         272 :             int         sock = PQsocket(slots[i].connection);
    1028             : 
    1029         272 :             if (sock >= 0 && FD_ISSET(sock, &slotset))
    1030             :             {
    1031             :                 /* select() says input is available, so consume it */
    1032         136 :                 PQconsumeInput(slots[i].connection);
    1033             :             }
    1034             : 
    1035             :             /* Collect result(s) as long as any are available */
    1036         680 :             while (!PQisBusy(slots[i].connection))
    1037             :             {
    1038         272 :                 PGresult   *result = PQgetResult(slots[i].connection);
    1039             : 
    1040         272 :                 if (result != NULL)
    1041             :                 {
    1042             :                     /* Check and discard the command result */
    1043         136 :                     if (!ProcessQueryResult(slots[i].connection, result,
    1044             :                                             progname))
    1045           0 :                         return NULL;
    1046             :                 }
    1047             :                 else
    1048             :                 {
    1049             :                     /* This connection has become idle */
    1050         136 :                     slots[i].isFree = true;
    1051         136 :                     if (firstFree < 0)
    1052         136 :                         firstFree = i;
    1053         136 :                     break;
    1054             :                 }
    1055             :             }
    1056             :         }
    1057             :     }
    1058             : 
    1059         136 :     return slots + firstFree;
    1060             : }
    1061             : 
    1062             : /*
    1063             :  * ProcessQueryResult
    1064             :  *
    1065             :  * Process (and delete) a query result.  Returns true if there's no error,
    1066             :  * false otherwise -- but errors about trying to vacuum a missing relation
    1067             :  * are reported and subsequently ignored.
    1068             :  */
    1069             : static bool
    1070         140 : ProcessQueryResult(PGconn *conn, PGresult *result, const char *progname)
    1071             : {
    1072             :     /*
    1073             :      * If it's an error, report it.  Errors about a missing table are harmless
    1074             :      * so we continue processing; but die for other errors.
    1075             :      */
    1076         140 :     if (PQresultStatus(result) != PGRES_COMMAND_OK)
    1077             :     {
    1078           0 :         char       *sqlState = PQresultErrorField(result, PG_DIAG_SQLSTATE);
    1079             : 
    1080           0 :         pg_log_error("vacuuming of database \"%s\" failed: %s",
    1081             :                      PQdb(conn), PQerrorMessage(conn));
    1082             : 
    1083           0 :         if (sqlState && strcmp(sqlState, ERRCODE_UNDEFINED_TABLE) != 0)
    1084             :         {
    1085           0 :             PQclear(result);
    1086           0 :             return false;
    1087             :         }
    1088             :     }
    1089             : 
    1090         140 :     PQclear(result);
    1091         140 :     return true;
    1092             : }
    1093             : 
    1094             : /*
    1095             :  * GetQueryResult
    1096             :  *
    1097             :  * Pump the conn till it's dry of results; return false if any are errors.
    1098             :  * Note that this will block if the conn is busy.
    1099             :  */
    1100             : static bool
    1101           4 : GetQueryResult(PGconn *conn, const char *progname)
    1102             : {
    1103           4 :     bool        ok = true;
    1104             :     PGresult   *result;
    1105             : 
    1106           4 :     SetCancelConn(conn);
    1107          12 :     while ((result = PQgetResult(conn)) != NULL)
    1108             :     {
    1109           4 :         if (!ProcessQueryResult(conn, result, progname))
    1110           0 :             ok = false;
    1111             :     }
    1112           4 :     ResetCancelConn();
    1113           4 :     return ok;
    1114             : }
    1115             : 
    1116             : /*
    1117             :  * DisconnectDatabase
    1118             :  *      Disconnect the connection associated with the given slot
    1119             :  */
    1120             : static void
    1121         110 : DisconnectDatabase(ParallelSlot *slot)
    1122             : {
    1123             :     char        errbuf[256];
    1124             : 
    1125         110 :     if (!slot->connection)
    1126           0 :         return;
    1127             : 
    1128         110 :     if (PQtransactionStatus(slot->connection) == PQTRANS_ACTIVE)
    1129             :     {
    1130             :         PGcancel   *cancel;
    1131             : 
    1132           0 :         if ((cancel = PQgetCancel(slot->connection)))
    1133             :         {
    1134           0 :             (void) PQcancel(cancel, errbuf, sizeof(errbuf));
    1135           0 :             PQfreeCancel(cancel);
    1136             :         }
    1137             :     }
    1138             : 
    1139         110 :     PQfinish(slot->connection);
    1140         110 :     slot->connection = NULL;
    1141             : }
    1142             : 
    1143             : /*
    1144             :  * Loop on select() until a descriptor from the given set becomes readable.
    1145             :  *
    1146             :  * If we get a cancel request while we're waiting, we forego all further
    1147             :  * processing and set the *aborting flag to true.  The return value must be
    1148             :  * ignored in this case.  Otherwise, *aborting is set to false.
    1149             :  */
    1150             : static int
    1151         136 : select_loop(int maxFd, fd_set *workerset, bool *aborting)
    1152             : {
    1153             :     int         i;
    1154         136 :     fd_set      saveSet = *workerset;
    1155             : 
    1156         136 :     if (CancelRequested)
    1157             :     {
    1158           0 :         *aborting = true;
    1159           0 :         return -1;
    1160             :     }
    1161             :     else
    1162         136 :         *aborting = false;
    1163             : 
    1164             :     for (;;)
    1165           0 :     {
    1166             :         /*
    1167             :          * On Windows, we need to check once in a while for cancel requests;
    1168             :          * on other platforms we rely on select() returning when interrupted.
    1169             :          */
    1170             :         struct timeval *tvp;
    1171             : #ifdef WIN32
    1172             :         struct timeval tv = {0, 1000000};
    1173             : 
    1174             :         tvp = &tv;
    1175             : #else
    1176         136 :         tvp = NULL;
    1177             : #endif
    1178             : 
    1179         136 :         *workerset = saveSet;
    1180         136 :         i = select(maxFd + 1, workerset, NULL, NULL, tvp);
    1181             : 
    1182             : #ifdef WIN32
    1183             :         if (i == SOCKET_ERROR)
    1184             :         {
    1185             :             i = -1;
    1186             : 
    1187             :             if (WSAGetLastError() == WSAEINTR)
    1188             :                 errno = EINTR;
    1189             :         }
    1190             : #endif
    1191             : 
    1192         136 :         if (i < 0 && errno == EINTR)
    1193           0 :             continue;           /* ignore this */
    1194         136 :         if (i < 0 || CancelRequested)
    1195           0 :             *aborting = true;   /* but not this */
    1196         136 :         if (i == 0)
    1197           0 :             continue;           /* timeout (Win32 only) */
    1198         136 :         break;
    1199             :     }
    1200             : 
    1201         136 :     return i;
    1202             : }
    1203             : 
    1204             : static void
    1205         114 : init_slot(ParallelSlot *slot, PGconn *conn)
    1206             : {
    1207         114 :     slot->connection = conn;
    1208             :     /* Initially assume connection is idle */
    1209         114 :     slot->isFree = true;
    1210         114 : }
    1211             : 
    1212             : static void
    1213           2 : help(const char *progname)
    1214             : {
    1215           2 :     printf(_("%s cleans and analyzes a PostgreSQL database.\n\n"), progname);
    1216           2 :     printf(_("Usage:\n"));
    1217           2 :     printf(_("  %s [OPTION]... [DBNAME]\n"), progname);
    1218           2 :     printf(_("\nOptions:\n"));
    1219           2 :     printf(_("  -a, --all                       vacuum all databases\n"));
    1220           2 :     printf(_("  -d, --dbname=DBNAME             database to vacuum\n"));
    1221           2 :     printf(_("      --disable-page-skipping     disable all page-skipping behavior\n"));
    1222           2 :     printf(_("  -e, --echo                      show the commands being sent to the server\n"));
    1223           2 :     printf(_("  -f, --full                      do full vacuuming\n"));
    1224           2 :     printf(_("  -F, --freeze                    freeze row transaction information\n"));
    1225           2 :     printf(_("  -j, --jobs=NUM                  use this many concurrent connections to vacuum\n"));
    1226           2 :     printf(_("      --min-mxid-age=MXID_AGE     minimum multixact ID age of tables to vacuum\n"));
    1227           2 :     printf(_("      --min-xid-age=XID_AGE       minimum transaction ID age of tables to vacuum\n"));
    1228           2 :     printf(_("  -q, --quiet                     don't write any messages\n"));
    1229           2 :     printf(_("      --skip-locked               skip relations that cannot be immediately locked\n"));
    1230           2 :     printf(_("  -t, --table='TABLE[(COLUMNS)]'  vacuum specific table(s) only\n"));
    1231           2 :     printf(_("  -v, --verbose                   write a lot of output\n"));
    1232           2 :     printf(_("  -V, --version                   output version information, then exit\n"));
    1233           2 :     printf(_("  -z, --analyze                   update optimizer statistics\n"));
    1234           2 :     printf(_("  -Z, --analyze-only              only update optimizer statistics; no vacuum\n"));
    1235           2 :     printf(_("      --analyze-in-stages         only update optimizer statistics, in multiple\n"
    1236             :              "                                  stages for faster results; no vacuum\n"));
    1237           2 :     printf(_("  -?, --help                      show this help, then exit\n"));
    1238           2 :     printf(_("\nConnection options:\n"));
    1239           2 :     printf(_("  -h, --host=HOSTNAME       database server host or socket directory\n"));
    1240           2 :     printf(_("  -p, --port=PORT           database server port\n"));
    1241           2 :     printf(_("  -U, --username=USERNAME   user name to connect as\n"));
    1242           2 :     printf(_("  -w, --no-password         never prompt for password\n"));
    1243           2 :     printf(_("  -W, --password            force password prompt\n"));
    1244           2 :     printf(_("  --maintenance-db=DBNAME   alternate maintenance database\n"));
    1245           2 :     printf(_("\nRead the description of the SQL command VACUUM for details.\n"));
    1246           2 :     printf(_("\nReport bugs to <pgsql-bugs@lists.postgresql.org>.\n"));
    1247           2 : }

Generated by: LCOV version 1.13