4

I have a postgres DB with SQL-only access (I mean I can connect using psql). I need to disable some rules, do maintenance and then enable them back. I'd like to assure that after all those operations all the rules are enabled. How could I list them using an SQL query?

mrzasa
  • 22,895
  • 11
  • 56
  • 94
  • 2
    depends on what Rules you're wanting to check but this may help for tables: http://stackoverflow.com/questions/109325/postgresql-describe-table or maybe: select * from pg_rules; would get the rules. – xQbert Nov 20 '13 at 14:53

1 Answers1

10

Something like this should get you started:

select n.nspname as rule_schema, 
       c.relname as rule_table, 
       case r.ev_type  
         when '1' then 'SELECT' 
         when '2' then 'UPDATE' 
         when '3' then 'INSERT' 
         when '4' then 'DELETE' 
         else 'UNKNOWN' 
       end as rule_event
from pg_rewrite r  
  join pg_class c on r.ev_class = c.oid 
  left join pg_namespace n on n.oid = c.relnamespace 
  left join pg_description d on r.oid = d.objoid