Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8c5e5a1
Restrict accesses to non-system views and foreign tables during pg_dump.
MasahikoSawada Aug 5, 2024
888dc26
pg_dump/psql: properly recognize GP
Smyatkin-Maxim Apr 3, 2026
025d5d3
Avoid invoking PQfnumber in loop constructs
danielgustafsson Aug 27, 2021
a07c2ea
pg_dump: Reorganize getTables()
tglsfdc Oct 19, 2021
dee7e1e
Refactor pg_dump's tracking of object components to be dumped.
tglsfdc Dec 6, 2021
9e95415
Rethink pg_dump's handling of object ACLs.
tglsfdc Dec 6, 2021
8b3c336
Avoid per-object queries in performance-critical paths in pg_dump.
tglsfdc Dec 6, 2021
7796f9e
Use PREPARE/EXECUTE for repetitive per-object queries in pg_dump.
tglsfdc Dec 6, 2021
3f311d3
pg_dump: Refactor getIndexes()
petere Dec 20, 2021
ad4716f
pg_dump: minor performance improvements from eliminating sub-SELECTs.
tglsfdc Dec 31, 2021
119b2b0
pg_dump: Remove dead code.
bmdoil Jul 21, 2022
2057075
pg_dump: Fix getTables parrelid
bmdoil Jul 26, 2022
e40da99
pg_dump: Put GPDB global vars in DumpOptions
bmdoil Jul 27, 2022
5dddb95
pg_dump: Formatting fixes and code cleanup
bmdoil Jul 27, 2022
7291f27
Remove unnecessary partitioning checks in pg_dump
Jul 7, 2022
f38a5b8
pg_dump: Remove DumpOptions argument from testGPbackend
bmdoil Aug 17, 2022
1c72ee1
pg_dump: Update child partition metadata for GPDB{5,6}
bmdoil Sep 7, 2022
21feac1
pg_dump: Omit BYPASSRLS clause for pre GPDB7 server
bmdoil Sep 10, 2022
bdf2086
pg_dump: Move partition def queries to getTables
bmdoil Sep 12, 2022
04baa70
pg_dump: Define macros for GPDB{5-7} Postgres major version
bmdoil Sep 21, 2022
2830f8e
pg_dump: Remove unneeded version check for quote_all_identifiers
bmdoil Sep 29, 2022
e61e494
Fix external protocol dump from gp6 using gp7 pg_dump.
wangxuqi Sep 27, 2022
c6c1d3e
Fix pg_dump small bug (#14991)
xiaoxiaoHe-E Mar 2, 2023
e22febb
Allow pg_dump to include/exclude child tables automatically.
tglsfdc Mar 14, 2023
5753b22
Add getPartitionDefs function to pg_dump
bmdoil Jul 11, 2023
12409e9
Postpone calls of unsafe server-side functions in pg_dump.
tglsfdc Dec 6, 2021
71fd435
pg_dumpall: dump 6x resource groups correctly for 6 > 7 upgrade
kyeap-vmware Nov 21, 2023
ed82386
pg_dump: fix --function-oid when --relation-oid is also used
kyeap-vmware Dec 15, 2023
d47b917
Fix dumping funcs/aggs with --function-oids flag.
bmdoil Jan 6, 2024
3a60eaa
pg_dump: exclude gp_toolkit from being dumped when upgrading from GPDB6
kyeap-vmware Jan 19, 2024
23470d5
pg_dumpall: Fix syntax error when dumping RGs
bmdoil Jan 31, 2024
5d34e12
Remove a fixme referring selectSourceSchema()
adam8157 Mar 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions contrib/postgres_fdw/expected/postgres_fdw.out
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,17 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM ft_empty ORDER BY c1;
Remote SQL: SELECT c1, c2 FROM public.loct_empty ORDER BY c1 ASC NULLS LAST
(3 rows)

-- test restriction on non-system foreign tables.
SET restrict_nonsystem_relation_kind TO 'foreign-table';
SELECT * from ft1 where c1 < 1; -- ERROR
ERROR: access to non-system foreign table is restricted
INSERT INTO ft1 (c1) VALUES (1); -- ERROR
ERROR: access to non-system foreign table is restricted
DELETE FROM ft1 WHERE c1 = 1; -- ERROR
ERROR: access to non-system foreign table is restricted
TRUNCATE ft1; -- ERROR
ERROR: access to non-system foreign table is restricted
RESET restrict_nonsystem_relation_kind;
-- ===================================================================
-- WHERE with remotely-executable conditions
-- ===================================================================
Expand Down
8 changes: 8 additions & 0 deletions contrib/postgres_fdw/sql/postgres_fdw.sql
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@ DELETE FROM loct_empty;
ANALYZE ft_empty;
EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM ft_empty ORDER BY c1;

-- test restriction on non-system foreign tables.
SET restrict_nonsystem_relation_kind TO 'foreign-table';
SELECT * from ft1 where c1 < 1; -- ERROR
INSERT INTO ft1 (c1) VALUES (1); -- ERROR
DELETE FROM ft1 WHERE c1 = 1; -- ERROR
TRUNCATE ft1; -- ERROR
RESET restrict_nonsystem_relation_kind;

-- ===================================================================
-- WHERE with remotely-executable conditions
-- ===================================================================
Expand Down
17 changes: 17 additions & 0 deletions doc/src/sgml/config.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -9027,6 +9027,23 @@ SET XML OPTION { DOCUMENT | CONTENT };
</listitem>
</varlistentry>

<varlistentry id="guc-restrict-nonsystem-relation-kind" xreflabel="restrict_nonsystem_relation_kind">
<term><varname>restrict_nonsystem_relation_kind</varname> (<type>string</type>)
<indexterm>
<primary><varname>restrict_nonsystem_relation_kind</varname></primary>
<secondary>configuration parameter</secondary>
</indexterm>
</term>
<listitem>
<para>
This variable specifies relation kind to which access is restricted.
It contains a comma-separated list of relation kind. Currently, the
supported relation kinds are <literal>view</literal> and
<literal>foreign-table</literal>.
</para>
</listitem>
</varlistentry>

</variablelist>
</sect2>
<sect2 id="runtime-config-client-format">
Expand Down
46 changes: 46 additions & 0 deletions doc/src/sgml/ref/pg_dump.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,19 @@ PostgreSQL documentation
</listitem>
</varlistentry>

<varlistentry>
<term><option>--exclude-table-and-children=<replaceable class="parameter">pattern</replaceable></option></term>
<listitem>
<para>
This is the same as
the <option>-T</option>/<option>--exclude-table</option> option,
except that it also excludes any partitions or inheritance child
tables of the table(s) matching the
<replaceable class="parameter">pattern</replaceable>.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>--exclude-table-data=<replaceable class="parameter">pattern</replaceable></option></term>
<listitem>
Expand All @@ -790,6 +803,18 @@ PostgreSQL documentation
</listitem>
</varlistentry>

<varlistentry>
<term><option>--exclude-table-data-and-children=<replaceable class="parameter">pattern</replaceable></option></term>
<listitem>
<para>
This is the same as the <option>--exclude-table-data</option> option,
except that it also excludes data of any partitions or inheritance
child tables of the table(s) matching the
<replaceable class="parameter">pattern</replaceable>.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>--extra-float-digits=<replaceable class="parameter">ndigits</replaceable></option></term>
<listitem>
Expand Down Expand Up @@ -831,6 +856,14 @@ PostgreSQL documentation
The only exception is that an empty pattern is disallowed.
</para>

<note>
<para>
Using wildcards in <option>--include-foreign-data</option> may result
in access to unexpected foreign servers. Also, to use this option securely,
make sure that the named server must have a trusted owner.
</para>
</note>

<note>
<para>
When <option>--include-foreign-data</option> is specified,
Expand Down Expand Up @@ -1161,6 +1194,19 @@ PostgreSQL documentation
</listitem>
</varlistentry>

<varlistentry>
<term><option>--table-and-children=<replaceable class="parameter">pattern</replaceable></option></term>
<listitem>
<para>
This is the same as
the <option>-t</option>/<option>--table</option> option,
except that it also includes any partitions or inheritance child
tables of the table(s) matching the
<replaceable class="parameter">pattern</replaceable>.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>--use-set-session-authorization</option></term>
<listitem>
Expand Down
1 change: 1 addition & 0 deletions gpMgmt/test/behave/mgmt_utils/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def before_feature(context, feature):
dbconn.execSQL(context.conn, 'insert into t1 values(1, 2)')
dbconn.execSQL(context.conn, 'insert into t2 values(1, 3)')
dbconn.execSQL(context.conn, 'insert into t3 values(1, 4)')
dbconn.execSQL(context.conn, 'create or replace function select_one() returns integer as $$ select 1 $$ language sql')
context.conn.commit()

if 'gppkg' in feature.tags:
Expand Down
12 changes: 12 additions & 0 deletions gpMgmt/test/behave/mgmt_utils/minirepro.feature
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,15 @@ Feature: Dump minimum database objects that is related to the query
And the output file "/tmp/out.sql" should contain "Table: t3, Attribute: f"
And the output file "/tmp/out.sql" should be loaded to database "minidb_tmp" without error
And the file "/tmp/in.sql" should be executed in database "minidb_tmp" without error

@minirepro_core
Scenario: Dump database objects of only functions
Given the file "/tmp/in.sql" exists and contains "SELECT select_one()"
And the file "/tmp/out.sql" does not exist
When the user runs "minirepro minireprodb -q /tmp/in.sql -f /tmp/out.sql"
Then the output file "/tmp/out.sql" should exist
And the output file "/tmp/out.sql" should contain "CREATE FUNCTION public.select_one() RETURNS integer"
And the output file "/tmp/out.sql" should contain "LANGUAGE sql"
And the output file "/tmp/out.sql" should contain "AS $$ select 1 $$;"
And the output file "/tmp/out.sql" should be loaded to database "minidb_tmp" without error
And the file "/tmp/in.sql" should be executed in database "minidb_tmp" without error
10 changes: 10 additions & 0 deletions src/backend/foreign/foreign.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "optimizer/planmain.h"
#include "optimizer/restrictinfo.h"
#include "optimizer/tlist.h"
#include "tcop/tcopprot.h"
#include "utils/builtins.h"
#include "utils/memutils.h"
#include "utils/rel.h"
Expand Down Expand Up @@ -590,6 +591,15 @@ GetFdwRoutine(Oid fdwhandler)
Datum datum;
FdwRoutine *routine;

/* Check if the access to foreign tables is restricted */
if (unlikely((restrict_nonsystem_relation_kind & RESTRICT_RELKIND_FOREIGN_TABLE) != 0))
{
/* there must not be built-in FDW handler */
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("access to non-system foreign table is restricted")));
}

