MCPcopy Create free account
hub / github.com/apache/cloudberry / dumpTablespaces

Function dumpTablespaces

src/bin/pg_dump/pg_dumpall.c:1620–1817  ·  view source on GitHub ↗

* Dump tablespaces. */

Source from the content-addressed store, hash-verified

1618 * Dump tablespaces.
1619 */
1620static void
1621dumpTablespaces(PGconn *conn)
1622{
1623 PGresult *res;
1624 int i;
1625
1626 // WALREP_FIXME: filespaces are gone. How do we deal with that here?
1627
1628 /*
1629 * Get all tablespaces except built-in ones (which we assume are named
1630 * pg_xxx)
1631 *
1632 * [FIXME] the queries need to be slightly different if the backend isn't
1633 * Cloudberry, and the dump format should vary depending on if the dump is
1634 * --gp-syntax or --no-gp-syntax.
1635 *
1636 * For the tablespace ACLs, as of 9.6, we extract both the positive (as
1637 * spcacl) and negative (as rspcacl) ACLs, relative to the default ACL for
1638 * tablespaces, which are then passed to buildACLCommands() below.
1639 *
1640 * See buildACLQueries() and buildACLCommands().
1641 *
1642 * The order in which privileges are in the ACL string (the order they
1643 * have been GRANT'd in, which the backend maintains) must be preserved to
1644 * ensure that GRANTs WITH GRANT OPTION and subsequent GRANTs based on
1645 * those are dumped in the correct order.
1646 *
1647 * Note that we do not support initial privileges (pg_init_privs) on
1648 * tablespaces, so this logic cannot make use of buildACLQueries().
1649 */
1650
1651 if (server_version >= 140000)
1652 {
1653 res = executeQuery(conn, "SELECT oid, spcname, "
1654 "pg_catalog.pg_get_userbyid(spcowner) AS spcowner, "
1655 "pg_catalog.pg_tablespace_location(oid), "
1656 "(SELECT array_agg(acl ORDER BY row_n) FROM "
1657 " (SELECT acl, row_n FROM "
1658 " unnest(coalesce(spcacl,acldefault('t',spcowner))) "
1659 " WITH ORDINALITY AS perm(acl,row_n) "
1660 " WHERE NOT EXISTS ( "
1661 " SELECT 1 "
1662 " FROM unnest(acldefault('t',spcowner)) "
1663 " AS init(init_acl) "
1664 " WHERE acl = init_acl)) AS spcacls) "
1665 " AS spcacl, "
1666 "(SELECT array_agg(acl ORDER BY row_n) FROM "
1667 " (SELECT acl, row_n FROM "
1668 " unnest(acldefault('t',spcowner)) "
1669 " WITH ORDINALITY AS initp(acl,row_n) "
1670 " WHERE NOT EXISTS ( "
1671 " SELECT 1 "
1672 " FROM unnest(coalesce(spcacl,acldefault('t',spcowner))) "
1673 " AS permp(orig_acl) "
1674 " WHERE acl = orig_acl)) AS rspcacls) "
1675 " AS rspcacl, "
1676 "array_to_string(spcoptions, ', '),"
1677 "pg_catalog.shobj_description(oid, 'pg_tablespace'), "

Callers 1

mainFunction · 0.85

Calls 15

PQntuplesFunction · 0.85
createPQExpBufferFunction · 0.85
PQgetvalueFunction · 0.85
pg_strdupFunction · 0.85
fmtIdFunction · 0.85
appendPQExpBufferStrFunction · 0.85
appendPQExpBufferFunction · 0.85
appendStringLiteralConnFunction · 0.85
buildACLCommandsFunction · 0.85
PQfinishFunction · 0.85
buildShSecLabelsFunction · 0.85
destroyPQExpBufferFunction · 0.85

Tested by

no test coverage detected