PostgreSQL Source Code git master
pg_dumpall.c File Reference
#include "postgres_fe.h"
#include <time.h>
#include <unistd.h>
#include "catalog/pg_authid_d.h"
#include "common/connect.h"
#include "common/file_perm.h"
#include "common/file_utils.h"
#include "common/hashfn_unstable.h"
#include "common/logging.h"
#include "common/string.h"
#include "connectdb.h"
#include "dumputils.h"
#include "fe_utils/string_utils.h"
#include "filter.h"
#include "getopt_long.h"
#include "lib/simplehash.h"
Include dependency graph for pg_dumpall.c:

Go to the source code of this file.

Data Structures

struct  RoleNameEntry
 

Macros

#define PGDUMP_VERSIONSTR   "pg_dump (PostgreSQL) " PG_VERSION "\n"
 
#define SH_PREFIX   rolename
 
#define SH_ELEMENT_TYPE   RoleNameEntry
 
#define SH_KEY_TYPE   char *
 
#define SH_KEY   rolename
 
#define SH_HASH_KEY(tb, key)   hash_string(key)
 
#define SH_EQUAL(tb, a, b)   (strcmp(a, b) == 0)
 
#define SH_STORE_HASH
 
#define SH_GET_HASH(tb, a)   (a)->hashval
 
#define SH_SCOPE   static inline
 
#define SH_RAW_ALLOCATOR   pg_malloc0
 
#define SH_DECLARE
 
#define SH_DEFINE
 
#define PG_AUTHID   "pg_authid"
 
#define PG_ROLES   "pg_roles "
 

Functions

static void help (void)
 
static void dropRoles (PGconn *conn)
 
static void dumpRoles (PGconn *conn)
 
static void dumpRoleMembership (PGconn *conn)
 
static void dumpRoleGUCPrivs (PGconn *conn)
 
static void dropTablespaces (PGconn *conn)
 
static void dumpTablespaces (PGconn *conn)
 
static void dropDBs (PGconn *conn)
 
static void dumpUserConfig (PGconn *conn, const char *username)
 
static void dumpDatabases (PGconn *conn, ArchiveFormat archDumpFormat)
 
static void dumpTimestamp (const char *msg)
 
static int runPgDump (const char *dbname, const char *create_opts, char *dbfile, ArchiveFormat archDumpFormat)
 
static void buildShSecLabels (PGconn *conn, const char *catalog_name, Oid objectId, const char *objtype, const char *objname, PQExpBuffer buffer)
 
static void executeCommand (PGconn *conn, const char *query)
 
static void expand_dbname_patterns (PGconn *conn, SimpleStringList *patterns, SimpleStringList *names)
 
static void read_dumpall_filters (const char *filename, SimpleStringList *pattern)
 
static ArchiveFormat parseDumpFormat (const char *format)
 
int main (int argc, char *argv[])
 

Variables

static char pg_dump_bin [MAXPGPATH]
 
static PQExpBuffer pgdumpopts
 
static const char * connstr = ""
 
static bool output_clean = false
 
static bool skip_acls = false
 
static bool verbose = false
 
static bool dosync = true
 
static int binary_upgrade = 0
 
static int column_inserts = 0
 
static int disable_dollar_quoting = 0
 
static int disable_triggers = 0
 
static int if_exists = 0
 
static int inserts = 0
 
static int no_table_access_method = 0
 
static int no_tablespaces = 0
 
static int use_setsessauth = 0
 
static int no_comments = 0
 
static int no_policies = 0
 
static int no_publications = 0
 
static int no_security_labels = 0
 
static int no_data = 0
 
static int no_schema = 0
 
static int no_statistics = 0
 
static int no_subscriptions = 0
 
static int no_toast_compression = 0
 
static int no_unlogged_table_data = 0
 
static int no_role_passwords = 0
 
static int with_data = 0
 
static int with_schema = 0
 
static int with_statistics = 0
 
static int server_version
 
static int load_via_partition_root = 0
 
static int on_conflict_do_nothing = 0
 
static int statistics_only = 0
 
static char role_catalog [10]
 
static FILE * OPF
 
static char * filename = NULL
 
static SimpleStringList database_exclude_patterns = {NULL, NULL}
 
static SimpleStringList database_exclude_names = {NULL, NULL}
 

Macro Definition Documentation

◆ PG_AUTHID

#define PG_AUTHID   "pg_authid"

Definition at line 119 of file pg_dumpall.c.

◆ PG_ROLES

#define PG_ROLES   "pg_roles "

Definition at line 120 of file pg_dumpall.c.

◆ PGDUMP_VERSIONSTR

#define PGDUMP_VERSIONSTR   "pg_dump (PostgreSQL) " PG_VERSION "\n"

Definition at line 35 of file pg_dumpall.c.

◆ SH_DECLARE

#define SH_DECLARE

Definition at line 54 of file pg_dumpall.c.

◆ SH_DEFINE

#define SH_DEFINE

Definition at line 55 of file pg_dumpall.c.

◆ SH_ELEMENT_TYPE

#define SH_ELEMENT_TYPE   RoleNameEntry

Definition at line 45 of file pg_dumpall.c.

◆ SH_EQUAL

#define SH_EQUAL (   tb,
  a,
  b 
)    (strcmp(a, b) == 0)

Definition at line 49 of file pg_dumpall.c.

◆ SH_GET_HASH

#define SH_GET_HASH (   tb,
  a 
)    (a)->hashval

Definition at line 51 of file pg_dumpall.c.

◆ SH_HASH_KEY

#define SH_HASH_KEY (   tb,
  key 
)    hash_string(key)

Definition at line 48 of file pg_dumpall.c.

◆ SH_KEY

#define SH_KEY   rolename

Definition at line 47 of file pg_dumpall.c.

◆ SH_KEY_TYPE

#define SH_KEY_TYPE   char *

Definition at line 46 of file pg_dumpall.c.

◆ SH_PREFIX

#define SH_PREFIX   rolename

Definition at line 44 of file pg_dumpall.c.

◆ SH_RAW_ALLOCATOR

#define SH_RAW_ALLOCATOR   pg_malloc0

Definition at line 53 of file pg_dumpall.c.

◆ SH_SCOPE

#define SH_SCOPE   static inline

Definition at line 52 of file pg_dumpall.c.

◆ SH_STORE_HASH

#define SH_STORE_HASH

Definition at line 50 of file pg_dumpall.c.

Function Documentation

◆ buildShSecLabels()

static void buildShSecLabels ( PGconn conn,
const char *  catalog_name,
Oid  objectId,
const char *  objtype,
const char *  objname,
PQExpBuffer  buffer 
)
static

Definition at line 1836 of file pg_dumpall.c.

1839{
1841 PGresult *res;
1842
1843 buildShSecLabelQuery(catalog_name, objectId, sql);
1844 res = executeQuery(conn, sql->data);
1845 emitShSecLabels(conn, res, buffer, objtype, objname);
1846
1847 PQclear(res);
1848 destroyPQExpBuffer(sql);
1849}
PGresult * executeQuery(PGconn *conn, const char *query)
Definition: connectdb.c:278
void buildShSecLabelQuery(const char *catalog_name, Oid objectId, PQExpBuffer sql)
Definition: dumputils.c:640
void emitShSecLabels(PGconn *conn, PGresult *res, PQExpBuffer buffer, const char *objtype, const char *objname)
Definition: dumputils.c:658
void PQclear(PGresult *res)
Definition: fe-exec.c:721
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:72
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:114
PGconn * conn
Definition: streamutil.c:52

References buildShSecLabelQuery(), conn, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), emitShSecLabels(), executeQuery(), and PQclear().

Referenced by dumpRoles(), and dumpTablespaces().

◆ dropDBs()

static void dropDBs ( PGconn conn)
static

Definition at line 1473 of file pg_dumpall.c.

1474{
1475 PGresult *res;
1476 int i;
1477
1478 /*
1479 * Skip databases marked not datallowconn, since we'd be unable to connect
1480 * to them anyway. This must agree with dumpDatabases().
1481 */
1482 res = executeQuery(conn,
1483 "SELECT datname "
1484 "FROM pg_database d "
1485 "WHERE datallowconn AND datconnlimit != -2 "
1486 "ORDER BY datname");
1487
1488 if (PQntuples(res) > 0)
1489 fprintf(OPF, "--\n-- Drop databases (except postgres and template1)\n--\n\n");
1490
1491 for (i = 0; i < PQntuples(res); i++)
1492 {
1493 char *dbname = PQgetvalue(res, i, 0);
1494
1495 /*
1496 * Skip "postgres" and "template1"; dumpDatabases() will deal with
1497 * them specially. Also, be sure to skip "template0", even if for
1498 * some reason it's not marked !datallowconn.
1499 */
1500 if (strcmp(dbname, "template1") != 0 &&
1501 strcmp(dbname, "template0") != 0 &&
1502 strcmp(dbname, "postgres") != 0)
1503 {
1504 fprintf(OPF, "DROP DATABASE %s%s;\n",
1505 if_exists ? "IF EXISTS " : "",
1506 fmtId(dbname));
1507 }
1508 }
1509
1510 PQclear(res);
1511
1512 fprintf(OPF, "\n\n");
1513}
#define fprintf(file, fmt, msg)
Definition: cubescan.l:21
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3876
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3481
int i
Definition: isn.c:77
static int if_exists
Definition: pg_dumpall.c:94
static FILE * OPF
Definition: pg_dumpall.c:122
char * dbname
Definition: streamutil.c:49
const char * fmtId(const char *rawid)
Definition: string_utils.c:248

References conn, dbname, executeQuery(), fmtId(), fprintf, i, if_exists, OPF, PQclear(), PQgetvalue(), and PQntuples().

Referenced by main().

◆ dropRoles()

static void dropRoles ( PGconn conn)
static

Definition at line 777 of file pg_dumpall.c.

778{
780 PGresult *res;
781 int i_rolname;
782 int i;
783
784 if (server_version >= 90600)
786 "SELECT rolname "
787 "FROM %s "
788 "WHERE rolname !~ '^pg_' "
789 "ORDER BY 1", role_catalog);
790 else
792 "SELECT rolname "
793 "FROM %s "
794 "ORDER BY 1", role_catalog);
795
796 res = executeQuery(conn, buf->data);
797
798 i_rolname = PQfnumber(res, "rolname");
799
800 if (PQntuples(res) > 0)
801 fprintf(OPF, "--\n-- Drop roles\n--\n\n");
802
803 for (i = 0; i < PQntuples(res); i++)
804 {
805 const char *rolename;
806
807 rolename = PQgetvalue(res, i, i_rolname);
808
809 fprintf(OPF, "DROP ROLE %s%s;\n",
810 if_exists ? "IF EXISTS " : "",
811 fmtId(rolename));
812 }
813
814 PQclear(res);
816
817 fprintf(OPF, "\n\n");
818}
int PQfnumber(const PGresult *res, const char *field_name)
Definition: fe-exec.c:3589
static int server_version
Definition: pg_dumpall.c:113
static char role_catalog[10]
Definition: pg_dumpall.c:118
static char * buf
Definition: pg_test_fsync.c:72
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:235

References buf, conn, createPQExpBuffer(), destroyPQExpBuffer(), executeQuery(), fmtId(), fprintf, i, if_exists, OPF, PQclear(), PQfnumber(), PQgetvalue(), PQntuples(), printfPQExpBuffer(), role_catalog, and server_version.

Referenced by main().

◆ dropTablespaces()

static void dropTablespaces ( PGconn conn)
static

Definition at line 1334 of file pg_dumpall.c.

1335{
1336 PGresult *res;
1337 int i;
1338
1339 /*
1340 * Get all tablespaces except built-in ones (which we assume are named
1341 * pg_xxx)
1342 */
1343 res = executeQuery(conn, "SELECT spcname "
1344 "FROM pg_catalog.pg_tablespace "
1345 "WHERE spcname !~ '^pg_' "
1346 "ORDER BY 1");
1347
1348 if (PQntuples(res) > 0)
1349 fprintf(OPF, "--\n-- Drop tablespaces\n--\n\n");
1350
1351 for (i = 0; i < PQntuples(res); i++)
1352 {
1353 char *spcname = PQgetvalue(res, i, 0);
1354
1355 fprintf(OPF, "DROP TABLESPACE %s%s;\n",
1356 if_exists ? "IF EXISTS " : "",
1357 fmtId(spcname));
1358 }
1359
1360 PQclear(res);
1361
1362 fprintf(OPF, "\n\n");
1363}