datum = OidFunctionCall0(fdwhandler);
routine = (FdwRoutine *) DatumGetPointer(datum);

Expand Down
13 changes: 13 additions & 0 deletions src/backend/optimizer/plan/createplan.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "parser/parsetree.h"
#include "partitioning/partdesc.h"
#include "partitioning/partprune.h"
#include "tcop/tcopprot.h"
#include "utils/lsyscache.h"
#include "utils/uri.h"

Expand Down Expand Up @@ -8482,7 +8483,19 @@ make_modifytable(PlannerInfo *root, Plan *subplan,

Assert(rte->rtekind == RTE_RELATION);
if (rte->relkind == RELKIND_FOREIGN_TABLE)
{
/* Check if the access to foreign tables is restricted */
if (unlikely((restrict_nonsystem_relation_kind & RESTRICT_RELKIND_FOREIGN_TABLE) != 0))
{
/* there must not be built-in foreign tables */
Assert(rte->relid >= FirstNormalObjectId);
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("access to non-system foreign table is restricted")));
}

fdwroutine = GetFdwRoutineByRelId(rte->relid);
}
else
fdwroutine = NULL;
}
Expand Down
12 changes: 12 additions & 0 deletions src/backend/optimizer/util/plancat.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "rewrite/rewriteManip.h"
#include "statistics/statistics.h"
#include "storage/bufmgr.h"
#include "tcop/tcopprot.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/partcache.h"
Expand Down Expand Up @@ -484,6 +485,17 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
/* Grab foreign-table info using the relcache, while we have it */
if (relation->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
{
/* Check if the access to foreign tables is restricted */
if (unlikely((restrict_nonsystem_relation_kind & RESTRICT_RELKIND_FOREIGN_TABLE) != 0))
{
/* there must not be built-in foreign tables */
Assert(RelationGetRelid(relation) >= FirstNormalObjectId);

ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("access to non-system foreign table is restricted")));
}

