![](/img/trans.png)
[英]PostgreSQL query not using INDEX when RLS (Row Level Security) is enabled
[英]How to check if row level security is enabled for a table in postgres
在 postgres 中的表上啟用行級安全性非常簡單:
alter table some_table enable row level security;
您將如何檢查給定模式中的哪些表啟用了行級安全性(用於測試)?
這存儲在pg_class中
relrowsecurity
bool如果表啟用了行級安全性, relrowsecurity
true;否則為relrowsecurity
。 參見pg_policy目錄 relforcerowsecurity
bool如果行級安全性(啟用時)也適用於表所有者, relforcerowsecurity
true;否則為true。 參見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';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.