References conn, executeQuery(), fmtId(), fprintf, i, if_exists, OPF, PQclear(), PQgetvalue(), and PQntuples().

Referenced by main().

◆ dumpDatabases()

static void dumpDatabases ( PGconn conn,
ArchiveFormat  archDumpFormat 
)
static

Definition at line 1616 of file pg_dumpall.c.

1617{
1618 PGresult *res;
1619 int i;
1620 char db_subdir[MAXPGPATH];
1621 char dbfilepath[MAXPGPATH];
1622 FILE *map_file = NULL;
1623
1624 /*
1625 * Skip databases marked not datallowconn, since we'd be unable to connect
1626 * to them anyway. This must agree with dropDBs().
1627 *
1628 * We arrange for template1 to be processed first, then we process other
1629 * DBs in alphabetical order. If we just did them all alphabetically, we
1630 * might find ourselves trying to drop the "postgres" database while still
1631 * connected to it. This makes trying to run the restore script while
1632 * connected to "template1" a bad idea, but there's no fixed order that
1633 * doesn't have some failure mode with --clean.
1634 */
1635 res = executeQuery(conn,
1636 "SELECT datname, oid "
1637 "FROM pg_database d "
1638 "WHERE datallowconn AND datconnlimit != -2 "
1639 "ORDER BY (datname <> 'template1'), datname");
1640
1641 if (archDumpFormat == archNull && PQntuples(res) > 0)
1642 fprintf(OPF, "--\n-- Databases\n--\n\n");
1643
1644 /*
1645 * If directory/tar/custom format is specified, create a subdirectory
1646 * under the main directory and each database dump file or subdirectory
1647 * will be created in that subdirectory by pg_dump.
1648 */
1649 if (archDumpFormat != archNull)
1650 {
1651 char map_file_path[MAXPGPATH];
1652
1653 snprintf(db_subdir, MAXPGPATH, "%s/databases", filename);
1654
1655 /* Create a subdirectory with 'databases' name under main directory. */
1656 if (mkdir(db_subdir, pg_dir_create_mode) != 0)
1657 pg_fatal("could not create subdirectory \"%s\": %m", db_subdir);
1658
1659 snprintf(map_file_path, MAXPGPATH, "%s/map.dat", filename);
1660
1661 /* Create a map file (to store dboid and dbname) */
1662 map_file = fopen(map_file_path, PG_BINARY_W);
1663 if (!map_file)
1664 pg_fatal("could not open map file: %s", strerror(errno));
1665 }
1666
1667 for (i = 0; i < PQntuples(res); i++)
1668 {
1669 char *dbname = PQgetvalue(res, i, 0);
1670 char *oid = PQgetvalue(res, i, 1);
1671 const char *create_opts = "";
1672 int ret;
1673
1674 /* Skip template0, even if it's not marked !datallowconn. */
1675 if (strcmp(dbname, "template0") == 0)
1676 continue;
1677
1678 /* Skip any explicitly excluded database */
1680 {
1681 pg_log_info("excluding database \"%s\"", dbname);
1682 continue;
1683 }
1684
1685 /*
1686 * If this is not a plain format dump, then append dboid and dbname to
1687 * the map.dat file.
1688 */
1689 if (archDumpFormat != archNull)
1690 {
1691 if (archDumpFormat == archCustom)
1692 snprintf(dbfilepath, MAXPGPATH, "\"%s\"/\"%s\".dmp", db_subdir, oid);
1693 else if (archDumpFormat == archTar)
1694 snprintf(dbfilepath, MAXPGPATH, "\"%s\"/\"%s\".tar", db_subdir, oid);
1695 else
1696 snprintf(dbfilepath, MAXPGPATH, "\"%s\"/\"%s\"", db_subdir, oid);
1697
1698 /* Put one line entry for dboid and dbname in map file. */
1699 fprintf(map_file, "%s %s\n", oid, dbname);
1700 }
1701
1702 pg_log_info("dumping database \"%s\"", dbname);
1703
1704 if (archDumpFormat == archNull)
1705 fprintf(OPF, "--\n-- Database \"%s\" dump\n--\n\n", dbname);
1706
1707 /*
1708 * We assume that "template1" and "postgres" already exist in the
1709 * target installation. dropDBs() won't have removed them, for fear
1710 * of removing the DB the restore script is initially connected to. If
1711 * --clean was specified, tell pg_dump to drop and recreate them;
1712 * otherwise we'll merely restore their contents. Other databases
1713 * should simply be created.
1714 */
1715 if (strcmp(dbname, "template1") == 0 || strcmp(dbname, "postgres") == 0)
1716 {
1717 if (output_clean)
1718 create_opts = "--clean --create";
1719 /* Since pg_dump won't emit a \connect command, we must */
1720 else if (archDumpFormat == archNull)
1721 fprintf(OPF, "\\connect %s\n\n", dbname);
1722 }
1723 else
1724 create_opts = "--create";
1725
1726 if (filename)
1727 fclose(OPF);
1728
1729 ret = runPgDump(dbname, create_opts, dbfilepath, archDumpFormat);
1730 if (ret != 0)
1731 pg_fatal("pg_dump failed on database \"%s\", exiting", dbname);
1732
1733 if (filename)
1734 {
1735 char global_path[MAXPGPATH];
1736
1737 if (archDumpFormat != archNull)
1738 snprintf(global_path, MAXPGPATH, "%s/global.dat", filename);
1739 else
1740 snprintf(global_path, MAXPGPATH, "%s", filename);
1741
1742 OPF = fopen(global_path, PG_BINARY_A);
1743 if (!OPF)
1744 pg_fatal("could not re-open the output file \"%s\": %m",
1745 global_path);
1746 }
1747 }
1748
1749 /* Close map file */
1750 if (archDumpFormat != archNull)
1751 fclose(map_file);
1752
1753 PQclear(res);
1754}
#define PG_BINARY_A
Definition: c.h:1245
#define PG_BINARY_W
Definition: c.h:1247
int pg_dir_create_mode
Definition: file_perm.c:18
#define pg_log_info(...)
Definition: logging.h:124
@ archTar
Definition: pg_backup.h:43
@ archCustom
Definition: pg_backup.h:42
@ archNull
Definition: pg_backup.h:44
#define pg_fatal(...)
#define MAXPGPATH
static SimpleStringList database_exclude_names
Definition: pg_dumpall.c:126
static bool output_clean
Definition: pg_dumpall.c:85
static char * filename
Definition: pg_dumpall.c:123
static int runPgDump(const char *dbname, const char *create_opts, char *dbfile, ArchiveFormat archDumpFormat)
Definition: pg_dumpall.c:1762
#define strerror
Definition: port.h:252
#define snprintf
Definition: port.h:239
bool simple_string_list_member(SimpleStringList *list, const char *val)
Definition: simple_list.c:87
#define mkdir(a, b)
Definition: win32_port.h:80

References archCustom, archNull, archTar, conn, database_exclude_names, dbname, executeQuery(), filename, fprintf, i, MAXPGPATH, mkdir, OPF, output_clean, PG_BINARY_A, PG_BINARY_W, pg_dir_create_mode, pg_fatal, pg_log_info, PQclear(), PQgetvalue(), PQntuples(), runPgDump(), simple_string_list_member(), snprintf, and strerror.

Referenced by main().

◆ dumpRoleGUCPrivs()

static void dumpRoleGUCPrivs ( PGconn conn)
static

Definition at line 1279 of file pg_dumpall.c.

1280{
1281 PGresult *res;
1282 int i;
1283
1284 /*
1285 * Get all parameters that have non-default acls defined.
1286 */
1287 res = executeQuery(conn, "SELECT parname, "
1288 "pg_catalog.pg_get_userbyid(" CppAsString2(BOOTSTRAP_SUPERUSERID) ") AS parowner, "
1289 "paracl, "
1290 "pg_catalog.acldefault('p', " CppAsString2(BOOTSTRAP_SUPERUSERID) ") AS acldefault "
1291 "FROM pg_catalog.pg_parameter_acl "
1292 "ORDER BY 1");
1293
1294 if (PQntuples(res) > 0)
1295 fprintf(OPF, "--\n-- Role privileges on configuration parameters\n--\n\n");
1296
1297 for (i = 0; i < PQntuples(res); i++)
1298 {
1300 char *parname = PQgetvalue(res, i, 0);
1301 char *parowner = PQgetvalue(res, i, 1);
1302 char *paracl = PQgetvalue(res, i, 2);
1303 char *acldefault = PQgetvalue(res, i, 3);
1304 char *fparname;
1305
1306 /* needed for buildACLCommands() */
1307 fparname = pg_strdup(fmtId(parname));
1308
1309 if (!buildACLCommands(fparname, NULL, NULL, "PARAMETER",
1310 paracl, acldefault,
1311 parowner, "", server_version, buf))
1312 {
1313 pg_log_error("could not parse ACL list (%s) for parameter \"%s\"",
1314 paracl, parname);
1315 PQfinish(conn);
1316 exit_nicely(1);
1317 }
1318
1319 fprintf(OPF, "%s", buf->data);
1320
1321 free(fparname);
1323 }
1324
1325 PQclear(res);
1326 fprintf(OPF, "\n\n");
1327}
Acl * acldefault(ObjectType objtype, Oid ownerId)
Definition: acl.c:787
#define CppAsString2(x)
Definition: c.h:363
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:66
void PQfinish(PGconn *conn)
Definition: fe-connect.c:5290
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
#define free(a)
Definition: header.h:65
#define pg_log_error(...)
Definition: logging.h:106
void exit_nicely(int code)

References acldefault(), buf, buildACLCommands(), conn, CppAsString2, createPQExpBuffer(), destroyPQExpBuffer(), executeQuery(), exit_nicely(), fmtId(), fprintf, free, i, OPF, pg_log_error, pg_strdup(), PQclear(), PQfinish(), PQgetvalue(), PQntuples(), and server_version.

Referenced by main().

◆ dumpRoleMembership()

static void dumpRoleMembership ( PGconn conn)
static

Definition at line 1029 of file pg_dumpall.c.