rel->serverid = GetForeignServerIdByRelId(RelationGetRelid(relation));
rel->segSeverids = GetForeignServerSegsByRelId(RelationGetRelid(relation));
rel->fdwroutine = GetFdwRoutineForRelation(relation, true);
Expand Down
17 changes: 17 additions & 0 deletions src/backend/rewrite/rewriteHandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "rewrite/rewriteManip.h"
#include "rewrite/rewriteSearchCycle.h"
#include "rewrite/rowsecurity.h"
#include "tcop/tcopprot.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
Expand Down Expand Up @@ -1815,6 +1816,14 @@ ApplyRetrieveRule(Query *parsetree,
if (rule->qual != NULL)
elog(ERROR, "cannot handle qualified ON SELECT rule");

/* Check if the expansion of non-system views are restricted */
if (unlikely((restrict_nonsystem_relation_kind & RESTRICT_RELKIND_VIEW) != 0 &&
RelationGetRelid(relation) >= FirstNormalObjectId))
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("access to non-system view \"%s\" is restricted",
RelationGetRelationName(relation))));

if (rt_index == parsetree->resultRelation)
{
/*
Expand Down Expand Up @@ -3261,6 +3270,14 @@ rewriteTargetView(Query *parsetree, Relation view)
}
}

/* Check if the expansion of non-system views are restricted */
if (unlikely((restrict_nonsystem_relation_kind & RESTRICT_RELKIND_VIEW) != 0 &&
RelationGetRelid(view) >= FirstNormalObjectId))
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("access to non-system view \"%s\" is restricted",
RelationGetRelationName(view))));

