在Postgres中的表上启用行级别安全性很简单:
alter table some_table enable row level security;
您将如何检查给定模式中的哪些表已启用行安全性(用于测试)?
这存储在pg_class
中-
relrowsecurity
如果表已启用了行级别安全性,则为true;请参阅PG_POLICY目录 -
relforcerowsecurity
如果行级安全性(启用时)也将适用于表所有者;请参阅PG_POLICY目录
因此您可以使用:
select relname, relrowsecurity, relforcerowsecurity
from pg_class
where oid = 'your_table_name'::regclass;
或者使用pg_tables
如果要检查针对特定模式的大量表是否启用了行级别安全性(在本例中为公共),则可以使用:
select relname, relrowsecurity, relforcerowsecurity
from pg_class
join pg_catalog.pg_namespace n on n.oid = pg_class.relnamespace
where n.nspname = 'public' and relkind = 'r';