1030{
1032 PQExpBuffer optbuf = createPQExpBuffer();
1033 PGresult *res;
1034 int start = 0,
1035 end,
1036 total;
1037 bool dump_grantors;
1038 bool dump_grant_options;
1039 int i_role;
1040 int i_member;
1041 int i_grantor;
1042 int i_roleid;
1043 int i_memberid;
1044 int i_grantorid;
1045 int i_admin_option;
1046 int i_inherit_option;
1047 int i_set_option;
1048
1049 /*
1050 * Previous versions of PostgreSQL didn't used to track the grantor very
1051 * carefully in the backend, and the grantor could be any user even if
1052 * they didn't have ADMIN OPTION on the role, or a user that no longer
1053 * existed. To avoid dump and restore failures, don't dump the grantor
1054 * when talking to an old server version.
1055 *
1056 * Also, in older versions the roleid and/or member could be role OIDs
1057 * that no longer exist. If we find such cases, print a warning and skip
1058 * the entry.
1059 */
1060 dump_grantors = (PQserverVersion(conn) >= 160000);
1061
1062 /*
1063 * Previous versions of PostgreSQL also did not have grant-level options.
1064 */
1065 dump_grant_options = (server_version >= 160000);
1066
1067 /* Generate and execute query. */
1068 printfPQExpBuffer(buf, "SELECT ur.rolname AS role, "
1069 "um.rolname AS member, "
1070 "ug.rolname AS grantor, "
1071 "a.roleid AS roleid, "
1072 "a.member AS memberid, "
1073 "a.grantor AS grantorid, "
1074 "a.admin_option");
1075 if (dump_grant_options)
1076 appendPQExpBufferStr(buf, ", a.inherit_option, a.set_option");
1077 appendPQExpBuffer(buf, " FROM pg_auth_members a "
1078 "LEFT JOIN %s ur on ur.oid = a.roleid "
1079 "LEFT JOIN %s um on um.oid = a.member "
1080 "LEFT JOIN %s ug on ug.oid = a.grantor "
1081 "WHERE NOT (ur.rolname ~ '^pg_' AND um.rolname ~ '^pg_')"
1082 "ORDER BY 1,2,3", role_catalog, role_catalog, role_catalog);
1083 res = executeQuery(conn, buf->data);
1084 i_role = PQfnumber(res, "role");
1085 i_member = PQfnumber(res, "member");
1086 i_grantor = PQfnumber(res, "grantor");
1087 i_roleid = PQfnumber(res, "roleid");
1088 i_memberid = PQfnumber(res, "memberid");
1089 i_grantorid = PQfnumber(res, "grantorid");
1090 i_admin_option = PQfnumber(res, "admin_option");
1091 i_inherit_option = PQfnumber(res, "inherit_option");
1092 i_set_option = PQfnumber(res, "set_option");
1093
1094 if (PQntuples(res) > 0)
1095 fprintf(OPF, "--\n-- Role memberships\n--\n\n");
1096
1097 /*
1098 * We can't dump these GRANT commands in arbitrary order, because a role
1099 * that is named as a grantor must already have ADMIN OPTION on the role
1100 * for which it is granting permissions, except for the bootstrap
1101 * superuser, who can always be named as the grantor.
1102 *
1103 * We handle this by considering these grants role by role. For each role,
1104 * we initially consider the only allowable grantor to be the bootstrap
1105 * superuser. Every time we grant ADMIN OPTION on the role to some user,
1106 * that user also becomes an allowable grantor. We make repeated passes
1107 * over the grants for the role, each time dumping those whose grantors
1108 * are allowable and which we haven't done yet. Eventually this should let
1109 * us dump all the grants.
1110 */
1111 total = PQntuples(res);
1112 while (start < total)
1113 {
1114 char *role = PQgetvalue(res, start, i_role);
1115 int i;
1116 bool *done;
1117 int remaining;
1118 int prev_remaining = 0;
1119 rolename_hash *ht;
1120
1121 /* If we hit a null roleid, we're done (nulls sort to the end). */
1122 if (PQgetisnull(res, start, i_role))
1123 {
1124 /* translator: %s represents a numeric role OID */
1125 pg_log_warning("found orphaned pg_auth_members entry for role %s",
1126 PQgetvalue(res, start, i_roleid));
1127 break;
1128 }
1129
1130 /* All memberships for a single role should be adjacent. */
1131 for (end = start; end < total; ++end)
1132 {
1133 char *otherrole;
1134
1135 otherrole = PQgetvalue(res, end, i_role);
1136 if (strcmp(role, otherrole) != 0)
1137 break;
1138 }
1139
1140 remaining = end - start;
1141 done = pg_malloc0(remaining * sizeof(bool));
1142 ht = rolename_create(remaining, NULL);
1143
1144 /*
1145 * Make repeated passes over the grants for this role until all have
1146 * been dumped.
1147 */
1148 while (remaining > 0)
1149 {
1150 /*
1151 * We should make progress on every iteration, because a notional
1152 * graph whose vertices are grants and whose edges point from
1153 * grantors to members should be connected and acyclic. If we fail
1154 * to make progress, either we or the server have messed up.
1155 */
1156 if (remaining == prev_remaining)
1157 {
1158 pg_log_error("could not find a legal dump ordering for memberships in role \"%s\"",
1159 role);
1160 PQfinish(conn);
1161 exit_nicely(1);
1162 }
1163 prev_remaining = remaining;
1164
1165 /* Make one pass over the grants for this role. */
1166 for (i = start; i < end; ++i)
1167 {
1168 char *member;
1169 char *admin_option;
1170 char *grantorid;
1171 char *grantor;
1172 char *set_option = "true";
1173 bool found;
1174
1175 /* If we already did this grant, don't do it again. */
1176 if (done[i - start])
1177 continue;
1178
1179 /* Complain about, then ignore, entries with orphaned OIDs. */
1180 if (PQgetisnull(res, i, i_member))
1181 {
1182 /* translator: %s represents a numeric role OID */
1183 pg_log_warning("found orphaned pg_auth_members entry for role %s",
1184 PQgetvalue(res, i, i_memberid));
1185 done[i - start] = true;
1186 --remaining;
1187 continue;
1188 }
1189 if (PQgetisnull(res, i, i_grantor))
1190 {
1191 /* translator: %s represents a numeric role OID */
1192 pg_log_warning("found orphaned pg_auth_members entry for role %s",
1193 PQgetvalue(res, i, i_grantorid));
1194 done[i - start] = true;
1195 --remaining;
1196 continue;
1197 }
1198
1199 member = PQgetvalue(res, i, i_member);
1200 grantor = PQgetvalue(res, i, i_grantor);
1201 grantorid = PQgetvalue(res, i, i_grantorid);
1202 admin_option = PQgetvalue(res, i, i_admin_option);
1203 if (dump_grant_options)
1204 set_option = PQgetvalue(res, i, i_set_option);
1205
1206 /*
1207 * If we're not dumping grantors or if the grantor is the
1208 * bootstrap superuser, it's fine to dump this now. Otherwise,
1209 * it's got to be someone who has already been granted ADMIN
1210 * OPTION.
1211 */
1212 if (dump_grantors &&
1213 atooid(grantorid) != BOOTSTRAP_SUPERUSERID &&
1214 rolename_lookup(ht, grantor) == NULL)
1215 continue;
1216
1217 /* Remember that we did this so that we don't do it again. */
1218 done[i - start] = true;
1219 --remaining;
1220
1221 /*
1222 * If ADMIN OPTION is being granted, remember that grants
1223 * listing this member as the grantor can now be dumped.
1224 */
1225 if (*admin_option == 't')
1226 rolename_insert(ht, member, &found);
1227
1228 /* Generate the actual GRANT statement. */
1229 resetPQExpBuffer(optbuf);
1230 fprintf(OPF, "GRANT %s", fmtId(role));
1231 fprintf(OPF, " TO %s", fmtId(member));
1232 if (*admin_option == 't')
1233 appendPQExpBufferStr(optbuf, "ADMIN OPTION");
1234 if (dump_grant_options)
1235 {
1236 char *inherit_option;
1237
1238 if (optbuf->data[0] != '\0')
1239 appendPQExpBufferStr(optbuf, ", ");
1240 inherit_option = PQgetvalue(res, i, i_inherit_option);
1241 appendPQExpBuffer(optbuf, "INHERIT %s",
1242 *inherit_option == 't' ?
1243 "TRUE" : "FALSE");
1244 }
1245 if (*set_option != 't')
1246 {
1247 if (optbuf->data[0] != '\0')
1248 appendPQExpBufferStr(optbuf, ", ");
1249 appendPQExpBufferStr(optbuf, "SET FALSE");
1250 }
1251 if (optbuf->data[0] != '\0')
1252 fprintf(OPF, " WITH %s", optbuf->data);
1253 if (dump_grantors)
1254 fprintf(OPF, " GRANTED BY %s", fmtId(grantor));
1255 fprintf(OPF, ";\n");
1256 }
1257 }
1258
1259 rolename_destroy(ht);
1260 pg_free(done);
1261 start = end;
1262 }
1263
1264 PQclear(res);
1266
1267 fprintf(OPF, "\n\n");
1268}
int PQserverVersion(const PGconn *conn)
Definition: fe-connect.c:7609
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3901
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
void pg_free(void *ptr)
Definition: fe_memutils.c:105
return str start
int remaining
Definition: informix.c:692
bool set_option
bool inherit_option
bool admin_option
#define pg_log_warning(...)
Definition: pgfnames.c:24
#define atooid(x)
Definition: postgres_ext.h:41
void resetPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:146
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:265
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:367

References admin_option, appendPQExpBuffer(), appendPQExpBufferStr(), atooid, buf, conn, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), executeQuery(), exit_nicely(), fmtId(), fprintf, i, inherit_option, OPF, pg_free(), pg_log_error, pg_log_warning, pg_malloc0(), PQclear(), PQfinish(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), PQserverVersion(), printfPQExpBuffer(), remaining, resetPQExpBuffer(), role_catalog, server_version, set_option, and start.

Referenced by main().

◆ dumpRoles()

static void dumpRoles ( PGconn conn)
static

Definition at line 824 of file pg_dumpall.c.