/*
* For INSERT/UPDATE the modified columns must all be updatable. Note that
* we get the modified columns from the query's targetlist, not from the
Expand Down
63 changes: 63 additions & 0 deletions src/backend/tcop/postgres.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
#include "utils/snapmgr.h"
#include "utils/timeout.h"
#include "utils/timestamp.h"
#include "utils/varlena.h"

#include "cdb/cdbutil.h"
#include "cdb/cdbvars.h"
Expand Down Expand Up @@ -151,6 +152,8 @@ cancel_pending_hook_type cancel_pending_hook = NULL;
* Hook for query execution.
*/
exec_simple_query_hook_type exec_simple_query_hook = NULL;
/* flags for non-system relation kinds to restrict use */
int restrict_nonsystem_relation_kind;

/* ----------------
* private typedefs etc
Expand Down Expand Up @@ -4558,6 +4561,66 @@ assign_max_stack_depth(int newval, void *extra)
max_stack_depth_bytes = newval_bytes;
}

/*
* GUC check_hook for restrict_nonsystem_relation_kind
*/
bool
check_restrict_nonsystem_relation_kind(char **newval, void **extra, GucSource source)
{
char *rawstring;
List *elemlist;
ListCell *l;
int flags = 0;

/* Need a modifiable copy of string */
rawstring = pstrdup(*newval);

if (!SplitIdentifierString(rawstring, ',', &elemlist))
{
/* syntax error in list */
GUC_check_errdetail("List syntax is invalid.");
pfree(rawstring);
list_free(elemlist);
return false;
}

foreach(l, elemlist)
{
char *tok = (char *) lfirst(l);

if (pg_strcasecmp(tok, "view") == 0)
flags |= RESTRICT_RELKIND_VIEW;
else if (pg_strcasecmp(tok, "foreign-table") == 0)
flags |= RESTRICT_RELKIND_FOREIGN_TABLE;
else
{
GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
pfree(rawstring);
list_free(elemlist);
return false;
}
}

pfree(rawstring);
list_free(elemlist);

/* Save the flags in *extra, for use by the assign function */
*extra = malloc(sizeof(int));
*((int *) *extra) = flags;

return true;
}

/*
* GUC assign_hook for restrict_nonsystem_relation_kind
*/
void
assign_restrict_nonsystem_relation_kind(const char *newval, void *extra)
{
int *flags = (int *) extra;

restrict_nonsystem_relation_kind = *flags;
}

/*
* set_debug_options --- apply "-d N" command line option
Expand Down
15 changes: 14 additions & 1 deletion src/backend/utils/misc/guc.c
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,8 @@ static char *recovery_target_xid_string;
static char *recovery_target_name_string;
static char *recovery_target_lsn_string;
static char *file_encryption_method_str;
static char *restrict_nonsystem_relation_kind_string;


/* should be static, but commands/variable.c needs to get at this */
char *role_string;
Expand Down Expand Up @@ -4761,7 +4763,18 @@ static struct config_string ConfigureNamesString[] =
"",
NULL, NULL, NULL
},


{
{"restrict_nonsystem_relation_kind", PGC_USERSET, CLIENT_CONN_STATEMENT,
gettext_noop("Sets relation kinds of non-system relation to restrict use"),
NULL,
GUC_LIST_INPUT | GUC_NOT_IN_SAMPLE
},
&restrict_nonsystem_relation_kind_string,
"",
check_restrict_nonsystem_relation_kind, assign_restrict_nonsystem_relation_kind, NULL
},

/* End-of-list marker */
{
{NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL, NULL
Expand Down
Loading
Loading