PostgreSQL Source Code  git master
reindexdb.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * reindexdb
4  *
5  * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
6  *
7  * src/bin/scripts/reindexdb.c
8  *
9  *-------------------------------------------------------------------------
10  */
11 
12 #include "postgres_fe.h"
13 
14 #include "catalog/pg_class_d.h"
15 #include "common.h"
16 #include "common/connect.h"
17 #include "common/logging.h"
18 #include "fe_utils/cancel.h"
19 #include "fe_utils/option_utils.h"
20 #include "fe_utils/parallel_slot.h"
21 #include "fe_utils/query_utils.h"
22 #include "fe_utils/simple_list.h"
23 #include "fe_utils/string_utils.h"
24 
25 typedef enum ReindexType
26 {
32 } ReindexType;
33 
34 
37  SimpleStringList *user_list,
38  bool echo);
39 static void reindex_one_database(const ConnParams *cparams, ReindexType type,
40  SimpleStringList *user_list,
41  const char *progname,
42  bool echo, bool verbose, bool concurrently,
43  int concurrentCons, const char *tablespace);
44 static void reindex_all_databases(ConnParams *cparams,
45  const char *progname, bool echo,
46  bool quiet, bool verbose, bool concurrently,
47  int concurrentCons, const char *tablespace);
49  const char *name, bool echo, bool verbose,
50  bool concurrently, bool async,
51  const char *tablespace);
52 
53 static void help(const char *progname);
54 
55 int
56 main(int argc, char *argv[])
57 {
58  static struct option long_options[] = {
59  {"host", required_argument, NULL, 'h'},
60  {"port", required_argument, NULL, 'p'},
61  {"username", required_argument, NULL, 'U'},
62  {"no-password", no_argument, NULL, 'w'},
63  {"password", no_argument, NULL, 'W'},
64  {"echo", no_argument, NULL, 'e'},
65  {"quiet", no_argument, NULL, 'q'},
66  {"schema", required_argument, NULL, 'S'},
67  {"dbname", required_argument, NULL, 'd'},
68  {"all", no_argument, NULL, 'a'},
69  {"system", no_argument, NULL, 's'},
70  {"table", required_argument, NULL, 't'},
71  {"index", required_argument, NULL, 'i'},
72  {"jobs", required_argument, NULL, 'j'},
73  {"verbose", no_argument, NULL, 'v'},
74  {"concurrently", no_argument, NULL, 1},
75  {"maintenance-db", required_argument, NULL, 2},
76  {"tablespace", required_argument, NULL, 3},
77  {NULL, 0, NULL, 0}
78  };
79 
80  const char *progname;
81  int optindex;
82  int c;
83 
84  const char *dbname = NULL;
85  const char *maintenance_db = NULL;
86  const char *host = NULL;
87  const char *port = NULL;
88  const char *username = NULL;
89  const char *tablespace = NULL;
90  enum trivalue prompt_password = TRI_DEFAULT;
91  ConnParams cparams;
92  bool syscatalog = false;
93  bool alldb = false;
94  bool echo = false;
95  bool quiet = false;
96  bool verbose = false;
97  bool concurrently = false;
98  SimpleStringList indexes = {NULL, NULL};
99  SimpleStringList tables = {NULL, NULL};
100  SimpleStringList schemas = {NULL, NULL};
101  int concurrentCons = 1;
102 
103  pg_logging_init(argv[0]);
104  progname = get_progname(argv[0]);
105  set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pgscripts"));
106 
107  handle_help_version_opts(argc, argv, "reindexdb", help);
108 
109  /* process command-line options */
110  while ((c = getopt_long(argc, argv, "h:p:U:wWeqS:d:ast:i:j:v", long_options, &optindex)) != -1)
111  {
112  switch (c)
113  {
114  case 'h':
115  host = pg_strdup(optarg);
116  break;
117  case 'p':
118  port = pg_strdup(optarg);
119  break;
120  case 'U':
121  username = pg_strdup(optarg);
122  break;
123  case 'w':
124  prompt_password = TRI_NO;
125  break;
126  case 'W':
127  prompt_password = TRI_YES;
128  break;
129  case 'e':
130  echo = true;
131  break;
132  case 'q':
133  quiet = true;
134  break;
135  case 'S':
137  break;
138  case 'd':
139  dbname = pg_strdup(optarg);
140  break;
141  case 'a':
142  alldb = true;
143  break;
144  case 's':
145  syscatalog = true;
146  break;
147  case 't':
149  break;
150  case 'i':
152  break;
153  case 'j':
154  concurrentCons = atoi(optarg);
155  if (concurrentCons <= 0)
156  {
157  pg_log_error("number of parallel jobs must be at least 1");
158  exit(1);
159  }
160  break;
161  case 'v':
162  verbose = true;
163  break;
164  case 1:
165  concurrently = true;
166  break;
167  case 2:
168  maintenance_db = pg_strdup(optarg);
169  break;
170  case 3:
171  tablespace = pg_strdup(optarg);
172  break;
173  default:
174  fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
175  exit(1);
176  }
177  }
178 
179  /*
180  * Non-option argument specifies database name as long as it wasn't
181  * already specified with -d / --dbname
182  */
183  if (optind < argc && dbname == NULL)
184  {
185  dbname = argv[optind];
186  optind++;
187  }
188 
189  if (optind < argc)
190  {
191  pg_log_error("too many command-line arguments (first is \"%s\")",
192  argv[optind]);
193  fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
194  exit(1);
195  }
196 
197  /* fill cparams except for dbname, which is set below */
198  cparams.pghost = host;
199  cparams.pgport = port;
200  cparams.pguser = username;
201  cparams.prompt_password = prompt_password;
202  cparams.override_dbname = NULL;
203 
204  setup_cancel_handler(NULL);
205 
206  if (alldb)
207  {
208  if (dbname)
209  {
210  pg_log_error("cannot reindex all databases and a specific one at the same time");
211  exit(1);
212  }
213  if (syscatalog)
214  {
215  pg_log_error("cannot reindex all databases and system catalogs at the same time");
216  exit(1);
217  }
218  if (schemas.head != NULL)
219  {
220  pg_log_error("cannot reindex specific schema(s) in all databases");
221  exit(1);
222  }
223  if (tables.head != NULL)
224  {
225  pg_log_error("cannot reindex specific table(s) in all databases");
226  exit(1);
227  }
228  if (indexes.head != NULL)
229  {
230  pg_log_error("cannot reindex specific index(es) in all databases");
231  exit(1);
232  }
233 
234  cparams.dbname = maintenance_db;
235 
236  reindex_all_databases(&cparams, progname, echo, quiet, verbose,
237  concurrently, concurrentCons, tablespace);
238  }
239  else if (syscatalog)
240  {
241  if (schemas.head != NULL)
242  {
243  pg_log_error("cannot reindex specific schema(s) and system catalogs at the same time");
244  exit(1);
245  }
246  if (tables.head != NULL)
247  {
248  pg_log_error("cannot reindex specific table(s) and system catalogs at the same time");
249  exit(1);
250  }
251  if (indexes.head != NULL)
252  {
253  pg_log_error("cannot reindex specific index(es) and system catalogs at the same time");
254  exit(1);
255  }
256 
257  if (concurrentCons > 1)
258  {
259  pg_log_error("cannot use multiple jobs to reindex system catalogs");
260  exit(1);
261  }
262 
263  if (dbname == NULL)
264  {
265  if (getenv("PGDATABASE"))
266  dbname = getenv("PGDATABASE");
267  else if (getenv("PGUSER"))
268  dbname = getenv("PGUSER");
269  else
270  dbname = get_user_name_or_exit(progname);
271  }
272 
273  cparams.dbname = dbname;
274 
275  reindex_one_database(&cparams, REINDEX_SYSTEM, NULL,
276  progname, echo, verbose,
277  concurrently, 1, tablespace);
278  }
279  else
280  {
281  /*
282  * Index-level REINDEX is not supported with multiple jobs as we
283  * cannot control the concurrent processing of multiple indexes
284  * depending on the same relation.
285  */
286  if (concurrentCons > 1 && indexes.head != NULL)
287  {
288  pg_log_error("cannot use multiple jobs to reindex indexes");
289  exit(1);
290  }
291 
292  if (dbname == NULL)
293  {
294  if (getenv("PGDATABASE"))
295  dbname = getenv("PGDATABASE");
296  else if (getenv("PGUSER"))
297  dbname = getenv("PGUSER");
298  else
299  dbname = get_user_name_or_exit(progname);
300  }
301 
302  cparams.dbname = dbname;
303 
304  if (schemas.head != NULL)
305  reindex_one_database(&cparams, REINDEX_SCHEMA, &schemas,
306  progname, echo, verbose,
307  concurrently, concurrentCons, tablespace);
308 
309  if (indexes.head != NULL)
310  reindex_one_database(&cparams, REINDEX_INDEX, &indexes,
311  progname, echo, verbose,
312  concurrently, 1, tablespace);
313 
314  if (tables.head != NULL)
315  reindex_one_database(&cparams, REINDEX_TABLE, &tables,
316  progname, echo, verbose,
317  concurrently, concurrentCons, tablespace);
318 
319  /*
320  * reindex database only if neither index nor table nor schema is
321  * specified
322  */
323  if (indexes.head == NULL && tables.head == NULL && schemas.head == NULL)
324  reindex_one_database(&cparams, REINDEX_DATABASE, NULL,
325  progname, echo, verbose,
326  concurrently, concurrentCons, tablespace);
327  }
328 
329  exit(0);
330 }
331 
332 static void
334  SimpleStringList *user_list,
335  const char *progname, bool echo,
336  bool verbose, bool concurrently, int concurrentCons,
337  const char *tablespace)
338 {
339  PGconn *conn;
340  SimpleStringListCell *cell;
341  bool parallel = concurrentCons > 1;
342  SimpleStringList *process_list = user_list;
343  ReindexType process_type = type;
344  ParallelSlot *slots;
345  bool failed = false;
346  int items_count = 0;
347 
348  conn = connectDatabase(cparams, progname, echo, false, false);
349 
350  if (concurrently && PQserverVersion(conn) < 120000)
351  {
352  PQfinish(conn);
353  pg_log_error("cannot use the \"%s\" option on server versions older than PostgreSQL %s",
354  "concurrently", "12");
355  exit(1);
356  }
357 
358  if (tablespace && PQserverVersion(conn) < 140000)
359  {
360  PQfinish(conn);
361  pg_log_error("cannot use the \"%s\" option on server versions older than PostgreSQL %s",
362  "tablespace", "14");
363  exit(1);
364  }
365 
366  if (!parallel)
367  {
368  switch (process_type)
369  {
370  case REINDEX_DATABASE:
371  case REINDEX_SYSTEM:
372 
373  /*
374  * Database and system reindexes only need to work on the
375  * database itself, so build a list with a single entry.
376  */
377  Assert(user_list == NULL);
378  process_list = pg_malloc0(sizeof(SimpleStringList));
379  simple_string_list_append(process_list, PQdb(conn));
380  break;
381 
382  case REINDEX_INDEX:
383  case REINDEX_SCHEMA:
384  case REINDEX_TABLE:
385  Assert(user_list != NULL);
386  break;
387  }
388  }
389  else
390  {
391  switch (process_type)
392  {
393  case REINDEX_DATABASE:
394 
395  /*
396  * Database-wide parallel reindex requires special processing.
397  * If multiple jobs were asked, we have to reindex system
398  * catalogs first as they cannot be processed in parallel.
399  */
400  if (concurrently)
401  pg_log_warning("cannot reindex system catalogs concurrently, skipping all");
402  else
403  run_reindex_command(conn, REINDEX_SYSTEM, PQdb(conn), echo,
404  verbose, concurrently, false,
405  tablespace);
406 
407  /* Build a list of relations from the database */
408  process_list = get_parallel_object_list(conn, process_type,
409  user_list, echo);
410  process_type = REINDEX_TABLE;
411 
412  /* Bail out if nothing to process */
413  if (process_list == NULL)
414  return;
415  break;
416 
417  case REINDEX_SCHEMA:
418  Assert(user_list != NULL);
419 
420  /* Build a list of relations from all the schemas */
421  process_list = get_parallel_object_list(conn, process_type,
422  user_list, echo);
423  process_type = REINDEX_TABLE;
424 
425  /* Bail out if nothing to process */
426  if (process_list == NULL)
427  return;
428  break;
429 
430  case REINDEX_SYSTEM:
431  case REINDEX_INDEX:
432  /* not supported */
433  Assert(false);
434  break;
435 
436  case REINDEX_TABLE:
437 
438  /*
439  * Fall through. The list of items for tables is already
440  * created.
441  */
442  break;
443  }
444  }
445 
446  /*
447  * Adjust the number of concurrent connections depending on the items in
448  * the list. We choose the minimum between the number of concurrent
449  * connections and the number of items in the list.
450  */
451  for (cell = process_list->head; cell; cell = cell->next)
452  {
453  items_count++;
454 
455  /* no need to continue if there are more elements than jobs */
456  if (items_count >= concurrentCons)
457  break;
458  }
459  concurrentCons = Min(concurrentCons, items_count);
460  Assert(concurrentCons > 0);
461 
462  Assert(process_list != NULL);
463 
464  slots = ParallelSlotsSetup(cparams, progname, echo, conn, concurrentCons);
465 
466  cell = process_list->head;
467  do
468  {
469  const char *objname = cell->val;
470  ParallelSlot *free_slot = NULL;
471 
472  if (CancelRequested)
473  {
474  failed = true;
475  goto finish;
476  }
477 
478  free_slot = ParallelSlotsGetIdle(slots, concurrentCons);
479  if (!free_slot)
480  {
481  failed = true;
482  goto finish;
483  }
484 
486  run_reindex_command(free_slot->connection, process_type, objname,
487  echo, verbose, concurrently, true, tablespace);
488 
489  cell = cell->next;
490  } while (cell != NULL);
491 
492  if (!ParallelSlotsWaitCompletion(slots, concurrentCons))
493  failed = true;
494 
495 finish:
496  if (process_list != user_list)
497  {
498  simple_string_list_destroy(process_list);
499  pg_free(process_list);
500  }
501 
502  ParallelSlotsTerminate(slots, concurrentCons);
503  pfree(slots);
504 
505  if (failed)
506  exit(1);
507 }
508 
509 static void
511  bool echo, bool verbose, bool concurrently, bool async,
512  const char *tablespace)
513 {
514  const char *paren = "(";
515  const char *comma = ", ";
516  const char *sep = paren;
517  PQExpBufferData sql;
518  bool status;
519 
520  Assert(name);
521 
522  /* build the REINDEX query */
523  initPQExpBuffer(&sql);
524 
525  appendPQExpBufferStr(&sql, "REINDEX ");
526 
527  if (verbose)
528  {
529  appendPQExpBuffer(&sql, "%sVERBOSE", sep);
530  sep = comma;
531  }
532 
533  if (tablespace)
534  {
535  appendPQExpBuffer(&sql, "%sTABLESPACE %s", sep, fmtId(tablespace));
536  sep = comma;
537  }
538 
539  if (sep != paren)
540  appendPQExpBufferStr(&sql, ") ");
541 
542  /* object type */
543  switch (type)
544  {
545  case REINDEX_DATABASE:
546  appendPQExpBufferStr(&sql, "DATABASE ");
547  break;
548  case REINDEX_INDEX:
549  appendPQExpBufferStr(&sql, "INDEX ");
550  break;
551  case REINDEX_SCHEMA:
552  appendPQExpBufferStr(&sql, "SCHEMA ");
553  break;
554  case REINDEX_SYSTEM:
555  appendPQExpBufferStr(&sql, "SYSTEM ");
556  break;
557  case REINDEX_TABLE:
558  appendPQExpBufferStr(&sql, "TABLE ");
559  break;
560  }
561 
562  /*
563  * Parenthesized grammar is only supported for CONCURRENTLY since
564  * PostgreSQL 14. Since 12, CONCURRENTLY can be specified after the
565  * object type.
566  */
567  if (concurrently)
568  appendPQExpBufferStr(&sql, "CONCURRENTLY ");
569 
570  /* object name */
571  switch (type)
572  {
573  case REINDEX_DATABASE:
574  case REINDEX_SYSTEM:
575  appendPQExpBufferStr(&sql, fmtId(name));
576  break;
577  case REINDEX_INDEX:
578  case REINDEX_TABLE:
579  appendQualifiedRelation(&sql, name, conn, echo);
580  break;
581  case REINDEX_SCHEMA:
582  appendPQExpBufferStr(&sql, name);
583  break;
584  }
585 
586  /* finish the query */
587  appendPQExpBufferChar(&sql, ';');
588 
589  if (async)
590  {
591  if (echo)
592  printf("%s\n", sql.data);
593 
594  status = PQsendQuery(conn, sql.data) == 1;
595  }
596  else
597  status = executeMaintenanceCommand(conn, sql.data, echo);
598 
599  if (!status)
600  {
601  switch (type)
602  {
603  case REINDEX_DATABASE:
604  pg_log_error("reindexing of database \"%s\" failed: %s",
605  PQdb(conn), PQerrorMessage(conn));
606  break;
607  case REINDEX_INDEX:
608  pg_log_error("reindexing of index \"%s\" in database \"%s\" failed: %s",
609  name, PQdb(conn), PQerrorMessage(conn));
610  break;
611  case REINDEX_SCHEMA:
612  pg_log_error("reindexing of schema \"%s\" in database \"%s\" failed: %s",
613  name, PQdb(conn), PQerrorMessage(conn));
614  break;
615  case REINDEX_SYSTEM:
616  pg_log_error("reindexing of system catalogs in database \"%s\" failed: %s",
617  PQdb(conn), PQerrorMessage(conn));
618  break;
619  case REINDEX_TABLE:
620  pg_log_error("reindexing of table \"%s\" in database \"%s\" failed: %s",
621  name, PQdb(conn), PQerrorMessage(conn));
622  break;
623  }
624  if (!async)
625  {
626  PQfinish(conn);
627  exit(1);
628  }
629  }
630 
631  termPQExpBuffer(&sql);
632 }
633 
634 /*
635  * Prepare the list of objects to process by querying the catalogs.
636  *
637  * This function will return a SimpleStringList object containing the entire
638  * list of tables in the given database that should be processed by a parallel
639  * database-wide reindex (excluding system tables), or NULL if there's no such
640  * table.
641  */
642 static SimpleStringList *
644  SimpleStringList *user_list, bool echo)
645 {
646  PQExpBufferData catalog_query;
648  PGresult *res;
649  SimpleStringList *tables;
650  int ntups,
651  i;
652 
653  initPQExpBuffer(&catalog_query);
654 
655  /*
656  * The queries here are using a safe search_path, so there's no need to
657  * fully qualify everything.
658  */
659  switch (type)
660  {
661  case REINDEX_DATABASE:
662  Assert(user_list == NULL);
663  appendPQExpBufferStr(&catalog_query,
664  "SELECT c.relname, ns.nspname\n"
665  " FROM pg_catalog.pg_class c\n"
666  " JOIN pg_catalog.pg_namespace ns"
667  " ON c.relnamespace = ns.oid\n"
668  " WHERE ns.nspname != 'pg_catalog'\n"
669  " AND c.relkind IN ("
670  CppAsString2(RELKIND_RELATION) ", "
671  CppAsString2(RELKIND_MATVIEW) ")\n"
672  " ORDER BY c.relpages DESC;");
673  break;
674 
675  case REINDEX_SCHEMA:
676  {
677  SimpleStringListCell *cell;
678  bool nsp_listed = false;
679 
680  Assert(user_list != NULL);
681 
682  /*
683  * All the tables from all the listed schemas are grabbed at
684  * once.
685  */
686  appendPQExpBufferStr(&catalog_query,
687  "SELECT c.relname, ns.nspname\n"
688  " FROM pg_catalog.pg_class c\n"
689  " JOIN pg_catalog.pg_namespace ns"
690  " ON c.relnamespace = ns.oid\n"
691  " WHERE c.relkind IN ("
692  CppAsString2(RELKIND_RELATION) ", "
693  CppAsString2(RELKIND_MATVIEW) ")\n"
694  " AND ns.nspname IN (");
695 
696  for (cell = user_list->head; cell; cell = cell->next)
697  {
698  const char *nspname = cell->val;
699 
700  if (nsp_listed)
701  appendPQExpBufferStr(&catalog_query, ", ");
702  else
703  nsp_listed = true;
704 
705  appendStringLiteralConn(&catalog_query, nspname, conn);
706  }
707 
708  appendPQExpBufferStr(&catalog_query, ")\n"
709  " ORDER BY c.relpages DESC;");
710  }
711  break;
712 
713  case REINDEX_SYSTEM:
714  case REINDEX_INDEX:
715  case REINDEX_TABLE:
716  Assert(false);
717  break;
718  }
719 
720  res = executeQuery(conn, catalog_query.data, echo);
721  termPQExpBuffer(&catalog_query);
722 
723  /*
724  * If no rows are returned, there are no matching tables, so we are done.
725  */
726  ntups = PQntuples(res);
727  if (ntups == 0)
728  {
729  PQclear(res);
730  PQfinish(conn);
731  return NULL;
732  }
733 
734  tables = pg_malloc0(sizeof(SimpleStringList));
735 
736  /* Build qualified identifiers for each table */
737  initPQExpBuffer(&buf);
738  for (i = 0; i < ntups; i++)
739  {
741  fmtQualifiedId(PQgetvalue(res, i, 1),
742  PQgetvalue(res, i, 0)));
743 
744  simple_string_list_append(tables, buf.data);
745  resetPQExpBuffer(&buf);
746  }
747  termPQExpBuffer(&buf);
748  PQclear(res);
749 
750  return tables;
751 }
752 
753 static void
755  const char *progname, bool echo, bool quiet, bool verbose,
756  bool concurrently, int concurrentCons,
757  const char *tablespace)
758 {
759  PGconn *conn;
760  PGresult *result;
761  int i;
762 
763  conn = connectMaintenanceDatabase(cparams, progname, echo);
764  result = executeQuery(conn, "SELECT datname FROM pg_database WHERE datallowconn ORDER BY 1;", echo);
765  PQfinish(conn);
766 
767  for (i = 0; i < PQntuples(result); i++)
768  {
769  char *dbname = PQgetvalue(result, i, 0);
770 
771  if (!quiet)
772  {
773  printf(_("%s: reindexing database \"%s\"\n"), progname, dbname);
774  fflush(stdout);
775  }
776 
777  cparams->override_dbname = dbname;
778 
779  reindex_one_database(cparams, REINDEX_DATABASE, NULL,
780  progname, echo, verbose, concurrently,
781  concurrentCons, tablespace);
782  }
783 
784  PQclear(result);
785 }
786 
787 static void
788 help(const char *progname)
789 {
790  printf(_("%s reindexes a PostgreSQL database.\n\n"), progname);
791  printf(_("Usage:\n"));
792  printf(_(" %s [OPTION]... [DBNAME]\n"), progname);
793  printf(_("\nOptions:\n"));
794  printf(_(" -a, --all reindex all databases\n"));
795  printf(_(" --concurrently reindex concurrently\n"));
796  printf(_(" -d, --dbname=DBNAME database to reindex\n"));
797  printf(_(" -e, --echo show the commands being sent to the server\n"));
798  printf(_(" -i, --index=INDEX recreate specific index(es) only\n"));
799  printf(_(" -j, --jobs=NUM use this many concurrent connections to reindex\n"));
800  printf(_(" -q, --quiet don't write any messages\n"));
801  printf(_(" -s, --system reindex system catalogs\n"));
802  printf(_(" -S, --schema=SCHEMA reindex specific schema(s) only\n"));
803  printf(_(" -t, --table=TABLE reindex specific table(s) only\n"));
804  printf(_(" --tablespace=TABLESPACE tablespace where indexes are rebuilt\n"));
805  printf(_(" -v, --verbose write a lot of output\n"));
806  printf(_(" -V, --version output version information, then exit\n"));
807  printf(_(" -?, --help show this help, then exit\n"));
808  printf(_("\nConnection options:\n"));
809  printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
810  printf(_(" -p, --port=PORT database server port\n"));
811  printf(_(" -U, --username=USERNAME user name to connect as\n"));
812  printf(_(" -w, --no-password never prompt for password\n"));
813  printf(_(" -W, --password force password prompt\n"));
814  printf(_(" --maintenance-db=DBNAME alternate maintenance database\n"));
815  printf(_("\nRead the description of the SQL command REINDEX for details.\n"));
816  printf(_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
817  printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
818 }
static PGresult * executeQuery(PGconn *conn, const char *query)
Definition: pg_dumpall.c:1874
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:6705
const char * progname
Definition: main.c:46
static void run_reindex_command(PGconn *conn, ReindexType type, const char *name, bool echo, bool verbose, bool concurrently, bool async, const char *tablespace)
Definition: reindexdb.c:510
char * pgport
Definition: pg_backup.h:66
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3026
const char * fmtId(const char *rawid)
Definition: string_utils.c:64
const char * get_progname(const char *argv0)
Definition: path.c:453
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:131
#define pg_log_error(...)
Definition: logging.h:80
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
Definition: getopt_long.c:57
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:369
void pg_logging_init(const char *argv0)
Definition: logging.c:81
#define Min(x, y)
Definition: c.h:986
void simple_string_list_destroy(SimpleStringList *list)
Definition: simple_list.c:125
void PQfinish(PGconn *conn)
Definition: fe-connect.c:4203
static void ParallelSlotSetHandler(ParallelSlot *slot, ParallelSlotResultHandler handler, void *context)
Definition: parallel_slot.h:37
#define printf(...)
Definition: port.h:222
static void setup_cancel_handler(void)
Definition: parallel.c:613
int PQserverVersion(const PGconn *conn)
Definition: fe-connect.c:6695
int PQntuples(const PGresult *res)
Definition: fe-exec.c:2632
#define fprintf
Definition: port.h:220
static void help(const char *progname)
Definition: reindexdb.c:788
char * dbname
Definition: pg_backup.h:65
int PQsendQuery(PGconn *conn, const char *query)
Definition: fe-exec.c:1198
#define required_argument
Definition: getopt_long.h:25
void pfree(void *pointer)
Definition: mcxt.c:1057
ParallelSlot * ParallelSlotsSetup(const ConnParams *cparams, const char *progname, bool echo, PGconn *conn, int numslots)
int optind
Definition: getopt.c:50
void handle_help_version_opts(int argc, char *argv[], const char *fixed_progname, help_handler hlp)
Definition: option_utils.c:22
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
PGconn * conn
Definition: streamutil.c:54
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:267
char * c
static char * buf
Definition: pg_test_fsync.c:68
char * tablespace
Definition: pgbench.c:190
struct SimpleStringListCell * next
Definition: simple_list.h:34
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
PGconn * connection
Definition: parallel_slot.h:23
const char * username
Definition: pgbench.c:246
char * override_dbname
Definition: pg_backup.h:72
static int port
Definition: pg_regress.c:92
char * pghost
Definition: pg_backup.h:67
enum trivalue prompt_password
Definition: connect_utils.h:32
static int verbose
trivalue
Definition: vacuumlo.c:34
#define CppAsString2(x)
Definition: c.h:289
#define no_argument
Definition: getopt_long.h:24
#define PG_TEXTDOMAIN(domain)
Definition: c.h:1215
void simple_string_list_append(SimpleStringList *list, const char *val)
Definition: simple_list.c:63
PGconn * connectMaintenanceDatabase(ConnParams *cparams, const char *progname, bool echo)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:380
void PQclear(PGresult *res)
Definition: fe-exec.c:676
bool ParallelSlotsWaitCompletion(ParallelSlot *slots, int numslots)
char * PQdb(const PGconn *conn)
Definition: fe-connect.c:6555
#define Assert(condition)
Definition: c.h:804
static PGconn * connectDatabase(const char *dbname, const char *connstr, const char *pghost, const char *pgport, const char *pguser, trivalue prompt_password, bool fail_on_error)
Definition: pg_dumpall.c:1636
SimpleStringListCell * head
Definition: simple_list.h:42
char * dbname
Definition: streamutil.c:51
const char * fmtQualifiedId(const char *schema, const char *id)
Definition: string_utils.c:145
void pg_free(void *ptr)
Definition: fe_memutils.c:105
const char * name
Definition: encode.c:515
void appendQualifiedRelation(PQExpBuffer buf, const char *spec, PGconn *conn, bool echo)
Definition: common.c:69
ParallelSlot * ParallelSlotsGetIdle(ParallelSlot *slots, int numslots)
void appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn)
Definition: string_utils.c:293
volatile sig_atomic_t CancelRequested
Definition: cancel.c:52
int main(int argc, char *argv[])
Definition: reindexdb.c:56
void set_pglocale_pgservice(const char *argv0, const char *app)
Definition: exec.c:433
bool executeMaintenanceCommand(PGconn *conn, const char *query, bool echo)
Definition: query_utils.c:74
char * optarg
Definition: getopt.c:52
static void reindex_all_databases(ConnParams *cparams, const char *progname, bool echo, bool quiet, bool verbose, bool concurrently, int concurrentCons, const char *tablespace)
Definition: reindexdb.c:754
int i
char val[FLEXIBLE_ARRAY_MEMBER]
Definition: simple_list.h:37
static SimpleStringList * get_parallel_object_list(PGconn *conn, ReindexType type, SimpleStringList *user_list, bool echo)
Definition: reindexdb.c:643
bool TableCommandResultHandler(PGresult *res, PGconn *conn, void *context)
#define pg_log_warning(...)
Definition: pgfnames.c:24
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:148
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:227
void ParallelSlotsTerminate(ParallelSlot *slots, int numslots)
#define _(x)
Definition: elog.c:89
ReindexType
Definition: reindexdb.c:25
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:92
const char * pguser
Definition: connect_utils.h:31
const char * get_user_name_or_exit(const char *progname)
Definition: username.c:74
static void reindex_one_database(const ConnParams *cparams, ReindexType type, SimpleStringList *user_list, const char *progname, bool echo, bool verbose, bool concurrently, int concurrentCons, const char *tablespace)
Definition: reindexdb.c:333