10

Enabling row level security on a table in postgres is pretty straightforward:

alter table some_table enable row level security;

How would you check to see which tables in a given schema have row level security enabled (for testing)?

2 Answers 2

15

This is stored in pg_class

  • relrowsecurity bool True if table has row level security enabled; see pg_policy catalog
  • relforcerowsecurity bool True if row level security (when enabled) will also apply to table owner; see pg_policy catalog

So you can use:

select relname, relrowsecurity, relforcerowsecurity
from pg_class
where oid = 'your_table_name'::regclass;

Alternatively use pg_tables

Sign up to request clarification or add additional context in comments.

1 Comment

select relname, relrowsecurity, relforcerowsecurity from pg_class where relrowsecurity=true or relforcerowsecurity=true;
4

If you want to check if row level security is enabled for lots of tables for a particular schema (in this case public) you can use:

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';

2 Comments

What does the relforcerowsecurity col represent?
The documentation for pgclass availed at postgresql.org/docs/current/catalog-pg-class.html reads:- a) relrowsecurity True if table has row-level security enabled b) relforcerowsecurity True if row-level security (when enabled) will also apply to table owner

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.