PostgreSQL Source Code git master
pg_dumpall.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * pg_dumpall.c
4 *
5 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
6 * Portions Copyright (c) 1994, Regents of the University of California
7 *
8 * pg_dumpall forces all pg_dump output to be text, since it also outputs
9 * text into the same output stream.
10 *
11 * src/bin/pg_dump/pg_dumpall.c
12 *
13 *-------------------------------------------------------------------------
14 */
15
16#include "postgres_fe.h"
17
18#include <time.h>
19#include <unistd.h>
20
21#include "catalog/pg_authid_d.h"
22#include "common/connect.h"
23#include "common/file_perm.h"
24#include "common/file_utils.h"
26#include "common/logging.h"
27#include "common/string.h"
28#include "connectdb.h"
29#include "dumputils.h"
31#include "filter.h"
32#include "getopt_long.h"
33
34/* version string we expect back from pg_dump */
35#define PGDUMP_VERSIONSTR "pg_dump (PostgreSQL) " PG_VERSION "\n"
36
37typedef struct
38{
41 char *rolename;
43
44#define SH_PREFIX rolename
45#define SH_ELEMENT_TYPE RoleNameEntry
46#define SH_KEY_TYPE char *
47#define SH_KEY rolename
48#define SH_HASH_KEY(tb, key) hash_string(key)
49#define SH_EQUAL(tb, a, b) (strcmp(a, b) == 0)
50#define SH_STORE_HASH
51#define SH_GET_HASH(tb, a) (a)->hashval
52#define SH_SCOPE static inline
53#define SH_RAW_ALLOCATOR pg_malloc0
54#define SH_DECLARE
55#define SH_DEFINE
56#include "lib/simplehash.h"
57
58static void help(void);
59
60static void dropRoles(PGconn *conn);
61static void dumpRoles(PGconn *conn);
62static void dumpRoleMembership(PGconn *conn);
63static void dumpRoleGUCPrivs(PGconn *conn);
64static void dropTablespaces(PGconn *conn);
65static void dumpTablespaces(PGconn *conn);
66static void dropDBs(PGconn *conn);
67static void dumpUserConfig(PGconn *conn, const char *username);
68static void dumpDatabases(PGconn *conn);
69static void dumpTimestamp(const char *msg);
70static int runPgDump(const char *dbname, const char *create_opts);
71static void buildShSecLabels(PGconn *conn,
72 const char *catalog_name, Oid objectId,
73 const char *objtype, const char *objname,
74 PQExpBuffer buffer);
75static void executeCommand(PGconn *conn, const char *query);
77 SimpleStringList *names);
78static void read_dumpall_filters(const char *filename, SimpleStringList *pattern);
79
82static const char *connstr = "";
83static bool output_clean = false;
84static bool skip_acls = false;
85static bool verbose = false;
86static bool dosync = true;
87
88static int binary_upgrade = 0;
89static int column_inserts = 0;
91static int disable_triggers = 0;
92static int if_exists = 0;
93static int inserts = 0;
95static int no_tablespaces = 0;
96static int use_setsessauth = 0;
97static int no_comments = 0;
98static int no_policies = 0;
99static int no_publications = 0;
100static int no_security_labels = 0;
101static int no_data = 0;
102static int no_schema = 0;
103static int no_statistics = 0;
104static int no_subscriptions = 0;
105static int no_toast_compression = 0;
107static int no_role_passwords = 0;
108static int with_statistics = 0;
109static int server_version;
112static int statistics_only = 0;
113static int sequence_data = 0;
114
115static char role_catalog[10];
116#define PG_AUTHID "pg_authid"
117#define PG_ROLES "pg_roles "
118
119static FILE *OPF;
120static char *filename = NULL;
121
124
125static char *restrict_key;
126
127int
128main(int argc, char *argv[])
129{
130 static struct option long_options[] = {
131 {"data-only", no_argument, NULL, 'a'},
132 {"clean", no_argument, NULL, 'c'},
133 {"encoding", required_argument, NULL, 'E'},
134 {"file", required_argument, NULL, 'f'},
135 {"globals-only", no_argument, NULL, 'g'},
136 {"host", required_argument, NULL, 'h'},
137 {"dbname", required_argument, NULL, 'd'},
138 {"database", required_argument, NULL, 'l'},
139 {"no-owner", no_argument, NULL, 'O'},
140 {"port", required_argument, NULL, 'p'},
141 {"roles-only", no_argument, NULL, 'r'},
142 {"schema-only", no_argument, NULL, 's'},
143 {"superuser", required_argument, NULL, 'S'},
144 {"tablespaces-only", no_argument, NULL, 't'},
145 {"username", required_argument, NULL, 'U'},
146 {"verbose", no_argument, NULL, 'v'},
147 {"no-password", no_argument, NULL, 'w'},
148 {"password", no_argument, NULL, 'W'},
149 {"no-privileges", no_argument, NULL, 'x'},
150 {"no-acl", no_argument, NULL, 'x'},
151
152 /*
153 * the following options don't have an equivalent short option letter
154 */
155 {"attribute-inserts", no_argument, &column_inserts, 1},
156 {"binary-upgrade", no_argument, &binary_upgrade, 1},
157 {"column-inserts", no_argument, &column_inserts, 1},
158 {"disable-dollar-quoting", no_argument, &disable_dollar_quoting, 1},
159 {"disable-triggers", no_argument, &disable_triggers, 1},
160 {"exclude-database", required_argument, NULL, 6},
161 {"extra-float-digits", required_argument, NULL, 5},
162 {"if-exists", no_argument, &if_exists, 1},
163 {"inserts", no_argument, &inserts, 1},
164 {"lock-wait-timeout", required_argument, NULL, 2},
165 {"no-table-access-method", no_argument, &no_table_access_method, 1},
166 {"no-tablespaces", no_argument, &no_tablespaces, 1},
167 {"quote-all-identifiers", no_argument, &quote_all_identifiers, 1},
168 {"load-via-partition-root", no_argument, &load_via_partition_root, 1},
169 {"role", required_argument, NULL, 3},
170 {"use-set-session-authorization", no_argument, &use_setsessauth, 1},
171 {"no-comments", no_argument, &no_comments, 1},
172 {"no-data", no_argument, &no_data, 1},
173 {"no-policies", no_argument, &no_policies, 1},
174 {"no-publications", no_argument, &no_publications, 1},
175 {"no-role-passwords", no_argument, &no_role_passwords, 1},
176 {"no-schema", no_argument, &no_schema, 1},
177 {"no-security-labels", no_argument, &no_security_labels, 1},
178 {"no-subscriptions", no_argument, &no_subscriptions, 1},
179 {"no-statistics", no_argument, &no_statistics, 1},
180 {"no-sync", no_argument, NULL, 4},
181 {"no-toast-compression", no_argument, &no_toast_compression, 1},
182 {"no-unlogged-table-data", no_argument, &no_unlogged_table_data, 1},
183 {"on-conflict-do-nothing", no_argument, &on_conflict_do_nothing, 1},
184 {"rows-per-insert", required_argument, NULL, 7},
185 {"statistics", no_argument, &with_statistics, 1},
186 {"statistics-only", no_argument, &statistics_only, 1},
187 {"filter", required_argument, NULL, 8},
188 {"sequence-data", no_argument, &sequence_data, 1},
189 {"restrict-key", required_argument, NULL, 9},
190
191 {NULL, 0, NULL, 0}
192 };
193
194 char *pghost = NULL;
195 char *pgport = NULL;
196 char *pguser = NULL;
197 char *pgdb = NULL;
198 char *use_role = NULL;
199 const char *dumpencoding = NULL;
200 trivalue prompt_password = TRI_DEFAULT;
201 bool data_only = false;
202 bool globals_only = false;
203 bool roles_only = false;
204 bool tablespaces_only = false;
205 PGconn *conn;
206 int encoding;
207 const char *std_strings;
208 int c,
209 ret;
210 int optindex;
211
212 pg_logging_init(argv[0]);
214 set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_dump"));
215 progname = get_progname(argv[0]);
216
217 if (argc > 1)
218 {
219 if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
220 {
221 help();
222 exit_nicely(0);
223 }
224 if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
225 {
226 puts("pg_dumpall (PostgreSQL) " PG_VERSION);
227 exit_nicely(0);
228 }
229 }
230
231 if ((ret = find_other_exec(argv[0], "pg_dump", PGDUMP_VERSIONSTR,
232 pg_dump_bin)) < 0)
233 {
234 char full_path[MAXPGPATH];
235
236 if (find_my_exec(argv[0], full_path) < 0)
237 strlcpy(full_path, progname, sizeof(full_path));
238
239 if (ret == -1)
240 pg_fatal("program \"%s\" is needed by %s but was not found in the same directory as \"%s\"",
241 "pg_dump", progname, full_path);
242 else
243 pg_fatal("program \"%s\" was found by \"%s\" but was not the same version as %s",
244 "pg_dump", full_path, progname);
245 }
246
248
249 while ((c = getopt_long(argc, argv, "acd:E:f:gh:l:Op:rsS:tU:vwWx", long_options, &optindex)) != -1)
250 {
251 switch (c)
252 {
253 case 'a':
254 data_only = true;
256 break;
257
258 case 'c':
259 output_clean = true;
260 break;
261
262 case 'd':
264 break;
265
266 case 'E':
267 dumpencoding = pg_strdup(optarg);
270 break;
271
272 case 'f':
276 break;
277
278 case 'g':
279 globals_only = true;
280 break;
281
282 case 'h':
284 break;
285
286 case 'l':
287 pgdb = pg_strdup(optarg);
288 break;
289
290 case 'O':
292 break;
293
294 case 'p':
296 break;
297
298 case 'r':
299 roles_only = true;
300 break;
301
302 case 's':
304 break;
305
306 case 'S':
309 break;
310
311 case 't':
312 tablespaces_only = true;
313 break;
314
315 case 'U':
316 pguser = pg_strdup(optarg);
317 break;
318
319 case 'v':
320 verbose = true;
323 break;
324
325 case 'w':
326 prompt_password = TRI_NO;
328 break;
329
330 case 'W':
331 prompt_password = TRI_YES;
333 break;
334
335 case 'x':
336 skip_acls = true;
338 break;
339
340 case 0:
341 break;
342
343 case 2:
344 appendPQExpBufferStr(pgdumpopts, " --lock-wait-timeout ");
346 break;
347
348 case 3:
349 use_role = pg_strdup(optarg);
350 appendPQExpBufferStr(pgdumpopts, " --role ");
351 appendShellString(pgdumpopts, use_role);
352 break;
353
354 case 4:
355 dosync = false;
356 appendPQExpBufferStr(pgdumpopts, " --no-sync");
357 break;
358
359 case 5:
360 appendPQExpBufferStr(pgdumpopts, " --extra-float-digits ");
362 break;
363
364 case 6:
366 break;
367
368 case 7:
369 appendPQExpBufferStr(pgdumpopts, " --rows-per-insert ");
371 break;
372
373 case 8:
375 break;
376
377 case 9:
379 appendPQExpBufferStr(pgdumpopts, " --restrict-key ");
381 break;
382
383 default:
384 /* getopt_long already emitted a complaint */
385 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
386 exit_nicely(1);
387 }
388 }
389
390 /* Complain if any arguments remain */
391 if (optind < argc)
392 {
393 pg_log_error("too many command-line arguments (first is \"%s\")",
394 argv[optind]);
395 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
396 exit_nicely(1);
397 }
398
399 if (database_exclude_patterns.head != NULL &&
400 (globals_only || roles_only || tablespaces_only))
401 {
402 pg_log_error("option %s cannot be used together with %s, %s, or %s",
403 "--exclude-database",
404 "-g/--globals-only", "-r/--roles-only", "-t/--tablespaces-only");
405 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
406 exit_nicely(1);
407 }
408
409 /* Make sure the user hasn't specified a mix of globals-only options */
410 if (globals_only && roles_only)
411 {
412 pg_log_error("options %s and %s cannot be used together",
413 "-g/--globals-only", "-r/--roles-only");
414 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
415 exit_nicely(1);
416 }
417
418 if (globals_only && tablespaces_only)
419 {
420 pg_log_error("options %s and %s cannot be used together",
421 "-g/--globals-only", "-t/--tablespaces-only");
422 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
423 exit_nicely(1);
424 }
425
426 if (if_exists && !output_clean)
427 pg_fatal("option %s requires option %s",
428 "--if-exists", "-c/--clean");
429
430 if (roles_only && tablespaces_only)
431 {
432 pg_log_error("options %s and %s cannot be used together",
433 "-r/--roles-only", "-t/--tablespaces-only");
434 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
435 exit_nicely(1);
436 }
437
438 /*
439 * If password values are not required in the dump, switch to using
440 * pg_roles which is equally useful, just more likely to have unrestricted
441 * access than pg_authid.
442 */
445 else
447
448 /* Add long options to the pg_dump argument list */
449 if (binary_upgrade)
450 appendPQExpBufferStr(pgdumpopts, " --binary-upgrade");
451 if (column_inserts)
452 appendPQExpBufferStr(pgdumpopts, " --column-inserts");
454 appendPQExpBufferStr(pgdumpopts, " --disable-dollar-quoting");
456 appendPQExpBufferStr(pgdumpopts, " --disable-triggers");
457 if (inserts)
458 appendPQExpBufferStr(pgdumpopts, " --inserts");
460 appendPQExpBufferStr(pgdumpopts, " --no-table-access-method");
461 if (no_tablespaces)
462 appendPQExpBufferStr(pgdumpopts, " --no-tablespaces");
464 appendPQExpBufferStr(pgdumpopts, " --quote-all-identifiers");
466 appendPQExpBufferStr(pgdumpopts, " --load-via-partition-root");
467 if (use_setsessauth)
468 appendPQExpBufferStr(pgdumpopts, " --use-set-session-authorization");
469 if (no_comments)
470 appendPQExpBufferStr(pgdumpopts, " --no-comments");
471 if (no_data)
472 appendPQExpBufferStr(pgdumpopts, " --no-data");
473 if (no_policies)
474 appendPQExpBufferStr(pgdumpopts, " --no-policies");
475 if (no_publications)
476 appendPQExpBufferStr(pgdumpopts, " --no-publications");
478 appendPQExpBufferStr(pgdumpopts, " --no-security-labels");
479 if (no_schema)
480 appendPQExpBufferStr(pgdumpopts, " --no-schema");
481 if (no_statistics)
482 appendPQExpBufferStr(pgdumpopts, " --no-statistics");
484 appendPQExpBufferStr(pgdumpopts, " --no-subscriptions");
486 appendPQExpBufferStr(pgdumpopts, " --no-toast-compression");
488 appendPQExpBufferStr(pgdumpopts, " --no-unlogged-table-data");
489 if (with_statistics)
490 appendPQExpBufferStr(pgdumpopts, " --statistics");
492 appendPQExpBufferStr(pgdumpopts, " --on-conflict-do-nothing");
493 if (statistics_only)
494 appendPQExpBufferStr(pgdumpopts, " --statistics-only");
495 if (sequence_data)
496 appendPQExpBufferStr(pgdumpopts, " --sequence-data");
497
498 /*
499 * If you don't provide a restrict key, one will be appointed for you.
500 */
501 if (!restrict_key)
503 if (!restrict_key)
504 pg_fatal("could not generate restrict key");
506 pg_fatal("invalid restrict key");
507
508 /*
509 * If there was a database specified on the command line, use that,
510 * otherwise try to connect to database "postgres", and failing that
511 * "template1".
512 */
513 if (pgdb)
514 {
515 conn = ConnectDatabase(pgdb, connstr, pghost, pgport, pguser,
516 prompt_password, false,
517 progname, &connstr, &server_version, NULL, NULL);
518
519 if (!conn)
520 pg_fatal("could not connect to database \"%s\"", pgdb);
521 }
522 else
523 {
524 conn = ConnectDatabase("postgres", connstr, pghost, pgport, pguser,
525 prompt_password, false,
526 progname, &connstr, &server_version, NULL, NULL);
527 if (!conn)
528 conn = ConnectDatabase("template1", connstr, pghost, pgport, pguser,
529 prompt_password, true,
530 progname, &connstr, &server_version, NULL, NULL);
531
532 if (!conn)
533 {
534 pg_log_error("could not connect to databases \"postgres\" or \"template1\"\n"
535 "Please specify an alternative database.");
536 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
537 exit_nicely(1);
538 }
539 }
540
541 /*
542 * Get a list of database names that match the exclude patterns
543 */
546
547 /*
548 * Open the output file if required, otherwise use stdout
549 */
550 if (filename)
551 {
552 OPF = fopen(filename, PG_BINARY_W);
553 if (!OPF)
554 pg_fatal("could not open output file \"%s\": %m",
555 filename);
556 }
557 else
558 OPF = stdout;
559
560 /*
561 * Set the client encoding if requested.
562 */
563 if (dumpencoding)
564 {
565 if (PQsetClientEncoding(conn, dumpencoding) < 0)
566 pg_fatal("invalid client encoding \"%s\" specified",
567 dumpencoding);
568 }
569
570 /*
571 * Get the active encoding and the standard_conforming_strings setting, so
572 * we know how to escape strings.
573 */
576 std_strings = PQparameterStatus(conn, "standard_conforming_strings");
577 if (!std_strings)
578 std_strings = "off";
579
580 /* Set the role if requested */
581 if (use_role)
582 {
584
585 appendPQExpBuffer(query, "SET ROLE %s", fmtId(use_role));
586 executeCommand(conn, query->data);
587 destroyPQExpBuffer(query);
588 }
589
590 /* Force quoting of all identifiers if requested. */
592 executeCommand(conn, "SET quote_all_identifiers = true");
593
594 fprintf(OPF, "--\n-- PostgreSQL database cluster dump\n--\n\n");
595 if (verbose)
596 dumpTimestamp("Started on");
597
598 /*
599 * Enter restricted mode to block any unexpected psql meta-commands. A
600 * malicious source might try to inject a variety of things via bogus
601 * responses to queries. While we cannot prevent such sources from
602 * affecting the destination at restore time, we can block psql
603 * meta-commands so that the client machine that runs psql with the dump
604 * output remains unaffected.
605 */
606 fprintf(OPF, "\\restrict %s\n\n", restrict_key);
607
608 /*
609 * We used to emit \connect postgres here, but that served no purpose
610 * other than to break things for installations without a postgres
611 * database. Everything we're restoring here is a global, so whichever
612 * database we're connected to at the moment is fine.
613 */
614
615 /* Restore will need to write to the target cluster */
616 fprintf(OPF, "SET default_transaction_read_only = off;\n\n");
617
618 /* Replicate encoding and std_strings in output */
619 fprintf(OPF, "SET client_encoding = '%s';\n",
621 fprintf(OPF, "SET standard_conforming_strings = %s;\n", std_strings);
622 if (strcmp(std_strings, "off") == 0)
623 fprintf(OPF, "SET escape_string_warning = off;\n");
624 fprintf(OPF, "\n");
625
626 if (!data_only && !statistics_only && !no_schema)
627 {
628 /*
629 * If asked to --clean, do that first. We can avoid detailed
630 * dependency analysis because databases never depend on each other,
631 * and tablespaces never depend on each other. Roles could have
632 * grants to each other, but DROP ROLE will clean those up silently.
633 */
634 if (output_clean)
635 {
636 if (!globals_only && !roles_only && !tablespaces_only)
637 dropDBs(conn);
638
639 if (!roles_only && !no_tablespaces)
641
642 if (!tablespaces_only)
644 }
645
646 /*
647 * Now create objects as requested. Be careful that option logic here
648 * is the same as for drops above.
649 */
650 if (!tablespaces_only)
651 {
652 /* Dump roles (users) */
654
655 /* Dump role memberships */
657
658 /* Dump role GUC privileges */
659 if (server_version >= 150000 && !skip_acls)
661 }
662
663 /* Dump tablespaces */
664 if (!roles_only && !no_tablespaces)
666 }
667
668 /*
669 * Exit restricted mode just before dumping the databases. pg_dump will
670 * handle entering restricted mode again as appropriate.
671 */
672 fprintf(OPF, "\\unrestrict %s\n\n", restrict_key);
673
674 if (!globals_only && !roles_only && !tablespaces_only)
676
677 PQfinish(conn);
678
679 if (verbose)
680 dumpTimestamp("Completed on");
681 fprintf(OPF, "--\n-- PostgreSQL database cluster dump complete\n--\n\n");
682
683 if (filename)
684 {
685 fclose(OPF);
686
687 /* sync the resulting file, errors are not fatal */
688 if (dosync)
689 (void) fsync_fname(filename, false);
690 }
691
692 exit_nicely(0);
693}
694
695
696static void
697help(void)
698{
699 printf(_("%s exports a PostgreSQL database cluster as an SQL script.\n\n"), progname);
700 printf(_("Usage:\n"));
701 printf(_(" %s [OPTION]...\n"), progname);
702
703 printf(_("\nGeneral options:\n"));
704 printf(_(" -f, --file=FILENAME output file name\n"));
705 printf(_(" -v, --verbose verbose mode\n"));
706 printf(_(" -V, --version output version information, then exit\n"));
707 printf(_(" --lock-wait-timeout=TIMEOUT fail after waiting TIMEOUT for a table lock\n"));
708 printf(_(" -?, --help show this help, then exit\n"));
709 printf(_("\nOptions controlling the output content:\n"));
710 printf(_(" -a, --data-only dump only the data, not the schema or statistics\n"));
711 printf(_(" -c, --clean clean (drop) databases before recreating\n"));
712 printf(_(" -E, --encoding=ENCODING dump the data in encoding ENCODING\n"));
713 printf(_(" -g, --globals-only dump only global objects, no databases\n"));
714 printf(_(" -O, --no-owner skip restoration of object ownership\n"));
715 printf(_(" -r, --roles-only dump only roles, no databases or tablespaces\n"));
716 printf(_(" -s, --schema-only dump only the schema, no data or statistics\n"));
717 printf(_(" -S, --superuser=NAME superuser user name to use in the dump\n"));
718 printf(_(" -t, --tablespaces-only dump only tablespaces, no databases or roles\n"));
719 printf(_(" -x, --no-privileges do not dump privileges (grant/revoke)\n"));
720 printf(_(" --binary-upgrade for use by upgrade utilities only\n"));
721 printf(_(" --column-inserts dump data as INSERT commands with column names\n"));
722 printf(_(" --disable-dollar-quoting disable dollar quoting, use SQL standard quoting\n"));
723 printf(_(" --disable-triggers disable triggers during data-only restore\n"));
724 printf(_(" --exclude-database=PATTERN exclude databases whose name matches PATTERN\n"));
725 printf(_(" --extra-float-digits=NUM override default setting for extra_float_digits\n"));
726 printf(_(" --filter=FILENAME exclude databases based on expressions in FILENAME\n"));
727 printf(_(" --if-exists use IF EXISTS when dropping objects\n"));
728 printf(_(" --inserts dump data as INSERT commands, rather than COPY\n"));
729 printf(_(" --load-via-partition-root load partitions via the root table\n"));
730 printf(_(" --no-comments do not dump comment commands\n"));
731 printf(_(" --no-data do not dump data\n"));
732 printf(_(" --no-policies do not dump row security policies\n"));
733 printf(_(" --no-publications do not dump publications\n"));
734 printf(_(" --no-role-passwords do not dump passwords for roles\n"));
735 printf(_(" --no-schema do not dump schema\n"));
736 printf(_(" --no-security-labels do not dump security label assignments\n"));
737 printf(_(" --no-statistics do not dump statistics\n"));
738 printf(_(" --no-subscriptions do not dump subscriptions\n"));
739 printf(_(" --no-sync do not wait for changes to be written safely to disk\n"));
740 printf(_(" --no-table-access-method do not dump table access methods\n"));
741 printf(_(" --no-tablespaces do not dump tablespace assignments\n"));
742 printf(_(" --no-toast-compression do not dump TOAST compression methods\n"));
743 printf(_(" --no-unlogged-table-data do not dump unlogged table data\n"));
744 printf(_(" --on-conflict-do-nothing add ON CONFLICT DO NOTHING to INSERT commands\n"));
745 printf(_(" --quote-all-identifiers quote all identifiers, even if not key words\n"));
746 printf(_(" --restrict-key=RESTRICT_KEY use provided string as psql \\restrict key\n"));
747 printf(_(" --rows-per-insert=NROWS number of rows per INSERT; implies --inserts\n"));
748 printf(_(" --sequence-data include sequence data in dump\n"));
749 printf(_(" --statistics dump the statistics\n"));
750 printf(_(" --statistics-only dump only the statistics, not schema or data\n"));
751 printf(_(" --use-set-session-authorization\n"
752 " use SET SESSION AUTHORIZATION commands instead of\n"
753 " ALTER OWNER commands to set ownership\n"));
754
755 printf(_("\nConnection options:\n"));
756 printf(_(" -d, --dbname=CONNSTR connect using connection string\n"));
757 printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
758 printf(_(" -l, --database=DBNAME alternative default database\n"));
759 printf(_(" -p, --port=PORT database server port number\n"));
760 printf(_(" -U, --username=NAME connect as specified database user\n"));
761 printf(_(" -w, --no-password never prompt for password\n"));
762 printf(_(" -W, --password force password prompt (should happen automatically)\n"));
763 printf(_(" --role=ROLENAME do SET ROLE before dump\n"));
764
765 printf(_("\nIf -f/--file is not used, then the SQL script will be written to the standard\n"
766 "output.\n\n"));
767 printf(_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
768 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
769}
770
771
772/*
773 * Drop roles
774 */
775static void
777{
779 PGresult *res;
780 int i_rolname;
781 int i;
782
783 if (server_version >= 90600)
785 "SELECT rolname "
786 "FROM %s "
787 "WHERE rolname !~ '^pg_' "
788 "ORDER BY 1", role_catalog);
789 else
791 "SELECT rolname "
792 "FROM %s "
793 "ORDER BY 1", role_catalog);
794
795 res = executeQuery(conn, buf->data);
796
797 i_rolname = PQfnumber(res, "rolname");
798
799 if (PQntuples(res) > 0)
800 fprintf(OPF, "--\n-- Drop roles\n--\n\n");
801
802 for (i = 0; i < PQntuples(res); i++)
803 {
804 const char *rolename;
805
806 rolename = PQgetvalue(res, i, i_rolname);
807
808 fprintf(OPF, "DROP ROLE %s%s;\n",
809 if_exists ? "IF EXISTS " : "",
810 fmtId(rolename));
811 }
812
813 PQclear(res);
815
816 fprintf(OPF, "\n\n");
817}
818
819/*
820 * Dump roles
821 */
822static void
824{
826 PGresult *res;
827 int i_oid,
828 i_rolname,
829 i_rolsuper,
830 i_rolinherit,
831 i_rolcreaterole,
832 i_rolcreatedb,
833 i_rolcanlogin,
834 i_rolconnlimit,
835 i_rolpassword,
836 i_rolvaliduntil,
837 i_rolreplication,
838 i_rolbypassrls,
839 i_rolcomment,
840 i_is_current_user;
841 int i;
842
843 /*
844 * Notes: rolconfig is dumped later, and pg_authid must be used for
845 * extracting rolcomment regardless of role_catalog.
846 */
847 if (server_version >= 90600)
849 "SELECT oid, rolname, rolsuper, rolinherit, "
850 "rolcreaterole, rolcreatedb, "
851 "rolcanlogin, rolconnlimit, rolpassword, "
852 "rolvaliduntil, rolreplication, rolbypassrls, "
853 "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, "
854 "rolname = current_user AS is_current_user "
855 "FROM %s "
856 "WHERE rolname !~ '^pg_' "
857 "ORDER BY 2", role_catalog);
858 else if (server_version >= 90500)
860 "SELECT oid, rolname, rolsuper, rolinherit, "
861 "rolcreaterole, rolcreatedb, "
862 "rolcanlogin, rolconnlimit, rolpassword, "
863 "rolvaliduntil, rolreplication, rolbypassrls, "
864 "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, "
865 "rolname = current_user AS is_current_user "
866 "FROM %s "
867 "ORDER BY 2", role_catalog);
868 else
870 "SELECT oid, rolname, rolsuper, rolinherit, "
871 "rolcreaterole, rolcreatedb, "
872 "rolcanlogin, rolconnlimit, rolpassword, "
873 "rolvaliduntil, rolreplication, "
874 "false as rolbypassrls, "
875 "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, "
876 "rolname = current_user AS is_current_user "
877 "FROM %s "
878 "ORDER BY 2", role_catalog);
879
880 res = executeQuery(conn, buf->data);
881
882 i_oid = PQfnumber(res, "oid");
883 i_rolname = PQfnumber(res, "rolname");
884 i_rolsuper = PQfnumber(res, "rolsuper");
885 i_rolinherit = PQfnumber(res, "rolinherit");
886 i_rolcreaterole = PQfnumber(res, "rolcreaterole");
887 i_rolcreatedb = PQfnumber(res, "rolcreatedb");
888 i_rolcanlogin = PQfnumber(res, "rolcanlogin");
889 i_rolconnlimit = PQfnumber(res, "rolconnlimit");
890 i_rolpassword = PQfnumber(res, "rolpassword");
891 i_rolvaliduntil = PQfnumber(res, "rolvaliduntil");
892 i_rolreplication = PQfnumber(res, "rolreplication");
893 i_rolbypassrls = PQfnumber(res, "rolbypassrls");
894 i_rolcomment = PQfnumber(res, "rolcomment");
895 i_is_current_user = PQfnumber(res, "is_current_user");
896
897 if (PQntuples(res) > 0)
898 fprintf(OPF, "--\n-- Roles\n--\n\n");
899
900 for (i = 0; i < PQntuples(res); i++)
901 {
902 const char *rolename;
903 Oid auth_oid;
904
905 auth_oid = atooid(PQgetvalue(res, i, i_oid));
906 rolename = PQgetvalue(res, i, i_rolname);
907
908 if (strncmp(rolename, "pg_", 3) == 0)
909 {
910 pg_log_warning("role name starting with \"pg_\" skipped (%s)",
911 rolename);
912 continue;
913 }
914
916
917 if (binary_upgrade)
918 {
919 appendPQExpBufferStr(buf, "\n-- For binary upgrade, must preserve pg_authid.oid\n");
921 "SELECT pg_catalog.binary_upgrade_set_next_pg_authid_oid('%u'::pg_catalog.oid);\n\n",
922 auth_oid);
923 }
924
925 /*
926 * We dump CREATE ROLE followed by ALTER ROLE to ensure that the role
927 * will acquire the right properties even if it already exists (ie, it
928 * won't hurt for the CREATE to fail). This is particularly important
929 * for the role we are connected as, since even with --clean we will
930 * have failed to drop it. binary_upgrade cannot generate any errors,
931 * so we assume the current role is already created.
932 */
933 if (!binary_upgrade ||
934 strcmp(PQgetvalue(res, i, i_is_current_user), "f") == 0)
935 appendPQExpBuffer(buf, "CREATE ROLE %s;\n", fmtId(rolename));
936 appendPQExpBuffer(buf, "ALTER ROLE %s WITH", fmtId(rolename));
937
938 if (strcmp(PQgetvalue(res, i, i_rolsuper), "t") == 0)
939 appendPQExpBufferStr(buf, " SUPERUSER");
940 else
941 appendPQExpBufferStr(buf, " NOSUPERUSER");
942
943 if (strcmp(PQgetvalue(res, i, i_rolinherit), "t") == 0)
944 appendPQExpBufferStr(buf, " INHERIT");
945 else
946 appendPQExpBufferStr(buf, " NOINHERIT");
947
948 if (strcmp(PQgetvalue(res, i, i_rolcreaterole), "t") == 0)
949 appendPQExpBufferStr(buf, " CREATEROLE");
950 else
951 appendPQExpBufferStr(buf, " NOCREATEROLE");
952
953 if (strcmp(PQgetvalue(res, i, i_rolcreatedb), "t") == 0)
954 appendPQExpBufferStr(buf, " CREATEDB");
955 else
956 appendPQExpBufferStr(buf, " NOCREATEDB");
957
958 if (strcmp(PQgetvalue(res, i, i_rolcanlogin), "t") == 0)
959 appendPQExpBufferStr(buf, " LOGIN");
960 else
961 appendPQExpBufferStr(buf, " NOLOGIN");
962
963 if (strcmp(PQgetvalue(res, i, i_rolreplication), "t") == 0)
964 appendPQExpBufferStr(buf, " REPLICATION");
965 else
966 appendPQExpBufferStr(buf, " NOREPLICATION");
967
968 if (strcmp(PQgetvalue(res, i, i_rolbypassrls), "t") == 0)
969 appendPQExpBufferStr(buf, " BYPASSRLS");
970 else
971 appendPQExpBufferStr(buf, " NOBYPASSRLS");
972
973 if (strcmp(PQgetvalue(res, i, i_rolconnlimit), "-1") != 0)
974 appendPQExpBuffer(buf, " CONNECTION LIMIT %s",
975 PQgetvalue(res, i, i_rolconnlimit));
976
977
978 if (!PQgetisnull(res, i, i_rolpassword) && !no_role_passwords)
979 {
980 appendPQExpBufferStr(buf, " PASSWORD ");
981 appendStringLiteralConn(buf, PQgetvalue(res, i, i_rolpassword), conn);
982 }
983
984 if (!PQgetisnull(res, i, i_rolvaliduntil))
985 appendPQExpBuffer(buf, " VALID UNTIL '%s'",
986 PQgetvalue(res, i, i_rolvaliduntil));
987
989
990 if (!no_comments && !PQgetisnull(res, i, i_rolcomment))
991 {
992 appendPQExpBuffer(buf, "COMMENT ON ROLE %s IS ", fmtId(rolename));
993 appendStringLiteralConn(buf, PQgetvalue(res, i, i_rolcomment), conn);
995 }
996
998 buildShSecLabels(conn, "pg_authid", auth_oid,
999 "ROLE", rolename,
1000 buf);
1001
1002 fprintf(OPF, "%s", buf->data);
1003 }
1004
1005 /*
1006 * Dump configuration settings for roles after all roles have been dumped.
1007 * We do it this way because config settings for roles could mention the
1008 * names of other roles.
1009 */
1010 if (PQntuples(res) > 0)
1011 fprintf(OPF, "\n--\n-- User Configurations\n--\n");
1012
1013 for (i = 0; i < PQntuples(res); i++)
1014 dumpUserConfig(conn, PQgetvalue(res, i, i_rolname));
1015
1016 PQclear(res);
1017
1018 fprintf(OPF, "\n\n");
1019
1021}
1022
1023
1024/*
1025 * Dump role memberships.
1026 *
1027 * Note: we expect dumpRoles already created all the roles, but there is
1028 * no membership yet.
1029 */
1030static void
1032{
1034 PQExpBuffer optbuf = createPQExpBuffer();
1035 PGresult *res;
1036 int start = 0,
1037 end,
1038 total;
1039 bool dump_grantors;
1040 bool dump_grant_options;
1041 int i_role;
1042 int i_member;
1043 int i_grantor;
1044 int i_roleid;
1045 int i_memberid;
1046 int i_grantorid;
1047 int i_admin_option;
1048 int i_inherit_option;
1049 int i_set_option;
1050
1051 /*
1052 * Previous versions of PostgreSQL didn't used to track the grantor very
1053 * carefully in the backend, and the grantor could be any user even if
1054 * they didn't have ADMIN OPTION on the role, or a user that no longer
1055 * existed. To avoid dump and restore failures, don't dump the grantor
1056 * when talking to an old server version.
1057 *
1058 * Also, in older versions the roleid and/or member could be role OIDs
1059 * that no longer exist. If we find such cases, print a warning and skip
1060 * the entry.
1061 */
1062 dump_grantors = (PQserverVersion(conn) >= 160000);
1063
1064 /*
1065 * Previous versions of PostgreSQL also did not have grant-level options.
1066 */
1067 dump_grant_options = (server_version >= 160000);
1068
1069 /* Generate and execute query. */
1070 printfPQExpBuffer(buf, "SELECT ur.rolname AS role, "
1071 "um.rolname AS member, "
1072 "ug.rolname AS grantor, "
1073 "a.roleid AS roleid, "
1074 "a.member AS memberid, "
1075 "a.grantor AS grantorid, "
1076 "a.admin_option");
1077 if (dump_grant_options)
1078 appendPQExpBufferStr(buf, ", a.inherit_option, a.set_option");
1079 appendPQExpBuffer(buf, " FROM pg_auth_members a "
1080 "LEFT JOIN %s ur on ur.oid = a.roleid "
1081 "LEFT JOIN %s um on um.oid = a.member "
1082 "LEFT JOIN %s ug on ug.oid = a.grantor "
1083 "WHERE NOT (ur.rolname ~ '^pg_' AND um.rolname ~ '^pg_')"
1084 "ORDER BY 1,2,3", role_catalog, role_catalog, role_catalog);
1085 res = executeQuery(conn, buf->data);
1086 i_role = PQfnumber(res, "role");
1087 i_member = PQfnumber(res, "member");
1088 i_grantor = PQfnumber(res, "grantor");
1089 i_roleid = PQfnumber(res, "roleid");
1090 i_memberid = PQfnumber(res, "memberid");
1091 i_grantorid = PQfnumber(res, "grantorid");
1092 i_admin_option = PQfnumber(res, "admin_option");
1093 i_inherit_option = PQfnumber(res, "inherit_option");
1094 i_set_option = PQfnumber(res, "set_option");
1095
1096 if (PQntuples(res) > 0)
1097 fprintf(OPF, "--\n-- Role memberships\n--\n\n");
1098
1099 /*
1100 * We can't dump these GRANT commands in arbitrary order, because a role
1101 * that is named as a grantor must already have ADMIN OPTION on the role
1102 * for which it is granting permissions, except for the bootstrap
1103 * superuser, who can always be named as the grantor.
1104 *
1105 * We handle this by considering these grants role by role. For each role,
1106 * we initially consider the only allowable grantor to be the bootstrap
1107 * superuser. Every time we grant ADMIN OPTION on the role to some user,
1108 * that user also becomes an allowable grantor. We make repeated passes
1109 * over the grants for the role, each time dumping those whose grantors
1110 * are allowable and which we haven't done yet. Eventually this should let
1111 * us dump all the grants.
1112 */
1113 total = PQntuples(res);
1114 while (start < total)
1115 {
1116 char *role = PQgetvalue(res, start, i_role);
1117 int i;
1118 bool *done;
1119 int remaining;
1120 int prev_remaining = 0;
1121 rolename_hash *ht;
1122
1123 /* If we hit a null roleid, we're done (nulls sort to the end). */
1124 if (PQgetisnull(res, start, i_role))
1125 {
1126 /* translator: %s represents a numeric role OID */
1127 pg_log_warning("found orphaned pg_auth_members entry for role %s",
1128 PQgetvalue(res, start, i_roleid));
1129 break;
1130 }
1131
1132 /* All memberships for a single role should be adjacent. */
1133 for (end = start; end < total; ++end)
1134 {
1135 char *otherrole;
1136
1137 otherrole = PQgetvalue(res, end, i_role);
1138 if (strcmp(role, otherrole) != 0)
1139 break;
1140 }
1141
1142 remaining = end - start;
1143 done = pg_malloc0(remaining * sizeof(bool));
1144 ht = rolename_create(remaining, NULL);
1145
1146 /*
1147 * Make repeated passes over the grants for this role until all have
1148 * been dumped.
1149 */
1150 while (remaining > 0)
1151 {
1152 /*
1153 * We should make progress on every iteration, because a notional
1154 * graph whose vertices are grants and whose edges point from
1155 * grantors to members should be connected and acyclic. If we fail
1156 * to make progress, either we or the server have messed up.
1157 */
1158 if (remaining == prev_remaining)
1159 {
1160 pg_log_error("could not find a legal dump ordering for memberships in role \"%s\"",
1161 role);
1162 PQfinish(conn);
1163 exit_nicely(1);
1164 }
1165 prev_remaining = remaining;
1166
1167 /* Make one pass over the grants for this role. */
1168 for (i = start; i < end; ++i)
1169 {
1170 char *member;
1171 char *admin_option;
1172 char *grantorid;
1173 char *grantor;
1174 char *set_option = "true";
1175 bool found;
1176
1177 /* If we already did this grant, don't do it again. */
1178 if (done[i - start])
1179 continue;
1180
1181 /* Complain about, then ignore, entries with orphaned OIDs. */
1182 if (PQgetisnull(res, i, i_member))
1183 {
1184 /* translator: %s represents a numeric role OID */
1185 pg_log_warning("found orphaned pg_auth_members entry for role %s",
1186 PQgetvalue(res, i, i_memberid));
1187 done[i - start] = true;
1188 --remaining;
1189 continue;
1190 }
1191 if (PQgetisnull(res, i, i_grantor))
1192 {
1193 /* translator: %s represents a numeric role OID */
1194 pg_log_warning("found orphaned pg_auth_members entry for role %s",
1195 PQgetvalue(res, i, i_grantorid));
1196 done[i - start] = true;
1197 --remaining;
1198 continue;
1199 }
1200
1201 member = PQgetvalue(res, i, i_member);
1202 grantor = PQgetvalue(res, i, i_grantor);
1203 grantorid = PQgetvalue(res, i, i_grantorid);
1204 admin_option = PQgetvalue(res, i, i_admin_option);
1205 if (dump_grant_options)
1206 set_option = PQgetvalue(res, i, i_set_option);
1207
1208 /*
1209 * If we're not dumping grantors or if the grantor is the
1210 * bootstrap superuser, it's fine to dump this now. Otherwise,
1211 * it's got to be someone who has already been granted ADMIN
1212 * OPTION.
1213 */
1214 if (dump_grantors &&
1215 atooid(grantorid) != BOOTSTRAP_SUPERUSERID &&
1216 rolename_lookup(ht, grantor) == NULL)
1217 continue;
1218
1219 /* Remember that we did this so that we don't do it again. */
1220 done[i - start] = true;
1221 --remaining;
1222
1223 /*
1224 * If ADMIN OPTION is being granted, remember that grants
1225 * listing this member as the grantor can now be dumped.
1226 */
1227 if (*admin_option == 't')
1228 rolename_insert(ht, member, &found);
1229
1230 /* Generate the actual GRANT statement. */
1231 resetPQExpBuffer(optbuf);
1232 fprintf(OPF, "GRANT %s", fmtId(role));
1233 fprintf(OPF, " TO %s", fmtId(member));
1234 if (*admin_option == 't')
1235 appendPQExpBufferStr(optbuf, "ADMIN OPTION");
1236 if (dump_grant_options)
1237 {
1238 char *inherit_option;
1239
1240 if (optbuf->data[0] != '\0')
1241 appendPQExpBufferStr(optbuf, ", ");
1242 inherit_option = PQgetvalue(res, i, i_inherit_option);
1243 appendPQExpBuffer(optbuf, "INHERIT %s",
1244 *inherit_option == 't' ?
1245 "TRUE" : "FALSE");
1246 }
1247 if (*set_option != 't')
1248 {
1249 if (optbuf->data[0] != '\0')
1250 appendPQExpBufferStr(optbuf, ", ");
1251 appendPQExpBufferStr(optbuf, "SET FALSE");
1252 }
1253 if (optbuf->data[0] != '\0')
1254 fprintf(OPF, " WITH %s", optbuf->data);
1255 if (dump_grantors)
1256 fprintf(OPF, " GRANTED BY %s", fmtId(grantor));
1257 fprintf(OPF, ";\n");
1258 }
1259 }
1260
1261 rolename_destroy(ht);
1262 pg_free(done);
1263 start = end;
1264 }
1265
1266 PQclear(res);
1268
1269 fprintf(OPF, "\n\n");
1270}
1271
1272
1273/*
1274 * Dump role configuration parameter privileges. This code is used for 15.0
1275 * and later servers.
1276 *
1277 * Note: we expect dumpRoles already created all the roles, but there are
1278 * no per-role configuration parameter privileges yet.
1279 */
1280static void
1282{
1283 PGresult *res;
1284 int i;
1285
1286 /*
1287 * Get all parameters that have non-default acls defined.
1288 */
1289 res = executeQuery(conn, "SELECT parname, "
1290 "pg_catalog.pg_get_userbyid(" CppAsString2(BOOTSTRAP_SUPERUSERID) ") AS parowner, "
1291 "paracl, "
1292 "pg_catalog.acldefault('p', " CppAsString2(BOOTSTRAP_SUPERUSERID) ") AS acldefault "
1293 "FROM pg_catalog.pg_parameter_acl "
1294 "ORDER BY 1");
1295
1296 if (PQntuples(res) > 0)
1297 fprintf(OPF, "--\n-- Role privileges on configuration parameters\n--\n\n");
1298
1299 for (i = 0; i < PQntuples(res); i++)
1300 {
1302 char *parname = PQgetvalue(res, i, 0);
1303 char *parowner = PQgetvalue(res, i, 1);
1304 char *paracl = PQgetvalue(res, i, 2);
1305 char *acldefault = PQgetvalue(res, i, 3);
1306 char *fparname;
1307
1308 /* needed for buildACLCommands() */
1309 fparname = pg_strdup(fmtId(parname));
1310
1311 if (!buildACLCommands(fparname, NULL, NULL, "PARAMETER",
1312 paracl, acldefault,
1313 parowner, "", server_version, buf))
1314 {
1315 pg_log_error("could not parse ACL list (%s) for parameter \"%s\"",
1316 paracl, parname);
1317 PQfinish(conn);
1318 exit_nicely(1);
1319 }
1320
1321 fprintf(OPF, "%s", buf->data);
1322
1323 free(fparname);
1325 }
1326
1327 PQclear(res);
1328 fprintf(OPF, "\n\n");
1329}
1330
1331
1332/*
1333 * Drop tablespaces.
1334 */
1335static void
1337{
1338 PGresult *res;
1339 int i;
1340
1341 /*
1342 * Get all tablespaces except built-in ones (which we assume are named
1343 * pg_xxx)
1344 */
1345 res = executeQuery(conn, "SELECT spcname "
1346 "FROM pg_catalog.pg_tablespace "
1347 "WHERE spcname !~ '^pg_' "
1348 "ORDER BY 1");
1349
1350 if (PQntuples(res) > 0)
1351 fprintf(OPF, "--\n-- Drop tablespaces\n--\n\n");
1352
1353 for (i = 0; i < PQntuples(res); i++)
1354 {
1355 char *spcname = PQgetvalue(res, i, 0);
1356
1357 fprintf(OPF, "DROP TABLESPACE %s%s;\n",
1358 if_exists ? "IF EXISTS " : "",
1359 fmtId(spcname));
1360 }
1361
1362 PQclear(res);
1363
1364 fprintf(OPF, "\n\n");
1365}
1366
1367/*
1368 * Dump tablespaces.
1369 */
1370static void
1372{
1373 PGresult *res;
1374 int i;
1375
1376 /*
1377 * Get all tablespaces except built-in ones (which we assume are named
1378 * pg_xxx)
1379 */
1380 res = executeQuery(conn, "SELECT oid, spcname, "
1381 "pg_catalog.pg_get_userbyid(spcowner) AS spcowner, "
1382 "pg_catalog.pg_tablespace_location(oid), "
1383 "spcacl, acldefault('t', spcowner) AS acldefault, "
1384 "array_to_string(spcoptions, ', '),"
1385 "pg_catalog.shobj_description(oid, 'pg_tablespace') "
1386 "FROM pg_catalog.pg_tablespace "
1387 "WHERE spcname !~ '^pg_' "
1388 "ORDER BY 1");
1389
1390 if (PQntuples(res) > 0)
1391 fprintf(OPF, "--\n-- Tablespaces\n--\n\n");
1392
1393 for (i = 0; i < PQntuples(res); i++)
1394 {
1396 Oid spcoid = atooid(PQgetvalue(res, i, 0));
1397 char *spcname = PQgetvalue(res, i, 1);
1398 char *spcowner = PQgetvalue(res, i, 2);
1399 char *spclocation = PQgetvalue(res, i, 3);
1400 char *spcacl = PQgetvalue(res, i, 4);
1401 char *acldefault = PQgetvalue(res, i, 5);
1402 char *spcoptions = PQgetvalue(res, i, 6);
1403 char *spccomment = PQgetvalue(res, i, 7);
1404 char *fspcname;
1405
1406 /* needed for buildACLCommands() */
1407 fspcname = pg_strdup(fmtId(spcname));
1408
1409 if (binary_upgrade)
1410 {
1411 appendPQExpBufferStr(buf, "\n-- For binary upgrade, must preserve pg_tablespace oid\n");
1412 appendPQExpBuffer(buf, "SELECT pg_catalog.binary_upgrade_set_next_pg_tablespace_oid('%u'::pg_catalog.oid);\n", spcoid);
1413 }
1414
1415 appendPQExpBuffer(buf, "CREATE TABLESPACE %s", fspcname);
1416 appendPQExpBuffer(buf, " OWNER %s", fmtId(spcowner));
1417
1418 appendPQExpBufferStr(buf, " LOCATION ");
1419
1420 /*
1421 * In-place tablespaces use a relative path, and need to be dumped
1422 * with an empty string as location.
1423 */
1424 if (is_absolute_path(spclocation))
1425 appendStringLiteralConn(buf, spclocation, conn);
1426 else
1428
1429 appendPQExpBufferStr(buf, ";\n");
1430
1431 if (spcoptions && spcoptions[0] != '\0')
1432 appendPQExpBuffer(buf, "ALTER TABLESPACE %s SET (%s);\n",
1433 fspcname, spcoptions);
1434
1435 /* tablespaces can't have initprivs */
1436
1437 if (!skip_acls &&
1438 !buildACLCommands(fspcname, NULL, NULL, "TABLESPACE",
1439 spcacl, acldefault,
1440 spcowner, "", server_version, buf))
1441 {
1442 pg_log_error("could not parse ACL list (%s) for tablespace \"%s\"",
1443 spcacl, spcname);
1444 PQfinish(conn);
1445 exit_nicely(1);
1446 }
1447
1448 if (!no_comments && spccomment && spccomment[0] != '\0')
1449 {
1450 appendPQExpBuffer(buf, "COMMENT ON TABLESPACE %s IS ", fspcname);
1451 appendStringLiteralConn(buf, spccomment, conn);
1452 appendPQExpBufferStr(buf, ";\n");
1453 }
1454
1455 if (!no_security_labels)
1456 buildShSecLabels(conn, "pg_tablespace", spcoid,
1457 "TABLESPACE", spcname,
1458 buf);
1459
1460 fprintf(OPF, "%s", buf->data);
1461
1462 free(fspcname);
1464 }
1465
1466 PQclear(res);
1467 fprintf(OPF, "\n\n");
1468}
1469
1470
1471/*
1472 * Dump commands to drop each database.
1473 */
1474static void
1476{
1477 PGresult *res;
1478 int i;
1479
1480 /*
1481 * Skip databases marked not datallowconn, since we'd be unable to connect
1482 * to them anyway. This must agree with dumpDatabases().
1483 */
1484 res = executeQuery(conn,
1485 "SELECT datname "
1486 "FROM pg_database d "
1487 "WHERE datallowconn AND datconnlimit != -2 "
1488 "ORDER BY datname");
1489
1490 if (PQntuples(res) > 0)
1491 fprintf(OPF, "--\n-- Drop databases (except postgres and template1)\n--\n\n");
1492
1493 for (i = 0; i < PQntuples(res); i++)
1494 {
1495 char *dbname = PQgetvalue(res, i, 0);
1496
1497 /*
1498 * Skip "postgres" and "template1"; dumpDatabases() will deal with
1499 * them specially. Also, be sure to skip "template0", even if for
1500 * some reason it's not marked !datallowconn.
1501 */
1502 if (strcmp(dbname, "template1") != 0 &&
1503 strcmp(dbname, "template0") != 0 &&
1504 strcmp(dbname, "postgres") != 0)
1505 {
1506 fprintf(OPF, "DROP DATABASE %s%s;\n",
1507 if_exists ? "IF EXISTS " : "",
1508 fmtId(dbname));
1509 }
1510 }
1511
1512 PQclear(res);
1513
1514 fprintf(OPF, "\n\n");
1515}
1516
1517
1518/*
1519 * Dump user-specific configuration
1520 */
1521static void
1523{
1525 PGresult *res;
1526
1527 printfPQExpBuffer(buf, "SELECT unnest(setconfig) FROM pg_db_role_setting "
1528 "WHERE setdatabase = 0 AND setrole = "
1529 "(SELECT oid FROM %s WHERE rolname = ",
1530 role_catalog);
1533
1534 res = executeQuery(conn, buf->data);
1535
1536 if (PQntuples(res) > 0)
1537 {
1538 char *sanitized;
1539
1540 sanitized = sanitize_line(username, true);
1541 fprintf(OPF, "\n--\n-- User Config \"%s\"\n--\n\n", sanitized);
1542 free(sanitized);
1543 }
1544
1545 for (int i = 0; i < PQntuples(res); i++)
1546 {
1549 "ROLE", username, NULL, NULL,
1550 buf);
1551 fprintf(OPF, "%s", buf->data);
1552 }
1553
1554 PQclear(res);
1555
1557}
1558
1559/*
1560 * Find a list of database names that match the given patterns.
1561 * See also expand_table_name_patterns() in pg_dump.c
1562 */
1563static void
1565 SimpleStringList *patterns,
1566 SimpleStringList *names)
1567{
1568 PQExpBuffer query;
1569 PGresult *res;
1570
1571 if (patterns->head == NULL)
1572 return; /* nothing to do */
1573
1574 query = createPQExpBuffer();
1575
1576 /*
1577 * The loop below runs multiple SELECTs, which might sometimes result in
1578 * duplicate entries in the name list, but we don't care, since all we're
1579 * going to do is test membership of the list.
1580 */
1581
1582 for (SimpleStringListCell *cell = patterns->head; cell; cell = cell->next)
1583 {
1584 int dotcnt;
1585
1587 "SELECT datname FROM pg_catalog.pg_database n\n");
1588 processSQLNamePattern(conn, query, cell->val, false,
1589 false, NULL, "datname", NULL, NULL, NULL,
1590 &dotcnt);
1591
1592 if (dotcnt > 0)
1593 {
1594 pg_log_error("improper qualified name (too many dotted names): %s",
1595 cell->val);
1596 PQfinish(conn);
1597 exit_nicely(1);
1598 }
1599
1600 res = executeQuery(conn, query->data);
1601 for (int i = 0; i < PQntuples(res); i++)
1602 {
1603 simple_string_list_append(names, PQgetvalue(res, i, 0));
1604 }
1605
1606 PQclear(res);
1607 resetPQExpBuffer(query);
1608 }
1609
1610 destroyPQExpBuffer(query);
1611}
1612
1613/*
1614 * Dump contents of databases.
1615 */
1616static void
1618{
1619 PGresult *res;
1620 int i;
1621
1622 /*
1623 * Skip databases marked not datallowconn, since we'd be unable to connect
1624 * to them anyway. This must agree with dropDBs().
1625 *
1626 * We arrange for template1 to be processed first, then we process other
1627 * DBs in alphabetical order. If we just did them all alphabetically, we
1628 * might find ourselves trying to drop the "postgres" database while still
1629 * connected to it. This makes trying to run the restore script while
1630 * connected to "template1" a bad idea, but there's no fixed order that
1631 * doesn't have some failure mode with --clean.
1632 */
1633 res = executeQuery(conn,
1634 "SELECT datname "
1635 "FROM pg_database d "
1636 "WHERE datallowconn AND datconnlimit != -2 "
1637 "ORDER BY (datname <> 'template1'), datname");
1638
1639 if (PQntuples(res) > 0)
1640 fprintf(OPF, "--\n-- Databases\n--\n\n");
1641
1642 for (i = 0; i < PQntuples(res); i++)
1643 {
1644 char *dbname = PQgetvalue(res, i, 0);
1645 char *sanitized;
1646 const char *create_opts;
1647 int ret;
1648
1649 /* Skip template0, even if it's not marked !datallowconn. */
1650 if (strcmp(dbname, "template0") == 0)
1651 continue;
1652
1653 /* Skip any explicitly excluded database */
1655 {
1656 pg_log_info("excluding database \"%s\"", dbname);
1657 continue;
1658 }
1659
1660 pg_log_info("dumping database \"%s\"", dbname);
1661
1662 sanitized = sanitize_line(dbname, true);
1663 fprintf(OPF, "--\n-- Database \"%s\" dump\n--\n\n", sanitized);
1664 free(sanitized);
1665
1666 /*
1667 * We assume that "template1" and "postgres" already exist in the
1668 * target installation. dropDBs() won't have removed them, for fear
1669 * of removing the DB the restore script is initially connected to. If
1670 * --clean was specified, tell pg_dump to drop and recreate them;
1671 * otherwise we'll merely restore their contents. Other databases
1672 * should simply be created.
1673 */
1674 if (strcmp(dbname, "template1") == 0 || strcmp(dbname, "postgres") == 0)
1675 {
1676 if (output_clean)
1677 create_opts = "--clean --create";
1678 else
1679 {
1680 create_opts = "";
1681 /* Since pg_dump won't emit a \connect command, we must */
1682 fprintf(OPF, "\\connect %s\n\n", dbname);
1683 }
1684 }
1685 else
1686 create_opts = "--create";
1687
1688 if (filename)
1689 fclose(OPF);
1690
1691 ret = runPgDump(dbname, create_opts);
1692 if (ret != 0)
1693 pg_fatal("pg_dump failed on database \"%s\", exiting", dbname);
1694
1695 if (filename)
1696 {
1697 OPF = fopen(filename, PG_BINARY_A);
1698 if (!OPF)
1699 pg_fatal("could not re-open the output file \"%s\": %m",
1700 filename);
1701 }
1702 }
1703
1704 PQclear(res);
1705}
1706
1707
1708
1709/*
1710 * Run pg_dump on dbname, with specified options.
1711 */
1712static int
1713runPgDump(const char *dbname, const char *create_opts)
1714{
1715 PQExpBufferData connstrbuf;
1716 PQExpBufferData cmd;
1717 int ret;
1718
1719 initPQExpBuffer(&connstrbuf);
1720 initPQExpBuffer(&cmd);
1721
1722 printfPQExpBuffer(&cmd, "\"%s\" %s %s", pg_dump_bin,
1723 pgdumpopts->data, create_opts);
1724
1725 /*
1726 * If we have a filename, use the undocumented plain-append pg_dump
1727 * format.
1728 */
1729 if (filename)
1730 appendPQExpBufferStr(&cmd, " -Fa ");
1731 else
1732 appendPQExpBufferStr(&cmd, " -Fp ");
1733
1734 /*
1735 * Append the database name to the already-constructed stem of connection
1736 * string.
1737 */
1738 appendPQExpBuffer(&connstrbuf, "%s dbname=", connstr);
1739 appendConnStrVal(&connstrbuf, dbname);
1740
1741 appendShellString(&cmd, connstrbuf.data);
1742
1743 pg_log_info("running \"%s\"", cmd.data);
1744
1745 fflush(NULL);
1746
1747 ret = system(cmd.data);
1748
1749 termPQExpBuffer(&cmd);
1750 termPQExpBuffer(&connstrbuf);
1751
1752 return ret;
1753}
1754
1755/*
1756 * buildShSecLabels
1757 *
1758 * Build SECURITY LABEL command(s) for a shared object
1759 *
1760 * The caller has to provide object type and identity in two separate formats:
1761 * catalog_name (e.g., "pg_database") and object OID, as well as
1762 * type name (e.g., "DATABASE") and object name (not pre-quoted).
1763 *
1764 * The command(s) are appended to "buffer".
1765 */
1766static void
1767buildShSecLabels(PGconn *conn, const char *catalog_name, Oid objectId,
1768 const char *objtype, const char *objname,
1769 PQExpBuffer buffer)
1770{
1772 PGresult *res;
1773
1774 buildShSecLabelQuery(catalog_name, objectId, sql);
1775 res = executeQuery(conn, sql->data);
1776 emitShSecLabels(conn, res, buffer, objtype, objname);
1777
1778 PQclear(res);
1779 destroyPQExpBuffer(sql);
1780}
1781
1782/*
1783 * As above for a SQL command (which returns nothing).
1784 */
1785static void
1786executeCommand(PGconn *conn, const char *query)
1787{
1788 PGresult *res;
1789
1790 pg_log_info("executing %s", query);
1791
1792 res = PQexec(conn, query);
1793 if (!res ||
1795 {
1796 pg_log_error("query failed: %s", PQerrorMessage(conn));
1797 pg_log_error_detail("Query was: %s", query);
1798 PQfinish(conn);
1799 exit_nicely(1);
1800 }
1801
1802 PQclear(res);
1803}
1804
1805
1806/*
1807 * dumpTimestamp
1808 */
1809static void
1810dumpTimestamp(const char *msg)
1811{
1812 char buf[64];
1813 time_t now = time(NULL);
1814
1815 if (strftime(buf, sizeof(buf), PGDUMP_STRFTIME_FMT, localtime(&now)) != 0)
1816 fprintf(OPF, "-- %s %s\n\n", msg, buf);
1817}
1818
1819/*
1820 * read_dumpall_filters - retrieve database identifier patterns from file
1821 *
1822 * Parse the specified filter file for include and exclude patterns, and add
1823 * them to the relevant lists. If the filename is "-" then filters will be
1824 * read from STDIN rather than a file.
1825 *
1826 * At the moment, the only allowed filter is for database exclusion.
1827 */
1828static void
1830{
1831 FilterStateData fstate;
1832 char *objname;
1833 FilterCommandType comtype;
1834 FilterObjectType objtype;
1835
1836 filter_init(&fstate, filename, exit);
1837
1838 while (filter_read_item(&fstate, &objname, &comtype, &objtype))
1839 {
1840 if (comtype == FILTER_COMMAND_TYPE_INCLUDE)
1841 {
1842 pg_log_filter_error(&fstate, _("%s filter for \"%s\" is not allowed"),
1843 "include",
1844 filter_object_type_name(objtype));
1845 exit_nicely(1);
1846 }
1847
1848 switch (objtype)
1849 {
1851 break;
1862 pg_log_filter_error(&fstate, _("unsupported filter object"));
1863 exit_nicely(1);
1864 break;
1865
1867 simple_string_list_append(pattern, objname);
1868 break;
1869 }
1870
1871 if (objname)
1872 free(objname);
1873 }
1874
1875 filter_free(&fstate);
1876}
Acl * acldefault(ObjectType objtype, Oid ownerId)
Definition: acl.c:803
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1609
#define PG_BINARY_A
Definition: c.h:1272
#define PG_TEXTDOMAIN(domain)
Definition: c.h:1212
#define CppAsString2(x)
Definition: c.h:434
uint32_t uint32
Definition: c.h:552
#define PG_BINARY_W
Definition: c.h:1274
int find_my_exec(const char *argv0, char *retpath)
Definition: exec.c:161
void set_pglocale_pgservice(const char *argv0, const char *app)
Definition: exec.c:430
int find_other_exec(const char *argv0, const char *target, const char *versionstr, char *retpath)
Definition: exec.c:311
PGresult * executeQuery(PGconn *conn, const char *query)
Definition: connectdb.c:278
PGconn * ConnectDatabase(const char *dbname, const char *connection_string, const char *pghost, const char *pgport, const char *pguser, trivalue prompt_password, bool fail_on_error, const char *progname, const char **connstr, int *server_version, char *password, char *override_dbname)
Definition: connectdb.c:40
#define fprintf(file, fmt, msg)
Definition: cubescan.l:21
char * generate_restrict_key(void)
Definition: dumputils.c:972
bool buildACLCommands(const char *name, const char *subname, const char *nspname, const char *type, const char *acls, const char *baseacls, const char *owner, const char *prefix, int remoteVersion, PQExpBuffer sql)
Definition: dumputils.c:104
bool valid_restrict_key(const char *restrict_key)
Definition: dumputils.c:996
void buildShSecLabelQuery(const char *catalog_name, Oid objectId, PQExpBuffer sql)
Definition: dumputils.c:678
void makeAlterConfigCommand(PGconn *conn, const char *configitem, const char *type, const char *name, const char *type2, const char *name2, PQExpBuffer buf)
Definition: dumputils.c:864
char * sanitize_line(const char *str, bool want_hyphen)
Definition: dumputils.c:52
void emitShSecLabels(PGconn *conn, PGresult *res, PQExpBuffer buffer, const char *objtype, const char *objname)
Definition: dumputils.c:696
#define PGDUMP_STRFTIME_FMT
Definition: dumputils.h:34
#define _(x)
Definition: elog.c:91
void fsync_fname(const char *fname, bool isdir)
Definition: fd.c:753
int PQserverVersion(const PGconn *conn)
Definition: fe-connect.c:7694
const char * PQparameterStatus(const PGconn *conn, const char *paramName)
Definition: fe-connect.c:7659
int PQclientEncoding(const PGconn *conn)
Definition: fe-connect.c:7794
void PQfinish(PGconn *conn)
Definition: fe-connect.c:5316
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:7704
int PQsetClientEncoding(PGconn *conn, const char *encoding)
Definition: fe-connect.c:7802
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3606
PGresult * PQexec(PGconn *conn, const char *query)
Definition: fe-exec.c:2279
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
void pg_free(void *ptr)
Definition: fe_memutils.c:105
void filter_init(FilterStateData *fstate, const char *filename, exit_function f_exit)
Definition: filter.c:36
void filter_free(FilterStateData *fstate)
Definition: filter.c:60
const char * filter_object_type_name(FilterObjectType fot)
Definition: filter.c:82
bool filter_read_item(FilterStateData *fstate, char **objname, FilterCommandType *comtype, FilterObjectType *objtype)
Definition: filter.c:392
void pg_log_filter_error(FilterStateData *fstate, const char *fmt,...)
Definition: filter.c:154
FilterObjectType
Definition: filter.h:48
@ FILTER_OBJECT_TYPE_TABLE_DATA_AND_CHILDREN
Definition: filter.h:51
@ FILTER_OBJECT_TYPE_SCHEMA
Definition: filter.h:57
@ FILTER_OBJECT_TYPE_INDEX
Definition: filter.h:56
@ FILTER_OBJECT_TYPE_TRIGGER
Definition: filter.h:60
@ FILTER_OBJECT_TYPE_FOREIGN_DATA
Definition: filter.h:54
@ FILTER_OBJECT_TYPE_DATABASE
Definition: filter.h:52
@ FILTER_OBJECT_TYPE_FUNCTION
Definition: filter.h:55
@ FILTER_OBJECT_TYPE_TABLE_DATA
Definition: filter.h:50
@ FILTER_OBJECT_TYPE_NONE
Definition: filter.h:49
@ FILTER_OBJECT_TYPE_TABLE_AND_CHILDREN
Definition: filter.h:59
@ FILTER_OBJECT_TYPE_EXTENSION
Definition: filter.h:53
@ FILTER_OBJECT_TYPE_TABLE
Definition: filter.h:58
FilterCommandType
Definition: filter.h:38
@ FILTER_COMMAND_TYPE_INCLUDE
Definition: filter.h:40
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
Definition: getopt_long.c:60
#define no_argument
Definition: getopt_long.h:25
#define required_argument
Definition: getopt_long.h:26
return str start
#define free(a)
Definition: header.h:65
int remaining
Definition: informix.c:692
static char * username
Definition: initdb.c:153
int i
Definition: isn.c:77
#define PQgetvalue
Definition: libpq-be-fe.h:253
#define PQclear
Definition: libpq-be-fe.h:245
#define PQresultStatus
Definition: libpq-be-fe.h:247
#define PQgetisnull
Definition: libpq-be-fe.h:255
#define PQntuples
Definition: libpq-be-fe.h:251
@ PGRES_COMMAND_OK
Definition: libpq-fe.h:125
void pg_logging_increase_verbosity(void)
Definition: logging.c:185
void pg_logging_init(const char *argv0)
Definition: logging.c:83
void pg_logging_set_level(enum pg_log_level new_level)
Definition: logging.c:176
#define pg_log_error(...)
Definition: logging.h:106
#define pg_log_error_hint(...)
Definition: logging.h:112
#define pg_log_info(...)
Definition: logging.h:124
@ PG_LOG_WARNING
Definition: logging.h:38
#define pg_log_error_detail(...)
Definition: logging.h:109
const char * progname
Definition: main.c:44
bool set_option
bool inherit_option
bool admin_option
void exit_nicely(int code)
#define pg_fatal(...)
#define MAXPGPATH
int32 encoding
Definition: pg_database.h:41
static void dumpTimestamp(const char *msg)
Definition: pg_dumpall.c:1810
static int if_exists
Definition: pg_dumpall.c:92
static int on_conflict_do_nothing
Definition: pg_dumpall.c:111
int main(int argc, char *argv[])
Definition: pg_dumpall.c:128
static void dropTablespaces(PGconn *conn)
Definition: pg_dumpall.c:1336
static void expand_dbname_patterns(PGconn *conn, SimpleStringList *patterns, SimpleStringList *names)
Definition: pg_dumpall.c:1564
static int no_role_passwords
Definition: pg_dumpall.c:107
static PQExpBuffer pgdumpopts
Definition: pg_dumpall.c:81
static int statistics_only
Definition: pg_dumpall.c:112
static int no_table_access_method
Definition: pg_dumpall.c:94
static int no_unlogged_table_data
Definition: pg_dumpall.c:106
#define PG_AUTHID
Definition: pg_dumpall.c:116
static int no_policies
Definition: pg_dumpall.c:98
static int binary_upgrade
Definition: pg_dumpall.c:88
static int disable_triggers
Definition: pg_dumpall.c:91
static void dumpUserConfig(PGconn *conn, const char *username)
Definition: pg_dumpall.c:1522
static bool dosync
Definition: pg_dumpall.c:86
static const char * connstr
Definition: pg_dumpall.c:82
static SimpleStringList database_exclude_patterns
Definition: pg_dumpall.c:122
static void dumpTablespaces(PGconn *conn)
Definition: pg_dumpall.c:1371
static void dumpRoleMembership(PGconn *conn)
Definition: pg_dumpall.c:1031
static char pg_dump_bin[MAXPGPATH]
Definition: pg_dumpall.c:80
static SimpleStringList database_exclude_names
Definition: pg_dumpall.c:123
static FILE * OPF
Definition: pg_dumpall.c:119
static int no_comments
Definition: pg_dumpall.c:97
static int no_publications
Definition: pg_dumpall.c:99
static int sequence_data
Definition: pg_dumpall.c:113
static char * restrict_key
Definition: pg_dumpall.c:125
static int no_security_labels
Definition: pg_dumpall.c:100
static void dumpDatabases(PGconn *conn)
Definition: pg_dumpall.c:1617
static int disable_dollar_quoting
Definition: pg_dumpall.c:90
static void buildShSecLabels(PGconn *conn, const char *catalog_name, Oid objectId, const char *objtype, const char *objname, PQExpBuffer buffer)
Definition: pg_dumpall.c:1767
static int no_tablespaces
Definition: pg_dumpall.c:95
static int no_toast_compression
Definition: pg_dumpall.c:105
#define PG_ROLES
Definition: pg_dumpall.c:117
static int inserts
Definition: pg_dumpall.c:93
static void executeCommand(PGconn *conn, const char *query)
Definition: pg_dumpall.c:1786
static bool verbose
Definition: pg_dumpall.c:85
static int runPgDump(const char *dbname, const char *create_opts)
Definition: pg_dumpall.c:1713
static void dumpRoleGUCPrivs(PGconn *conn)
Definition: pg_dumpall.c:1281
static int no_statistics
Definition: pg_dumpall.c:103
static void dumpRoles(PGconn *conn)
Definition: pg_dumpall.c:823
static void help(void)
Definition: pg_dumpall.c:697
static int use_setsessauth
Definition: pg_dumpall.c:96
static int no_data
Definition: pg_dumpall.c:101
static int load_via_partition_root
Definition: pg_dumpall.c:110
static int column_inserts
Definition: pg_dumpall.c:89
static void read_dumpall_filters(const char *filename, SimpleStringList *pattern)
Definition: pg_dumpall.c:1829
static void dropRoles(PGconn *conn)
Definition: pg_dumpall.c:776
static void dropDBs(PGconn *conn)
Definition: pg_dumpall.c:1475
static int server_version
Definition: pg_dumpall.c:109
static char role_catalog[10]
Definition: pg_dumpall.c:115
static bool output_clean
Definition: pg_dumpall.c:83
static int no_schema
Definition: pg_dumpall.c:102
static int no_subscriptions
Definition: pg_dumpall.c:104
static char * filename
Definition: pg_dumpall.c:120
static int with_statistics
Definition: pg_dumpall.c:108
#define PGDUMP_VERSIONSTR
Definition: pg_dumpall.c:35
static bool skip_acls
Definition: pg_dumpall.c:84
PGDLLIMPORT int optind
Definition: getopt.c:51
PGDLLIMPORT char * optarg
Definition: getopt.c:53
static char buf[DEFAULT_XLOG_SEG_SIZE]
Definition: pg_test_fsync.c:71
#define pg_encoding_to_char
Definition: pg_wchar.h:630
static const char * pghost
Definition: pgbench.c:295
static const char * pgport
Definition: pgbench.c:296
#define pg_log_warning(...)
Definition: pgfnames.c:24
#define is_absolute_path(filename)
Definition: port.h:104
#define sprintf
Definition: port.h:262
const char * get_progname(const char *argv0)
Definition: path.c:652
#define printf(...)
Definition: port.h:266
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
unsigned int Oid
Definition: postgres_ext.h:32
#define atooid(x)
Definition: postgres_ext.h:43
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:235
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:72
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:90
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:146
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:265
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:114
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:378
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:367
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:129
char * c
bool quote_all_identifiers
Definition: ruleutils.c:339
bool simple_string_list_member(SimpleStringList *list, const char *val)
Definition: simple_list.c:87
void simple_string_list_append(SimpleStringList *list, const char *val)
Definition: simple_list.c:63
char * dbname
Definition: streamutil.c:49
PGconn * conn
Definition: streamutil.c:52
const char * fmtId(const char *rawid)
Definition: string_utils.c:248
void setFmtEncoding(int encoding)
Definition: string_utils.c:69
void appendShellString(PQExpBuffer buf, const char *str)
Definition: string_utils.c:582
void appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn)
Definition: string_utils.c:446
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule, PQExpBuffer dbnamebuf, int *dotcnt)
void appendConnStrVal(PQExpBuffer buf, const char *str)
Definition: string_utils.c:698
uint32 hashval
Definition: pg_dumpall.c:40
uint32 status
Definition: pg_dumpall.c:39
char * rolename
Definition: pg_dumpall.c:41
struct SimpleStringListCell * next
Definition: simple_list.h:34
SimpleStringListCell * head
Definition: simple_list.h:42
trivalue
Definition: vacuumlo.c:35
@ TRI_YES
Definition: vacuumlo.c:38
@ TRI_DEFAULT
Definition: vacuumlo.c:36
@ TRI_NO
Definition: vacuumlo.c:37