如何检查是否为 postgres 中的 table 启用了行级安全性
How to check if row level security is enabled for a table in postgres
在 postgres 中的 table 上启用行级安全性非常简单:
alter table some_table enable row level security;
您将如何检查给定架构中的哪些 table 启用了行级安全性(用于测试)?
这存储在pg_class
relrowsecurity
bool 如果 table 启用了行级安全性则为真;请参阅 pg_policy 目录
relforcerowsecurity
bool 如果行级安全性(启用时)也适用于 table 所有者,则为真;请参阅 pg_policy 目录
所以你可以使用:
select relname, relrowsecurity, relforcerowsecurity
from pg_class
where oid = 'your_table_name'::regclass;
或者使用pg_tables
如果您想检查是否为特定模式的大量表启用了行级安全性(在本例中 public),您可以使用:
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';
在 postgres 中的 table 上启用行级安全性非常简单:
alter table some_table enable row level security;
您将如何检查给定架构中的哪些 table 启用了行级安全性(用于测试)?
这存储在pg_class
relrowsecurity
bool 如果 table 启用了行级安全性则为真;请参阅 pg_policy 目录relforcerowsecurity
bool 如果行级安全性(启用时)也适用于 table 所有者,则为真;请参阅 pg_policy 目录
所以你可以使用:
select relname, relrowsecurity, relforcerowsecurity
from pg_class
where oid = 'your_table_name'::regclass;
或者使用pg_tables
如果您想检查是否为特定模式的大量表启用了行级安全性(在本例中 public),您可以使用:
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';