825{
827 PGresult *res;
828 int i_oid,
829 i_rolname,
830 i_rolsuper,
831 i_rolinherit,
832 i_rolcreaterole,
833 i_rolcreatedb,
834 i_rolcanlogin,
835 i_rolconnlimit,
836 i_rolpassword,
837 i_rolvaliduntil,
838 i_rolreplication,
839 i_rolbypassrls,
840 i_rolcomment,
841 i_is_current_user;
842 int i;
843
844 /*
845 * Notes: rolconfig is dumped later, and pg_authid must be used for
846 * extracting rolcomment regardless of role_catalog.
847 */
848 if (server_version >= 90600)
850 "SELECT oid, rolname, rolsuper, rolinherit, "
851 "rolcreaterole, rolcreatedb, "
852 "rolcanlogin, rolconnlimit, rolpassword, "
853 "rolvaliduntil, rolreplication, rolbypassrls, "
854 "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, "
855 "rolname = current_user AS is_current_user "
856 "FROM %s "
857 "WHERE rolname !~ '^pg_' "
858 "ORDER BY 2", role_catalog);
859 else if (server_version >= 90500)
861 "SELECT oid, rolname, rolsuper, rolinherit, "
862 "rolcreaterole, rolcreatedb, "
863 "rolcanlogin, rolconnlimit, rolpassword, "
864 "rolvaliduntil, rolreplication, rolbypassrls, "
865 "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, "
866 "rolname = current_user AS is_current_user "
867 "FROM %s "
868 "ORDER BY 2", role_catalog);
869 else
871 "SELECT oid, rolname, rolsuper, rolinherit, "
872 "rolcreaterole, rolcreatedb, "
873 "rolcanlogin, rolconnlimit, rolpassword, "
874 "rolvaliduntil, rolreplication, "
875 "false as rolbypassrls, "
876 "pg_catalog.shobj_description(oid, 'pg_authid') as rolcomment, "
877 "rolname = current_user AS is_current_user "
878 "FROM %s "
879 "ORDER BY 2", role_catalog);
880
881 res = executeQuery(conn, buf->data);
882
883 i_oid = PQfnumber(res, "oid");
884 i_rolname = PQfnumber(res, "rolname");
885 i_rolsuper = PQfnumber(res, "rolsuper");
886 i_rolinherit = PQfnumber(res, "rolinherit");
887 i_rolcreaterole = PQfnumber(res, "rolcreaterole");
888 i_rolcreatedb = PQfnumber(res, "rolcreatedb");
889 i_rolcanlogin = PQfnumber(res, "rolcanlogin");
890 i_rolconnlimit = PQfnumber(res, "rolconnlimit");
891 i_rolpassword = PQfnumber(res, "rolpassword");
892 i_rolvaliduntil = PQfnumber(res, "rolvaliduntil");
893 i_rolreplication = PQfnumber(res, "rolreplication");
894 i_rolbypassrls = PQfnumber(res, "rolbypassrls");
895 i_rolcomment = PQfnumber(res, "rolcomment");
896 i_is_current_user = PQfnumber(res, "is_current_user");
897
898 if (PQntuples(res) > 0)
899 fprintf(OPF, "--\n-- Roles\n--\n\n");
900
901 for (i = 0; i < PQntuples(res); i++)
902 {
903 const char *rolename;
904 Oid auth_oid;
905
906 auth_oid = atooid(PQgetvalue(res, i, i_oid));
907 rolename = PQgetvalue(res, i, i_rolname);
908
909 if (strncmp(rolename, "pg_", 3) == 0)
910 {
911 pg_log_warning("role name starting with \"pg_\" skipped (%s)",
912 rolename);
913 continue;
914 }
915
917
918 if (binary_upgrade)
919 {
920 appendPQExpBufferStr(buf, "\n-- For binary upgrade, must preserve pg_authid.oid\n");
922 "SELECT pg_catalog.binary_upgrade_set_next_pg_authid_oid('%u'::pg_catalog.oid);\n\n",
923 auth_oid);
924 }
925
926 /*
927 * We dump CREATE ROLE followed by ALTER ROLE to ensure that the role
928 * will acquire the right properties even if it already exists (ie, it
929 * won't hurt for the CREATE to fail). This is particularly important
930 * for the role we are connected as, since even with --clean we will
931 * have failed to drop it. binary_upgrade cannot generate any errors,
932 * so we assume the current role is already created.
933 */
934 if (!binary_upgrade ||
935 strcmp(PQgetvalue(res, i, i_is_current_user), "f") == 0)
936 appendPQExpBuffer(buf, "CREATE ROLE %s;\n", fmtId(rolename));
937 appendPQExpBuffer(buf, "ALTER ROLE %s WITH", fmtId(rolename));
938
939 if (strcmp(PQgetvalue(res, i, i_rolsuper), "t") == 0)
940 appendPQExpBufferStr(buf, " SUPERUSER");
941 else
942 appendPQExpBufferStr(buf, " NOSUPERUSER");
943
944 if (strcmp(PQgetvalue(res, i, i_rolinherit), "t") == 0)
945 appendPQExpBufferStr(buf, " INHERIT");
946 else
947 appendPQExpBufferStr(buf, " NOINHERIT");
948
949 if (strcmp(PQgetvalue(res, i, i_rolcreaterole), "t") == 0)
950 appendPQExpBufferStr(buf, " CREATEROLE");
951 else
952 appendPQExpBufferStr(buf, " NOCREATEROLE");
953
954 if (strcmp(PQgetvalue(res, i, i_rolcreatedb), "t") == 0)
955 appendPQExpBufferStr(buf, " CREATEDB");
956 else
957 appendPQExpBufferStr(buf, " NOCREATEDB");
958
959 if (strcmp(PQgetvalue(res, i, i_rolcanlogin), "t") == 0)
960 appendPQExpBufferStr(buf, " LOGIN");
961 else
962 appendPQExpBufferStr(buf, " NOLOGIN");
963
964 if (strcmp(PQgetvalue(res, i, i_rolreplication), "t") == 0)
965 appendPQExpBufferStr(buf, " REPLICATION");
966 else
967 appendPQExpBufferStr(buf, " NOREPLICATION");
968
969 if (strcmp(PQgetvalue(res, i, i_rolbypassrls), "t") == 0)
970 appendPQExpBufferStr(buf, " BYPASSRLS");
971 else
972 appendPQExpBufferStr(buf, " NOBYPASSRLS");
973
974 if (strcmp(PQgetvalue(res, i, i_rolconnlimit), "-1") != 0)
975 appendPQExpBuffer(buf, " CONNECTION LIMIT %s",
976 PQgetvalue(res, i, i_rolconnlimit));
977
978
979 if (!PQgetisnull(res, i, i_rolpassword) && !no_role_passwords)
980 {
981 appendPQExpBufferStr(buf, " PASSWORD ");
982 appendStringLiteralConn(buf, PQgetvalue(res, i, i_rolpassword), conn);
983 }
984
985 if (!PQgetisnull(res, i, i_rolvaliduntil))
986 appendPQExpBuffer(buf, " VALID UNTIL '%s'",
987 PQgetvalue(res, i, i_rolvaliduntil));
988
990
991 if (!no_comments && !PQgetisnull(res, i, i_rolcomment))
992 {
993 appendPQExpBuffer(buf, "COMMENT ON ROLE %s IS ", fmtId(rolename));
994 appendStringLiteralConn(buf, PQgetvalue(res, i, i_rolcomment), conn);
996 }
997
999 buildShSecLabels(conn, "pg_authid", auth_oid,
1000 "ROLE", rolename,
1001 buf);
1002
1003 fprintf(OPF, "%s", buf->data);
1004 }
1005
1006 /*
1007 * Dump configuration settings for roles after all roles have been dumped.
1008 * We do it this way because config settings for roles could mention the
1009 * names of other roles.
1010 */
1011 for (i = 0; i < PQntuples(res); i++)
1012 dumpUserConfig(conn, PQgetvalue(res, i, i_rolname));
1013
1014 PQclear(res);
1015
1016 fprintf(OPF, "\n\n");
1017
1019}
static int no_role_passwords
Definition: pg_dumpall.c:109
static int binary_upgrade
Definition: pg_dumpall.c:90
static void dumpUserConfig(PGconn *conn, const char *username)
Definition: pg_dumpall.c:1520
static int no_comments
Definition: pg_dumpall.c:99
static int no_security_labels
Definition: pg_dumpall.c:102
static void buildShSecLabels(PGconn *conn, const char *catalog_name, Oid objectId, const char *objtype, const char *objname, PQExpBuffer buffer)
Definition: pg_dumpall.c:1836
unsigned int Oid
Definition: postgres_ext.h:30
void appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn)
Definition: string_utils.c:446

References appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralConn(), atooid, binary_upgrade, buf, buildShSecLabels(), conn, createPQExpBuffer(), destroyPQExpBuffer(), dumpUserConfig(), executeQuery(), fmtId(), fprintf, i, no_comments, no_role_passwords, no_security_labels, OPF, pg_log_warning, PQclear(), PQfnumber(), PQgetisnull(), PQgetvalue(), PQntuples(), printfPQExpBuffer(), resetPQExpBuffer(), role_catalog, and server_version.

Referenced by main().

◆ dumpTablespaces()

static void dumpTablespaces ( PGconn conn)
static

Definition at line 1369 of file pg_dumpall.c.

1370{
1371 PGresult *res;
1372 int i;
1373
1374 /*
1375 * Get all tablespaces except built-in ones (which we assume are named
1376 * pg_xxx)
1377 */
1378 res = executeQuery(conn, "SELECT oid, spcname, "
1379 "pg_catalog.pg_get_userbyid(spcowner) AS spcowner, "
1380 "pg_catalog.pg_tablespace_location(oid), "
1381 "spcacl, acldefault('t', spcowner) AS acldefault, "
1382 "array_to_string(spcoptions, ', '),"
1383 "pg_catalog.shobj_description(oid, 'pg_tablespace') "
1384 "FROM pg_catalog.pg_tablespace "
1385 "WHERE spcname !~ '^pg_' "
1386 "ORDER BY 1");
1387
1388 if (PQntuples(res) > 0)
1389 fprintf(OPF, "--\n-- Tablespaces\n--\n\n");
1390
1391 for (i = 0; i < PQntuples(res); i++)
1392 {
1394 Oid spcoid = atooid(PQgetvalue(res, i, 0));
1395 char *spcname = PQgetvalue(res, i, 1);
1396 char *spcowner = PQgetvalue(res, i, 2);
1397 char *spclocation = PQgetvalue(res, i, 3);
1398 char *spcacl = PQgetvalue(res, i, 4);
1399 char *acldefault = PQgetvalue(res, i, 5);
1400 char *spcoptions = PQgetvalue(res, i, 6);
1401 char *spccomment = PQgetvalue(res, i, 7);
1402 char *fspcname;
1403
1404 /* needed for buildACLCommands() */
1405 fspcname = pg_strdup(fmtId(spcname));
1406
1407 if (binary_upgrade)
1408 {
1409 appendPQExpBufferStr(buf, "\n-- For binary upgrade, must preserve pg_tablespace oid\n");
1410 appendPQExpBuffer(buf, "SELECT pg_catalog.binary_upgrade_set_next_pg_tablespace_oid('%u'::pg_catalog.oid);\n", spcoid);
1411 }
1412
1413 appendPQExpBuffer(buf, "CREATE TABLESPACE %s", fspcname);
1414 appendPQExpBuffer(buf, " OWNER %s", fmtId(spcowner));
1415
1416 appendPQExpBufferStr(buf, " LOCATION ");
1417
1418 /*
1419 * In-place tablespaces use a relative path, and need to be dumped
1420 * with an empty string as location.
1421 */
1422 if (is_absolute_path(spclocation))
1423 appendStringLiteralConn(buf, spclocation, conn);
1424 else
1426
1427 appendPQExpBufferStr(buf, ";\n");
1428
1429 if (spcoptions && spcoptions[0] != '\0')
1430 appendPQExpBuffer(buf, "ALTER TABLESPACE %s SET (%s);\n",
1431 fspcname, spcoptions);
1432
1433 /* tablespaces can't have initprivs */
1434
1435 if (!skip_acls &&
1436 !buildACLCommands(fspcname, NULL, NULL, "TABLESPACE",
1437 spcacl, acldefault,
1438 spcowner, "", server_version, buf))
1439 {
1440 pg_log_error("could not parse ACL list (%s) for tablespace \"%s\"",
1441 spcacl, spcname);
1442 PQfinish(conn);
1443 exit_nicely(1);
1444 }
1445
1446 if (!no_comments && spccomment && spccomment[0] != '\0')
1447 {
1448 appendPQExpBuffer(buf, "COMMENT ON TABLESPACE %s IS ", fspcname);
1449 appendStringLiteralConn(buf, spccomment, conn);
1450 appendPQExpBufferStr(buf, ";\n");
1451 }
1452
1453 if (!no_security_labels)
1454 buildShSecLabels(conn, "pg_tablespace", spcoid,
1455 "TABLESPACE", spcname,
1456 buf);
1457
1458 fprintf(OPF, "%s", buf->data);
1459
1460 free(fspcname);
1462 }
1463
1464 PQclear(res);
1465 fprintf(OPF, "\n\n");
1466}
static bool skip_acls
Definition: pg_dumpall.c:86
#define is_absolute_path(filename)
Definition: port.h:104

References acldefault(), appendPQExpBuffer(), appendPQExpBufferStr(), appendStringLiteralConn(), atooid, binary_upgrade, buf, buildACLCommands(), buildShSecLabels(), conn, createPQExpBuffer(), destroyPQExpBuffer(), executeQuery(), exit_nicely(), fmtId(), fprintf, free, i, is_absolute_path, no_comments, no_security_labels, OPF, pg_log_error, pg_strdup(), PQclear(), PQfinish(), PQgetvalue(), PQntuples(), server_version, and skip_acls.

Referenced by main().

◆ dumpTimestamp()

static void dumpTimestamp ( const char *  msg)
static

Definition at line 1879 of file pg_dumpall.c.

1880{
1881 char buf[64];
1882 time_t now = time(NULL);
1883
1884 if (strftime(buf, sizeof(buf), PGDUMP_STRFTIME_FMT, localtime(&now)) != 0)
1885 fprintf(OPF, "-- %s %s\n\n", msg, buf);
1886}
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1609
#define PGDUMP_STRFTIME_FMT
Definition: dumputils.h:33

References buf, fprintf, now(), OPF, and PGDUMP_STRFTIME_FMT.

Referenced by main().

◆ dumpUserConfig()

static void dumpUserConfig ( PGconn conn,
const char *  username 
)
static

Definition at line 1520 of file pg_dumpall.c.

1521{
1523 PGresult *res;
1524 static bool header_done = false;
1525
1526 printfPQExpBuffer(buf, "SELECT unnest(setconfig) FROM pg_db_role_setting "
1527 "WHERE setdatabase = 0 AND setrole = "
1528 "(SELECT oid FROM %s WHERE rolname = ",
1529 role_catalog);
1532
1533 res = executeQuery(conn, buf->data);
1534
1535 if (PQntuples(res) > 0)
1536 {
1537 if (!header_done)
1538 fprintf(OPF, "\n--\n-- User Configurations\n--\n");
1539 header_done = true;
1540
1541 fprintf(OPF, "\n--\n-- User Config \"%s\"\n--\n\n", username);
1542 }
1543
1544 for (int i = 0; i < PQntuples(res); i++)
1545 {
1548 "ROLE", username, NULL, NULL,
1549 buf);
1550 fprintf(OPF, "%s", buf->data);
1551 }
1552
1553 PQclear(res);
1554
1556}
void makeAlterConfigCommand(PGconn *conn, const char *configitem, const char *type, const char *name, const char *type2, const char *name2, PQExpBuffer buf)
Definition: dumputils.c:826
static char * username
Definition: initdb.c:153
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:378

