diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 4e8c982..5da3747 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -6012,6 +6012,31 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
+
+ catalog_row_security (boolean)
+
+ catalog_row_security> configuration parameter
+
+
+
+
+ This variable controls whether to raise an error in lieu of applying a
+ row security policy for a catalog table. When set to on>,
+ policies apply normally. When set to off>, queries fail which
+ would otherwise apply at least one policy. The default is on>.
+ Change to off> where limited row visibility could cause
+ incorrect results. This variable has no effect on roles which bypass
+ every row security policy, to wit, superusers and roles with
+ the BYPASSRLS> attribute.
+
+
+
+ For more information on row security policies,
+ see .
+
+
+
+
default_tablespace (string)
diff --git a/doc/src/sgml/ref/pg_dump.sgml b/doc/src/sgml/ref/pg_dump.sgml
index be1b684..70267e9 100644
--- a/doc/src/sgml/ref/pg_dump.sgml
+++ b/doc/src/sgml/ref/pg_dump.sgml
@@ -703,6 +703,21 @@ PostgreSQL documentation
+
+
+
+ This option is relevant only to throw an error instead of dumping
+ limited row visibility because of a row security on a catalog table.
+ If the user does not have sufficient privileges to bypass row security,
+ then an error is thrown. This parameter instructs pg_dump
+ to set to off instead, allowing the user
+ to dump the parts of the contents of the table that they have access to.
+
+
+
+
+
+
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 6ac5184..719f638 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -419,6 +419,7 @@ bool log_btree_build_stats = false;
char *event_source;
bool row_security;
+bool catalog_row_security;
bool check_function_bodies = true;
bool default_with_oids = false;
bool SQL_inheritance = true;
@@ -1390,6 +1391,15 @@ static struct config_bool ConfigureNamesBool[] =
NULL, NULL, NULL
},
{
+ {"catalog_row_security", PGC_USERSET, CONN_AUTH_SECURITY,
+ gettext_noop("Enable catalog row security."),
+ gettext_noop("When enabled, row security will be applied to all users on catalog tables.")
+ },
+ &catalog_row_security,
+ true,
+ NULL, NULL, NULL
+ },
+ {
{"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
gettext_noop("Check function bodies during CREATE FUNCTION."),
NULL
diff --git a/src/backend/utils/misc/rls.c b/src/backend/utils/misc/rls.c
index 4d6c88d..3d1bb10 100644
--- a/src/backend/utils/misc/rls.c
+++ b/src/backend/utils/misc/rls.c
@@ -113,16 +113,31 @@ check_enable_rls(Oid relid, Oid checkAsUser, bool noError)
return RLS_NONE_ENV;
}
- /*
- * We should apply RLS. However, the user may turn off the row_security
- * GUC to get a forced error instead.
- */
- if (!row_security && !noError)
- ereport(ERROR,
- (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
- errmsg("query would be affected by row-level security policy for table \"%s\"",
- get_rel_name(relid)),
- amowner ? errhint("To disable the policy for the table's owner, use ALTER TABLE NO FORCE ROW LEVEL SECURITY.") : 0));
+ if (relid < FirstNormalObjectId)
+ {
+ /*
+ * We should apply catalog RLS. However, the user may turn off the
+ * catalog_row_security GUC to get a forced error instead.
+ */
+ if (!catalog_row_security && !noError)
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("query would be affected by catalog row-level security policy for table \"%s\"",
+ get_rel_name(relid))));
+ }
+ else
+ {
+ /*
+ * We should apply RLS. However, the user may turn off the row_security
+ * GUC to get a forced error instead.
+ */
+ if (!row_security && !noError)
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("query would be affected by row-level security policy for table \"%s\"",
+ get_rel_name(relid)),
+ amowner ? errhint("To disable the policy for the table's owner, use ALTER TABLE NO FORCE ROW LEVEL SECURITY.") : 0));
+ }
/* RLS should be fully enabled for this relation. */
return RLS_ENABLED;
diff --git a/src/bin/pg_dump/pg_backup.h b/src/bin/pg_dump/pg_backup.h
index f94caa3..a2c6b7a 100644
--- a/src/bin/pg_dump/pg_backup.h
+++ b/src/bin/pg_dump/pg_backup.h
@@ -150,6 +150,7 @@ typedef struct _dumpOptions
int outputNoTablespaces;
int use_setsessauth;
int enable_row_security;
+ int disable_catalog_row_security;
/* default, if no "inclusion" switches appear, is to dump everything */
bool include_everything;
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 08c2b0c..0680de5 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -334,6 +334,7 @@ main(int argc, char **argv)
{"disable-dollar-quoting", no_argument, &dopt.disable_dollar_quoting, 1},
{"disable-triggers", no_argument, &dopt.disable_triggers, 1},
{"enable-row-security", no_argument, &dopt.enable_row_security, 1},
+ {"disable-catalog-row-security", no_argument, &dopt.disable_catalog_row_security, 1},
{"exclude-table-data", required_argument, NULL, 4},
{"if-exists", no_argument, &dopt.if_exists, 1},
{"inserts", no_argument, &dopt.dump_inserts, 1},
@@ -912,6 +914,9 @@ help(const char *progname)
printf(_(" --disable-triggers disable triggers during data-only restore\n"));
printf(_(" --enable-row-security enable row security (dump only content user has\n"
" access to)\n"));
+ printf(_(" --disable-catalog-row-security\n"
+ " disable catalog row security (throw error instead of\n"
+ " dumping only content user has access to)\n"));
printf(_(" --exclude-table-data=TABLE do NOT dump data for the named table(s)\n"));
printf(_(" --if-exists use IF EXISTS when dropping objects\n"));
printf(_(" --inserts dump data as INSERT commands, rather than COPY\n"));
@@ -1040,6 +1045,9 @@ setup_connection(Archive *AH, const char *dumpencoding,
ExecuteSqlStatement(AH, "SET row_security = on");
else
ExecuteSqlStatement(AH, "SET row_security = off");
+
+ if (dopt->disable_catalog_row_security)
+ ExecuteSqlStatement(AH, "SET catalog_row_security = off");
}
/*
diff --git a/src/include/utils/rls.h b/src/include/utils/rls.h
index 29d17a4..a76abe0 100644
--- a/src/include/utils/rls.h
+++ b/src/include/utils/rls.h
@@ -15,6 +15,7 @@
/* GUC variable */
extern bool row_security;
+extern bool catalog_row_security;
/*
* Used by callers of check_enable_rls.