References appendPQExpBufferChar(), appendStringLiteralConn(), buf, conn, createPQExpBuffer(), destroyPQExpBuffer(), executeQuery(), fprintf, i, makeAlterConfigCommand(), OPF, PQclear(), PQgetvalue(), PQntuples(), printfPQExpBuffer(), resetPQExpBuffer(), role_catalog, and username.

Referenced by dumpRoles().

◆ executeCommand()

static void executeCommand ( PGconn conn,
const char *  query 
)
static

Definition at line 1855 of file pg_dumpall.c.

1856{
1857 PGresult *res;
1858
1859 pg_log_info("executing %s", query);
1860
1861 res = PQexec(conn, query);
1862 if (!res ||
1864 {
1865 pg_log_error("query failed: %s", PQerrorMessage(conn));
1866 pg_log_error_detail("Query was: %s", query);
1867 PQfinish(conn);
1868 exit_nicely(1);
1869 }
1870
1871 PQclear(res);
1872}
char * PQerrorMessage(const PGconn *conn)
Definition: fe-connect.c:7619
ExecStatusType PQresultStatus(const PGresult *res)
Definition: fe-exec.c:3411
PGresult * PQexec(PGconn *conn, const char *query)
Definition: fe-exec.c:2262
@ PGRES_COMMAND_OK
Definition: libpq-fe.h:125
#define pg_log_error_detail(...)
Definition: logging.h:109

References conn, exit_nicely(), pg_log_error, pg_log_error_detail, pg_log_info, PGRES_COMMAND_OK, PQclear(), PQerrorMessage(), PQexec(), PQfinish(), and PQresultStatus().

Referenced by appendQualifiedRelation(), connect_slot(), main(), retrieve_objects(), and vacuum_one_database().

◆ expand_dbname_patterns()

static void expand_dbname_patterns ( PGconn conn,
SimpleStringList patterns,
SimpleStringList names 
)
static

Definition at line 1563 of file pg_dumpall.c.

1566{
1567 PQExpBuffer query;
1568 PGresult *res;
1569
1570 if (patterns->head == NULL)
1571 return; /* nothing to do */
1572
1573 query = createPQExpBuffer();
1574
1575 /*
1576 * The loop below runs multiple SELECTs, which might sometimes result in
1577 * duplicate entries in the name list, but we don't care, since all we're
1578 * going to do is test membership of the list.
1579 */
1580
1581 for (SimpleStringListCell *cell = patterns->head; cell; cell = cell->next)
1582 {
1583 int dotcnt;
1584
1586 "SELECT datname FROM pg_catalog.pg_database n\n");
1587 processSQLNamePattern(conn, query, cell->val, false,
1588 false, NULL, "datname", NULL, NULL, NULL,
1589 &dotcnt);
1590
1591 if (dotcnt > 0)
1592 {
1593 pg_log_error("improper qualified name (too many dotted names): %s",
1594 cell->val);
1595 PQfinish(conn);
1596 exit_nicely(1);
1597 }
1598
1599 res = executeQuery(conn, query->data);
1600 for (int i = 0; i < PQntuples(res); i++)
1601 {
1602 simple_string_list_append(names, PQgetvalue(res, i, 0));
1603 }
1604
1605 PQclear(res);
1606 resetPQExpBuffer(query);
1607 }
1608
1609 destroyPQExpBuffer(query);
1610}
void simple_string_list_append(SimpleStringList *list, const char *val)
Definition: simple_list.c:63
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)
struct SimpleStringListCell * next
Definition: simple_list.h:34
SimpleStringListCell * head
Definition: simple_list.h:42

References appendPQExpBufferStr(), conn, createPQExpBuffer(), PQExpBufferData::data, destroyPQExpBuffer(), executeQuery(), exit_nicely(), SimpleStringList::head, i, SimpleStringListCell::next, pg_log_error, PQclear(), PQfinish(), PQgetvalue(), PQntuples(), processSQLNamePattern(), resetPQExpBuffer(), and simple_string_list_append().

Referenced by main().

◆ help()

static void help ( void  )
static

Definition at line 696 of file pg_dumpall.c.

697{
698 printf(_("%s extracts a PostgreSQL database cluster based on specified dump format.\n\n"), progname);
699 printf(_("Usage:\n"));
700 printf(_(" %s [OPTION]...\n"), progname);
701
702 printf(_("\nGeneral options:\n"));
703 printf(_(" -f, --file=FILENAME output file name\n"));
704 printf(_(" -F, --format=c|d|t|p output file format (custom, directory, tar,\n"
705 " plain text (default))\n"));
706 printf(_(" -v, --verbose verbose mode\n"));
707 printf(_(" -V, --version output version information, then exit\n"));
708 printf(_(" --lock-wait-timeout=TIMEOUT fail after waiting TIMEOUT for a table lock\n"));
709 printf(_(" -?, --help show this help, then exit\n"));
710 printf(_("\nOptions controlling the output content:\n"));
711 printf(_(" -a, --data-only dump only the data, not the schema or statistics\n"));
712 printf(_(" -c, --clean clean (drop) databases before recreating\n"));
713 printf(_(" -E, --encoding=ENCODING dump the data in encoding ENCODING\n"));
714 printf(_(" -g, --globals-only dump only global objects, no databases\n"));
715 printf(_(" -O, --no-owner skip restoration of object ownership\n"));
716 printf(_(" -r, --roles-only dump only roles, no databases or tablespaces\n"));
717 printf(_(" -s, --schema-only dump only the schema, no data or statistics\n"));
718 printf(_(" -S, --superuser=NAME superuser user name to use in the dump\n"));
719 printf(_(" -t, --tablespaces-only dump only tablespaces, no databases or roles\n"));
720 printf(_(" -x, --no-privileges do not dump privileges (grant/revoke)\n"));
721 printf(_(" --binary-upgrade for use by upgrade utilities only\n"));
722 printf(_(" --column-inserts dump data as INSERT commands with column names\n"));
723 printf(_(" --disable-dollar-quoting disable dollar quoting, use SQL standard quoting\n"));
724 printf(_(" --disable-triggers disable triggers during data-only restore\n"));
725 printf(_(" --exclude-database=PATTERN exclude databases whose name matches PATTERN\n"));
726 printf(_(" --extra-float-digits=NUM override default setting for extra_float_digits\n"));
727 printf(_(" --filter=FILENAME exclude databases based on expressions in FILENAME\n"));
728 printf(_(" --if-exists use IF EXISTS when dropping objects\n"));
729 printf(_(" --inserts dump data as INSERT commands, rather than COPY\n"));
730 printf(_(" --load-via-partition-root load partitions via the root table\n"));
731 printf(_(" --no-comments do not dump comment commands\n"));
732 printf(_(" --no-data do not dump data\n"));
733 printf(_(" --no-policies do not dump row security policies\n"));
734 printf(_(" --no-publications do not dump publications\n"));
735 printf(_(" --no-role-passwords do not dump passwords for roles\n"));
736 printf(_(" --no-schema do not dump schema\n"));
737 printf(_(" --no-security-labels do not dump security label assignments\n"));
738 printf(_(" --no-statistics do not dump statistics\n"));
739 printf(_(" --no-subscriptions do not dump subscriptions\n"));
740 printf(_(" --no-sync do not wait for changes to be written safely to disk\n"));
741 printf(_(" --no-table-access-method do not dump table access methods\n"));
742 printf(_(" --no-tablespaces do not dump tablespace assignments\n"));
743 printf(_(" --no-toast-compression do not dump TOAST compression methods\n"));
744 printf(_(" --no-unlogged-table-data do not dump unlogged table data\n"));
745 printf(_(" --on-conflict-do-nothing add ON CONFLICT DO NOTHING to INSERT commands\n"));
746 printf(_(" --quote-all-identifiers quote all identifiers, even if not key words\n"));
747 printf(_(" --rows-per-insert=NROWS number of rows per INSERT; implies --inserts\n"));
748 printf(_(" --statistics-only dump only the statistics, not schema or data\n"));
749 printf(_(" --use-set-session-authorization\n"
750 " use SET SESSION AUTHORIZATION commands instead of\n"
751 " ALTER OWNER commands to set ownership\n"));
752 printf(_(" --with-data dump the data\n"));
753 printf(_(" --with-schema dump the schema\n"));
754 printf(_(" --with-statistics dump the statistics\n"));
755
756 printf(_("\nConnection options:\n"));
757 printf(_(" -d, --dbname=CONNSTR connect using connection string\n"));
758 printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
759 printf(_(" -l, --database=DBNAME alternative default database\n"));
760 printf(_(" -p, --port=PORT database server port number\n"));
761 printf(_(" -U, --username=NAME connect as specified database user\n"));
762 printf(_(" -w, --no-password never prompt for password\n"));
763 printf(_(" -W, --password force password prompt (should happen automatically)\n"));
764 printf(_(" --role=ROLENAME do SET ROLE before dump\n"));
765
766 printf(_("\nIf -f/--file is not used, then the SQL script will be written to the standard\n"
767 "output.\n\n"));
768 printf(_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
769 printf(_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
770}
#define _(x)
Definition: elog.c:91
const char * progname
Definition: main.c:44
#define printf(...)
Definition: port.h:245

References _, printf, and progname.

Referenced by main().

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 129 of file pg_dumpall.c.

130{
131 static struct option long_options[] = {
132 {"data-only", no_argument, NULL, 'a'},
133 {"clean", no_argument, NULL, 'c'},
134 {"encoding", required_argument, NULL, 'E'},
135 {"file", required_argument, NULL, 'f'},
136 {"globals-only", no_argument, NULL, 'g'},
137 {"host", required_argument, NULL, 'h'},
138 {"dbname", required_argument, NULL, 'd'},
139 {"database", required_argument, NULL, 'l'},
140 {"no-owner", no_argument, NULL, 'O'},
141 {"port", required_argument, NULL, 'p'},
142 {"roles-only", no_argument, NULL, 'r'},
143 {"schema-only", no_argument, NULL, 's'},
144 {"superuser", required_argument, NULL, 'S'},
145 {"tablespaces-only", no_argument, NULL, 't'},
146 {"username", required_argument, NULL, 'U'},
147 {"verbose", no_argument, NULL, 'v'},
148 {"no-password", no_argument, NULL, 'w'},
149 {"password", no_argument, NULL, 'W'},
150 {"no-privileges", no_argument, NULL, 'x'},
151 {"no-acl", no_argument, NULL, 'x'},
152 {"format", required_argument, NULL, 'F'},
153
154 /*
155 * the following options don't have an equivalent short option letter
156 */
157 {"attribute-inserts", no_argument, &column_inserts, 1},
158 {"binary-upgrade", no_argument, &binary_upgrade, 1},
159 {"column-inserts", no_argument, &column_inserts, 1},
160 {"disable-dollar-quoting", no_argument, &disable_dollar_quoting, 1},
161 {"disable-triggers", no_argument, &disable_triggers, 1},
162 {"exclude-database", required_argument, NULL, 6},
163 {"extra-float-digits", required_argument, NULL, 5},
164 {"if-exists", no_argument, &if_exists, 1},
165 {"inserts", no_argument, &inserts, 1},
166 {"lock-wait-timeout", required_argument, NULL, 2},
167 {"no-table-access-method", no_argument, &no_table_access_method, 1},
168 {"no-tablespaces", no_argument, &no_tablespaces, 1},
169 {"quote-all-identifiers", no_argument, &quote_all_identifiers, 1},
170 {"load-via-partition-root", no_argument, &load_via_partition_root, 1},
171 {"role", required_argument, NULL, 3},
172 {"use-set-session-authorization", no_argument, &use_setsessauth, 1},
173 {"no-comments", no_argument, &no_comments, 1},
174 {"no-data", no_argument, &no_data, 1},
175 {"no-policies", no_argument, &no_policies, 1},
176 {"no-publications", no_argument, &no_publications, 1},
177 {"no-role-passwords", no_argument, &no_role_passwords, 1},
178 {"no-schema", no_argument, &no_schema, 1},
179 {"no-security-labels", no_argument, &no_security_labels, 1},
180 {"no-subscriptions", no_argument, &no_subscriptions, 1},
181 {"no-statistics", no_argument, &no_statistics, 1},
182 {"no-sync", no_argument, NULL, 4},
183 {"no-toast-compression", no_argument, &no_toast_compression, 1},
184 {"no-unlogged-table-data", no_argument, &no_unlogged_table_data, 1},
185 {"with-data", no_argument, &with_data, 1},
186 {"with-schema", no_argument, &with_schema, 1},
187 {"with-statistics", no_argument, &with_statistics, 1},
188 {"on-conflict-do-nothing", no_argument, &on_conflict_do_nothing, 1},
189 {"rows-per-insert", required_argument, NULL, 7},
190 {"statistics-only", no_argument, &statistics_only, 1},
191 {"filter", required_argument, NULL, 8},
192
193 {NULL, 0, NULL, 0}
194 };
195
196 char *pghost = NULL;
197 char *pgport = NULL;
198 char *pguser = NULL;
199 char *pgdb = NULL;
200 char *use_role = NULL;
201 const char *dumpencoding = NULL;
202 ArchiveFormat archDumpFormat = archNull;
203 const char *formatName = "p";
204 trivalue prompt_password = TRI_DEFAULT;
205 bool data_only = false;
206 bool globals_only = false;
207 bool roles_only = false;
208 bool tablespaces_only = false;
209 PGconn *conn;
210 int encoding;
211 const char *std_strings;
212 int c,
213 ret;
214 int optindex;
215
216 pg_logging_init(argv[0]);
218 set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_dump"));
219 progname = get_progname(argv[0]);
220
221 if (argc > 1)
222 {
223 if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
224 {
225 help();
226 exit_nicely(0);
227 }
228 if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
229 {
230 puts("pg_dumpall (PostgreSQL) " PG_VERSION);
231 exit_nicely(0);
232 }
233 }
234
235 if ((ret = find_other_exec(argv[0], "pg_dump", PGDUMP_VERSIONSTR,
236 pg_dump_bin)) < 0)
237 {
238 char full_path[MAXPGPATH];
239
240 if (find_my_exec(argv[0], full_path) < 0)
241 strlcpy(full_path, progname, sizeof(full_path));
242
243 if (ret == -1)
244 pg_fatal("program \"%s\" is needed by %s but was not found in the same directory as \"%s\"",
245 "pg_dump", progname, full_path);
246 else
247 pg_fatal("program \"%s\" was found by \"%s\" but was not the same version as %s",
248 "pg_dump", full_path, progname);
249 }
250
252
253 while ((c = getopt_long(argc, argv, "acd:E:f:F:gh:l:Op:rsS:tU:vwWx", long_options, &optindex)) != -1)
254 {
255 switch (c)
256 {
257 case 'a':
258 data_only = true;
260 break;
261
262 case 'c':
263 output_clean = true;
264 break;
265
266 case 'd':
268 break;
269
270 case 'E':
271 dumpencoding = pg_strdup(optarg);
274 break;
275
276 case 'f':
280 break;
281 case 'F':
282 formatName = pg_strdup(optarg);
283 break;
284 case 'g':
285 globals_only = true;
286 break;
287
288 case 'h':
290 break;
291
292 case 'l':
293 pgdb = pg_strdup(optarg);
294 break;
295
296 case 'O':
298 break;
299
300 case 'p':
302 break;
303
304 case 'r':
305 roles_only = true;
306 break;
307
308 case 's':
310 break;
311
312 case 'S':
315 break;
316
317 case 't':
318 tablespaces_only = true;
319 break;
320
321 case 'U':
322 pguser = pg_strdup(optarg);
323 break;
324
325 case 'v':
326 verbose = true;
329 break;
330
331 case 'w':
332 prompt_password = TRI_NO;
334 break;
335
336 case 'W':
337 prompt_password = TRI_YES;
339 break;
340
341 case 'x':
342 skip_acls = true;
344 break;
345
346 case 0:
347 break;
348
349 case 2:
350 appendPQExpBufferStr(pgdumpopts, " --lock-wait-timeout ");
352 break;
353
354 case 3:
355 use_role = pg_strdup(optarg);
356 appendPQExpBufferStr(pgdumpopts, " --role ");
357 appendShellString(pgdumpopts, use_role);
358 break;
359
360 case 4:
361 dosync = false;
362 appendPQExpBufferStr(pgdumpopts, " --no-sync");
363 break;
364
365 case 5:
366 appendPQExpBufferStr(pgdumpopts, " --extra-float-digits ");
368 break;
369
370 case 6:
372 break;
373
374 case 7:
375 appendPQExpBufferStr(pgdumpopts, " --rows-per-insert ");
377 break;
378
379 case 8:
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 --exclude-database cannot be used together with -g/--globals-only, -r/--roles-only, or -t/--tablespaces-only");
403 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
404 exit_nicely(1);
405 }
406
407 /* Make sure the user hasn't specified a mix of globals-only options */
408 if (globals_only && roles_only)
409 {
410 pg_log_error("options -g/--globals-only and -r/--roles-only cannot be used together");
411 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
412 exit_nicely(1);
413 }
414
415 if (globals_only && tablespaces_only)
416 {
417 pg_log_error("options -g/--globals-only and -t/--tablespaces-only cannot be used together");
418 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
419 exit_nicely(1);
420 }
421
422 if (if_exists && !output_clean)
423 pg_fatal("option --if-exists requires option -c/--clean");
424
425 if (roles_only && tablespaces_only)
426 {
427 pg_log_error("options -r/--roles-only and -t/--tablespaces-only cannot be used together");
428 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
429 exit_nicely(1);
430 }
431
432 /* Get format for dump. */
433 archDumpFormat = parseDumpFormat(formatName);
434
435 /*
436 * If a non-plain format is specified, a file name is also required as the
437 * path to the main directory.
438 */
439 if (archDumpFormat != archNull &&
440 (!filename || strcmp(filename, "") == 0))
441 {
442 pg_log_error("option -F/--format=d|c|t requires option -f/--file");
443 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
444 exit_nicely(1);
445 }
446
447 /*
448 * If password values are not required in the dump, switch to using
449 * pg_roles which is equally useful, just more likely to have unrestricted
450 * access than pg_authid.
451 */
454 else
456
457 /* Add long options to the pg_dump argument list */
458 if (binary_upgrade)
459 appendPQExpBufferStr(pgdumpopts, " --binary-upgrade");
460 if (column_inserts)
461 appendPQExpBufferStr(pgdumpopts, " --column-inserts");
463 appendPQExpBufferStr(pgdumpopts, " --disable-dollar-quoting");
465 appendPQExpBufferStr(pgdumpopts, " --disable-triggers");
466 if (inserts)
467 appendPQExpBufferStr(pgdumpopts, " --inserts");
469 appendPQExpBufferStr(pgdumpopts, " --no-table-access-method");
470 if (no_tablespaces)
471 appendPQExpBufferStr(pgdumpopts, " --no-tablespaces");
473 appendPQExpBufferStr(pgdumpopts, " --quote-all-identifiers");
475 appendPQExpBufferStr(pgdumpopts, " --load-via-partition-root");
476 if (use_setsessauth)
477 appendPQExpBufferStr(pgdumpopts, " --use-set-session-authorization");
478 if (no_comments)
479 appendPQExpBufferStr(pgdumpopts, " --no-comments");
480 if (no_data)
481 appendPQExpBufferStr(pgdumpopts, " --no-data");
482 if (no_policies)
483 appendPQExpBufferStr(pgdumpopts, " --no-policies");
484 if (no_publications)
485 appendPQExpBufferStr(pgdumpopts, " --no-publications");
487 appendPQExpBufferStr(pgdumpopts, " --no-security-labels");
488 if (no_schema)
489 appendPQExpBufferStr(pgdumpopts, " --no-schema");
490 if (no_statistics)
491 appendPQExpBufferStr(pgdumpopts, " --no-statistics");
493 appendPQExpBufferStr(pgdumpopts, " --no-subscriptions");
495 appendPQExpBufferStr(pgdumpopts, " --no-toast-compression");
497 appendPQExpBufferStr(pgdumpopts, " --no-unlogged-table-data");
498 if (with_data)
499 appendPQExpBufferStr(pgdumpopts, " --with-data");
500 if (with_schema)
501 appendPQExpBufferStr(pgdumpopts, " --with-schema");
502 if (with_statistics)
503 appendPQExpBufferStr(pgdumpopts, " --with-statistics");
505 appendPQExpBufferStr(pgdumpopts, " --on-conflict-do-nothing");
506 if (statistics_only)
507 appendPQExpBufferStr(pgdumpopts, " --statistics-only");
508
509 /*
510 * Open the output file if required, otherwise use stdout. If required,
511 * then create new directory and global.dat file.
512 */
513 if (archDumpFormat != archNull)
514 {
515 char global_path[MAXPGPATH];
516
517 /* Create new directory or accept the empty existing directory. */
519
520 snprintf(global_path, MAXPGPATH, "%s/global.dat", filename);
521
522 OPF = fopen(global_path, PG_BINARY_W);
523 if (!OPF)
524 pg_fatal("could not open \"%s\": %m", global_path);
525 }
526 else if (filename)
527 {
528 OPF = fopen(filename, PG_BINARY_W);
529 if (!OPF)
530 pg_fatal("could not open output file \"%s\": %m",
531 filename);
532 }
533 else
534 OPF = stdout;
535
536 /*
537 * If there was a database specified on the command line, use that,
538 * otherwise try to connect to database "postgres", and failing that
539 * "template1".
540 */
541 if (pgdb)
542 {
543 conn = ConnectDatabase(pgdb, connstr, pghost, pgport, pguser,
544 prompt_password, false,
545 progname, &connstr, &server_version, NULL, NULL);
546
547 if (!conn)
548 pg_fatal("could not connect to database \"%s\"", pgdb);
549 }
550 else
551 {
552 conn = ConnectDatabase("postgres", connstr, pghost, pgport, pguser,
553 prompt_password, false,
554 progname, &connstr, &server_version, NULL, NULL);
555 if (!conn)
556 conn = ConnectDatabase("template1", connstr, pghost, pgport, pguser,
557 prompt_password, true,
558 progname, &connstr, &server_version, NULL, NULL);
559
560 if (!conn)
561 {
562 pg_log_error("could not connect to databases \"postgres\" or \"template1\"\n"
563 "Please specify an alternative database.");
564 pg_log_error_hint("Try \"%s --help\" for more information.", progname);
565 exit_nicely(1);
566 }
567 }
568
569 /*
570 * Get a list of database names that match the exclude patterns
571 */
574
575 /*
576 * Set the client encoding if requested.
577 */
578 if (dumpencoding)
579 {
580 if (PQsetClientEncoding(conn, dumpencoding) < 0)
581 pg_fatal("invalid client encoding \"%s\" specified",
582 dumpencoding);
583 }
584
585 /*
586 * Get the active encoding and the standard_conforming_strings setting, so
587 * we know how to escape strings.
588 */
591 std_strings = PQparameterStatus(conn, "standard_conforming_strings");
592 if (!std_strings)
593 std_strings = "off";
594
595 /* Set the role if requested */
596 if (use_role)
597 {
599
600 appendPQExpBuffer(query, "SET ROLE %s", fmtId(use_role));
601 executeCommand(conn, query->data);
602 destroyPQExpBuffer(query);
603 }
604
605 /* Force quoting of all identifiers if requested. */
607 executeCommand(conn, "SET quote_all_identifiers = true");
608
609 fprintf(OPF, "--\n-- PostgreSQL database cluster dump\n--\n\n");
610 if (verbose)
611 dumpTimestamp("Started on");
612
613 /*
614 * We used to emit \connect postgres here, but that served no purpose
615 * other than to break things for installations without a postgres
616 * database. Everything we're restoring here is a global, so whichever
617 * database we're connected to at the moment is fine.
618 */
619
620 /* Restore will need to write to the target cluster */
621 fprintf(OPF, "SET default_transaction_read_only = off;\n\n");
622
623 /* Replicate encoding and std_strings in output */
624 fprintf(OPF, "SET client_encoding = '%s';\n",
626 fprintf(OPF, "SET standard_conforming_strings = %s;\n", std_strings);
627 if (strcmp(std_strings, "off") == 0)
628 fprintf(OPF, "SET escape_string_warning = off;\n");
629 fprintf(OPF, "\n");
630
631 if (!data_only)
632 {
633 /*
634 * If asked to --clean, do that first. We can avoid detailed
635 * dependency analysis because databases never depend on each other,
636 * and tablespaces never depend on each other. Roles could have
637 * grants to each other, but DROP ROLE will clean those up silently.
638 */
639 if (output_clean)
640 {
641 if (!globals_only && !roles_only && !tablespaces_only)
642 dropDBs(conn);
643
644 if (!roles_only && !no_tablespaces)
646
647 if (!tablespaces_only)
649 }
650
651 /*
652 * Now create objects as requested. Be careful that option logic here
653 * is the same as for drops above.
654 */
655 if (!tablespaces_only)
656 {
657 /* Dump roles (users) */
659
660 /* Dump role memberships */
662
663 /* Dump role GUC privileges */
664 if (server_version >= 150000 && !skip_acls)
666 }
667
668 /* Dump tablespaces */
669 if (!roles_only && !no_tablespaces)
671 }
672
673 if (!globals_only && !roles_only && !tablespaces_only)
674 dumpDatabases(conn, archDumpFormat);
675
676 PQfinish(conn);
677
678 if (verbose)
679 dumpTimestamp("Completed on");
680 fprintf(OPF, "--\n-- PostgreSQL database cluster dump complete\n--\n\n");
681
682 if (filename)
683 {
684 fclose(OPF);
685
686 /* sync the resulting file, errors are not fatal */
687 if (dosync && (archDumpFormat == archNull))
688 (void) fsync_fname(filename, false);
689 }
690
691 exit_nicely(0);
692}
#define PG_TEXTDOMAIN(domain)
Definition: c.h:1185
int find_my_exec(const char *argv0, char *retpath)
Definition: exec.c:160
void set_pglocale_pgservice(const char *argv0, const char *app)
Definition: exec.c:429
int find_other_exec(const char *argv0, const char *target, const char *versionstr, char *retpath)
Definition: exec.c:310
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
void create_or_open_dir(const char *dirname)
Definition: dumputils.c:897
void fsync_fname(const char *fname, bool isdir)
Definition: fd.c:756
const char * PQparameterStatus(const PGconn *conn, const char *paramName)
Definition: fe-connect.c:7574
int PQclientEncoding(const PGconn *conn)
Definition: fe-connect.c:7709
int PQsetClientEncoding(PGconn *conn, const char *encoding)
Definition: fe-connect.c:7717
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
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_hint(...)
Definition: logging.h:112
@ PG_LOG_WARNING
Definition: logging.h:38
enum _archiveFormat ArchiveFormat
int32 encoding
Definition: pg_database.h:41
static void dumpTimestamp(const char *msg)
Definition: pg_dumpall.c:1879
static int on_conflict_do_nothing
Definition: pg_dumpall.c:115
static void dropTablespaces(PGconn *conn)
Definition: pg_dumpall.c:1334
static void expand_dbname_patterns(PGconn *conn, SimpleStringList *patterns, SimpleStringList *names)
Definition: pg_dumpall.c:1563
static PQExpBuffer pgdumpopts
Definition: pg_dumpall.c:83
static int statistics_only
Definition: pg_dumpall.c:116
static int no_table_access_method
Definition: pg_dumpall.c:96
static int no_unlogged_table_data
Definition: pg_dumpall.c:108
#define PG_AUTHID
Definition: pg_dumpall.c:119
static int no_policies
Definition: pg_dumpall.c:100
static int disable_triggers
Definition: pg_dumpall.c:93
static bool dosync
Definition: pg_dumpall.c:88
static const char * connstr
Definition: pg_dumpall.c:84
static SimpleStringList database_exclude_patterns
Definition: pg_dumpall.c:125
static void dumpTablespaces(PGconn *conn)
Definition: pg_dumpall.c:1369
static void dumpRoleMembership(PGconn *conn)
Definition: pg_dumpall.c:1029
static int with_data
Definition: pg_dumpall.c:110
static char pg_dump_bin[MAXPGPATH]
Definition: pg_dumpall.c:82
static int no_publications
Definition: pg_dumpall.c:101
static int with_schema
Definition: pg_dumpall.c:111
static ArchiveFormat parseDumpFormat(const char *format)
Definition: pg_dumpall.c:1953
static void dumpDatabases(PGconn *conn, ArchiveFormat archDumpFormat)
Definition: pg_dumpall.c:1616
static int disable_dollar_quoting
Definition: pg_dumpall.c:92
static int no_tablespaces
Definition: pg_dumpall.c:97
static int no_toast_compression
Definition: pg_dumpall.c:107
#define PG_ROLES
Definition: pg_dumpall.c:120
static int inserts
Definition: pg_dumpall.c:95
static void executeCommand(PGconn *conn, const char *query)
Definition: pg_dumpall.c:1855
static bool verbose
Definition: pg_dumpall.c:87
static void dumpRoleGUCPrivs(PGconn *conn)
Definition: pg_dumpall.c:1279
static int no_statistics
Definition: pg_dumpall.c:105
static void dumpRoles(PGconn *conn)
Definition: pg_dumpall.c:824
static void help(void)
Definition: pg_dumpall.c:696
static int use_setsessauth
Definition: pg_dumpall.c:98
static int no_data
Definition: pg_dumpall.c:103
static int load_via_partition_root
Definition: pg_dumpall.c:114
static int column_inserts
Definition: pg_dumpall.c:91
static void read_dumpall_filters(const char *filename, SimpleStringList *pattern)
Definition: pg_dumpall.c:1898
static void dropRoles(PGconn *conn)
Definition: pg_dumpall.c:777
static void dropDBs(PGconn *conn)
Definition: pg_dumpall.c:1473
static int no_schema
Definition: pg_dumpall.c:104
static int no_subscriptions
Definition: pg_dumpall.c:106
static int with_statistics
Definition: pg_dumpall.c:112
#define PGDUMP_VERSIONSTR
Definition: pg_dumpall.c:35
PGDLLIMPORT int optind
Definition: getopt.c:51
PGDLLIMPORT char * optarg
Definition: getopt.c:53
#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 sprintf
Definition: port.h:241
const char * get_progname(const char *argv0)
Definition: path.c:652
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
char * c
bool quote_all_identifiers
Definition: ruleutils.c:339
void setFmtEncoding(int encoding)
Definition: string_utils.c:69
void appendShellString(PQExpBuffer buf, const char *str)
Definition: string_utils.c:582
trivalue
Definition: vacuumlo.c:35
@ TRI_YES
Definition: vacuumlo.c:38
@ TRI_DEFAULT
Definition: vacuumlo.c:36
@ TRI_NO
Definition: vacuumlo.c:37

References appendPQExpBuffer(), appendPQExpBufferStr(), appendShellString(), archNull, binary_upgrade, column_inserts, conn, ConnectDatabase(), connstr, create_or_open_dir(), createPQExpBuffer(), PQExpBufferData::data, database_exclude_names, database_exclude_patterns, destroyPQExpBuffer(), disable_dollar_quoting, disable_triggers, dosync, dropDBs(), dropRoles(), dropTablespaces(), dumpDatabases(), dumpRoleGUCPrivs(), dumpRoleMembership(), dumpRoles(), dumpTablespaces(), dumpTimestamp(), encoding, executeCommand(), exit_nicely(), expand_dbname_patterns(), filename, find_my_exec(), find_other_exec(), fmtId(), fprintf, fsync_fname(), get_progname(), getopt_long(), SimpleStringList::head, help(), if_exists, inserts, load_via_partition_root, MAXPGPATH, no_argument, no_comments, no_data, no_policies, no_publications, no_role_passwords, no_schema, no_security_labels, no_statistics, no_subscriptions, no_table_access_method, no_tablespaces, no_toast_compression, no_unlogged_table_data, on_conflict_do_nothing, OPF, optarg, optind, output_clean, parseDumpFormat(), PG_AUTHID, PG_BINARY_W, pg_dump_bin, pg_encoding_to_char, pg_fatal, pg_log_error, pg_log_error_hint, PG_LOG_WARNING, pg_logging_increase_verbosity(), pg_logging_init(), pg_logging_set_level(), PG_ROLES, pg_strdup(), PG_TEXTDOMAIN, PGDUMP_VERSIONSTR, pgdumpopts, pghost, pgport, PQclientEncoding(), PQfinish(), PQparameterStatus(), PQsetClientEncoding(), progname, quote_all_identifiers, read_dumpall_filters(), required_argument, role_catalog, server_version, set_pglocale_pgservice(), setFmtEncoding(), simple_string_list_append(), skip_acls, snprintf, sprintf, statistics_only, generate_unaccent_rules::stdout, strlcpy(), TRI_DEFAULT, TRI_NO, TRI_YES, use_setsessauth, verbose, with_data, with_schema, and with_statistics.

◆ parseDumpFormat()

static ArchiveFormat parseDumpFormat ( const char *  format)
static

Definition at line 1953 of file pg_dumpall.c.

1954{
1955 ArchiveFormat archDumpFormat;
1956
1957 if (pg_strcasecmp(format, "c") == 0)
1958 archDumpFormat = archCustom;
1959 else if (pg_strcasecmp(format, "custom") == 0)
1960 archDumpFormat = archCustom;
1961 else if (pg_strcasecmp(format, "d") == 0)
1962 archDumpFormat = archDirectory;
1963 else if (pg_strcasecmp(format, "directory") == 0)
1964 archDumpFormat = archDirectory;
1965 else if (pg_strcasecmp(format, "p") == 0)
1966 archDumpFormat = archNull;
1967 else if (pg_strcasecmp(format, "plain") == 0)
1968 archDumpFormat = archNull;
1969 else if (pg_strcasecmp(format, "t") == 0)
1970 archDumpFormat = archTar;
1971 else if (pg_strcasecmp(format, "tar") == 0)
1972 archDumpFormat = archTar;
1973 else
1974 pg_fatal("unrecognized archive format \"%s\"; please specify \"c\", \"d\", \"p\", or \"t\"",
1975 format);
1976
1977 return archDumpFormat;
1978}
@ archDirectory
Definition: pg_backup.h:45
static char format
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36

References archCustom, archDirectory, archNull, archTar, format, pg_fatal, and pg_strcasecmp().

Referenced by main().

◆ read_dumpall_filters()

static void read_dumpall_filters ( const char *  filename,
SimpleStringList pattern 
)
static

Definition at line 1898 of file pg_dumpall.c.

1899{
1900 FilterStateData fstate;
1901 char *objname;
1902 FilterCommandType comtype;
1903 FilterObjectType objtype;
1904
1905 filter_init(&fstate, filename, exit);
1906
1907 while (filter_read_item(&fstate, &objname, &comtype, &objtype))
1908 {
1909 if (comtype == FILTER_COMMAND_TYPE_INCLUDE)
1910 {
1911 pg_log_filter_error(&fstate, _("%s filter for \"%s\" is not allowed"),
1912 "include",
1913 filter_object_type_name(objtype));
1914 exit_nicely(1);
1915 }
1916
1917 switch (objtype)
1918 {
1920 break;
1931 pg_log_filter_error(&fstate, _("unsupported filter object"));
1932 exit_nicely(1);
1933 break;
1934
1936 simple_string_list_append(pattern, objname);
1937 break;
1938 }
1939
1940 if (objname)
1941 free(objname);
1942 }
1943
1944 filter_free(&fstate);
1945}
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:389
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

References _, exit_nicely(), filename, FILTER_COMMAND_TYPE_INCLUDE, filter_free(), filter_init(), FILTER_OBJECT_TYPE_DATABASE, FILTER_OBJECT_TYPE_EXTENSION, FILTER_OBJECT_TYPE_FOREIGN_DATA, FILTER_OBJECT_TYPE_FUNCTION, FILTER_OBJECT_TYPE_INDEX, filter_object_type_name(), FILTER_OBJECT_TYPE_NONE, FILTER_OBJECT_TYPE_SCHEMA, FILTER_OBJECT_TYPE_TABLE, FILTER_OBJECT_TYPE_TABLE_AND_CHILDREN, FILTER_OBJECT_TYPE_TABLE_DATA, FILTER_OBJECT_TYPE_TABLE_DATA_AND_CHILDREN, FILTER_OBJECT_TYPE_TRIGGER, filter_read_item(), free, pg_log_filter_error(), and simple_string_list_append().

Referenced by main().

◆ runPgDump()

static int runPgDump ( const char *  dbname,
const char *  create_opts,
char *  dbfile,
ArchiveFormat  archDumpFormat 
)
static

Definition at line 1762 of file pg_dumpall.c.

1764{
1765 PQExpBufferData connstrbuf;
1766 PQExpBufferData cmd;
1767 int ret;
1768
1769 initPQExpBuffer(&connstrbuf);
1770 initPQExpBuffer(&cmd);
1771
1772 /*
1773 * If this is not a plain format dump, then append file name and dump
1774 * format to the pg_dump command to get archive dump.
1775 */
1776 if (archDumpFormat != archNull)
1777 {
1778 printfPQExpBuffer(&cmd, "\"%s\" -f %s %s", pg_dump_bin,
1779 dbfile, create_opts);
1780
1781 if (archDumpFormat == archDirectory)
1782 appendPQExpBufferStr(&cmd, " --format=directory ");
1783 else if (archDumpFormat == archCustom)
1784 appendPQExpBufferStr(&cmd, " --format=custom ");
1785 else if (archDumpFormat == archTar)
1786 appendPQExpBufferStr(&cmd, " --format=tar ");
1787 }
1788 else
1789 {
1790 printfPQExpBuffer(&cmd, "\"%s\" %s %s", pg_dump_bin,
1791 pgdumpopts->data, create_opts);
1792
1793 /*
1794 * If we have a filename, use the undocumented plain-append pg_dump
1795 * format.
1796 */
1797 if (filename)
1798 appendPQExpBufferStr(&cmd, " -Fa ");
1799 else
1800 appendPQExpBufferStr(&cmd, " -Fp ");
1801 }
1802
1803 /*
1804 * Append the database name to the already-constructed stem of connection
1805 * string.
1806 */
1807 appendPQExpBuffer(&connstrbuf, "%s dbname=", connstr);
1808 appendConnStrVal(&connstrbuf, dbname);
1809
1810 appendShellString(&cmd, connstrbuf.data);
1811
1812 pg_log_info("running \"%s\"", cmd.data);
1813
1814 fflush(NULL);
1815
1816 ret = system(cmd.data);
1817
1818 termPQExpBuffer(&cmd);
1819 termPQExpBuffer(&connstrbuf);
1820
1821 return ret;
1822}
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:90
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:129
void appendConnStrVal(PQExpBuffer buf, const char *str)
Definition: string_utils.c:698

References appendConnStrVal(), appendPQExpBuffer(), appendPQExpBufferStr(), appendShellString(), archCustom, archDirectory, archNull, archTar, connstr, PQExpBufferData::data, dbname, filename, initPQExpBuffer(), pg_dump_bin, pg_log_info, pgdumpopts, printfPQExpBuffer(), and termPQExpBuffer().

Referenced by dumpDatabases().

Variable Documentation

◆ binary_upgrade

int binary_upgrade = 0
static

Definition at line 90 of file pg_dumpall.c.

Referenced by dumpRoles(), dumpTablespaces(), and main().

◆ column_inserts

int column_inserts = 0
static

Definition at line 91 of file pg_dumpall.c.

Referenced by main().

◆ connstr

◆ database_exclude_names

SimpleStringList database_exclude_names = {NULL, NULL}
static

Definition at line 126 of file pg_dumpall.c.

Referenced by dumpDatabases(), and main().

◆ database_exclude_patterns

SimpleStringList database_exclude_patterns = {NULL, NULL}
static

Definition at line 125 of file pg_dumpall.c.

Referenced by main().

◆ disable_dollar_quoting

int disable_dollar_quoting = 0
static

Definition at line 92 of file pg_dumpall.c.

Referenced by main().

◆ disable_triggers

int disable_triggers = 0
static

Definition at line 93 of file pg_dumpall.c.

Referenced by main().

◆ dosync

bool dosync = true
static

Definition at line 88 of file pg_dumpall.c.

Referenced by main().

◆ filename

char* filename = NULL
static

Definition at line 123 of file pg_dumpall.c.

Referenced by _fileExistsInDirectory(), _PrintFileData(), _tarPositionTo(), _tarWriteHeader(), adjust_data_dir(), BaseBackup(), basebackup_read_file(), bbsink_server_begin_archive(), bbsink_server_end_manifest(), be_lo_export(), be_lo_import(), be_lo_import_with_oid(), BeginCopyFrom(), BeginCopyTo(), check_file_excluded(), CheckXLogRemoved(), convert_and_check_filename(), create_file_for_extract(), CreateExtensionInternal(), CreateLockFile(), db_dir_size(), dir_close(), dir_get_file_name(), dir_open_for_write(), dsynonym_init(), dumpDatabases(), dxsyn_init(), ecpg_postprocess_result(), errfinish(), errsave_finish(), execute_extension_script(), execute_sql_string(), expand_tilde(), exportFile(), extract_directory(), extract_link(), file_acquire_sample_rows(), file_exists_in_directory(), file_fdw_validator(), fileAnalyzeForeignTable(), fileBeginForeignScan(), fileExplainForeignScan(), fileGetOptions(), fill_hba_line(), fill_ident_line(), filter_init(), first_dir_separator(), get_sock_dir(), GetConfFilesInDir(), hasSuffix(), importFile(), initTrie(), internal_load_library(), is_extension_control_filename(), is_extension_script_filename(), is_xlogfilename(), IsWalSummaryFilename(), last_dir_separator(), libpqrcv_readtimelinehistoryfile(), llvm_compile_module(), lo_export(), lo_import(), lo_import_internal(), lo_import_with_oid(), load_dh_file(), load_external_function(), load_file(), load_libraries(), load_tzoffsets(), log_locus_callback(), logfile_getname(), logfile_open(), logfile_rotate_dest(), LogicalTapeImport(), LogicalTapeSetCreate(), main(), make_incremental_rfile(), make_native_path(), make_outputdirs(), make_rfile(), next_field_expand(), NIImportAffixes(), NIImportDictionary(), NIImportOOAffixes(), open_auth_file(), parse_backup_label(), parse_extension_control_file(), parse_relfilenumber(), parse_snapshot_filename(), parseIntFromText(), ParseTzFile(), parseVxidFromText(), parseXidFromText(), pg_log_generic_v(), pg_stat_file(), PLy_traceback(), process_file(), process_psqlrc_file(), process_queued_fetch_requests(), progress_update_filename(), read_binary_file(), read_dictionary(), read_dump_filters(), read_dumpall_filters(), read_extension_script_file(), read_pg_version_file(), read_restore_filters(), read_text_file(), read_whole_file(), readstoplist(), reconstruct_from_incremental_file(), regcomp_auth_token(), run_diff(), runPgDump(), sendFileWithContent(), set_input(), set_stack_entry_location(), SetOutput(), setup_run_file(), shell_construct_command(), shell_run_command(), should_allow_existing_directory(), slurp_file(), splitTzLine(), SysLogger_Start(), tar_get_file_name(), tarCreateHeader(), tarOpen(), test_slru_scan_cb(), thesaurusRead(), tokenize_auth_file(), TrimExtension(), tsearch_readline_begin(), UpdateLastRemovedPtr(), verify_plain_backup_directory(), verify_tar_backup(), write_auto_conf_file(), WriteRecoveryConfig(), writeTimeLineHistoryFile(), and XLogRecordSaveFPWs().

◆ if_exists

int if_exists = 0
static

Definition at line 94 of file pg_dumpall.c.

Referenced by dropDBs(), dropRoles(), dropTablespaces(), and main().

◆ inserts

int inserts = 0
static

Definition at line 95 of file pg_dumpall.c.

Referenced by main().

◆ load_via_partition_root

int load_via_partition_root = 0
static

Definition at line 114 of file pg_dumpall.c.

Referenced by main().

◆ no_comments

int no_comments = 0
static

Definition at line 99 of file pg_dumpall.c.

Referenced by dumpRoles(), dumpTablespaces(), and main().

◆ no_data

int no_data = 0
static

Definition at line 103 of file pg_dumpall.c.

Referenced by main().

◆ no_policies

int no_policies = 0
static

Definition at line 100 of file pg_dumpall.c.

Referenced by main().

◆ no_publications

int no_publications = 0
static

Definition at line 101 of file pg_dumpall.c.

Referenced by main().

◆ no_role_passwords

int no_role_passwords = 0
static

Definition at line 109 of file pg_dumpall.c.

Referenced by dumpRoles(), and main().

◆ no_schema

int no_schema = 0
static

Definition at line 104 of file pg_dumpall.c.

Referenced by main().

◆ no_security_labels

int no_security_labels = 0
static

Definition at line 102 of file pg_dumpall.c.

Referenced by dumpRoles(), dumpTablespaces(), and main().

◆ no_statistics

int no_statistics = 0
static

Definition at line 105 of file pg_dumpall.c.

Referenced by main().

◆ no_subscriptions

int no_subscriptions = 0
static

Definition at line 106 of file pg_dumpall.c.

Referenced by main().

◆ no_table_access_method

int no_table_access_method = 0
static

Definition at line 96 of file pg_dumpall.c.

Referenced by main().

◆ no_tablespaces

int no_tablespaces = 0
static

Definition at line 97 of file pg_dumpall.c.

Referenced by main().

◆ no_toast_compression

int no_toast_compression = 0
static

Definition at line 107 of file pg_dumpall.c.

Referenced by main().

◆ no_unlogged_table_data

int no_unlogged_table_data = 0
static

Definition at line 108 of file pg_dumpall.c.

Referenced by main().

◆ on_conflict_do_nothing

int on_conflict_do_nothing = 0
static

Definition at line 115 of file pg_dumpall.c.

Referenced by main().

◆ OPF

◆ output_clean

bool output_clean = false
static

Definition at line 85 of file pg_dumpall.c.

Referenced by dumpDatabases(), and main().

◆ pg_dump_bin

char pg_dump_bin[MAXPGPATH]
static

Definition at line 82 of file pg_dumpall.c.

Referenced by main(), and runPgDump().

◆ pgdumpopts

PQExpBuffer pgdumpopts
static

Definition at line 83 of file pg_dumpall.c.

Referenced by main(), and runPgDump().

◆ role_catalog

char role_catalog[10]
static

Definition at line 118 of file pg_dumpall.c.

Referenced by dropRoles(), dumpRoleMembership(), dumpRoles(), dumpUserConfig(), and main().

◆ server_version

◆ skip_acls

bool skip_acls = false
static

Definition at line 86 of file pg_dumpall.c.

Referenced by dumpTablespaces(), and main().

◆ statistics_only

int statistics_only = 0
static

Definition at line 116 of file pg_dumpall.c.

Referenced by main().

◆ use_setsessauth

int use_setsessauth = 0
static

Definition at line 98 of file pg_dumpall.c.

Referenced by main().

◆ verbose

bool verbose = false
static

Definition at line 87 of file pg_dumpall.c.

Referenced by main().

◆ with_data

int with_data = 0
static

Definition at line 110 of file pg_dumpall.c.

Referenced by main().

◆ with_schema

int with_schema = 0
static

Definition at line 111 of file pg_dumpall.c.

Referenced by main().

◆ with_statistics

int with_statistics = 0
static

Definition at line 112 of file pg_dumpall.c.

Referenced by main().