Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I mark a table read-only?

Tags:

postgresql

I'm dealing with a migration of a django site, and I'd like make all tables read-only except for the django_session table. How can I do this?

like image 454
FLX Avatar asked Aug 07 '14 21:08

FLX


1 Answers

REVOKE INSERT, UPDATE, DELETE, TRUNCATE
ON ALL TABLES IN SCHEMA public
FROM public, <target_role>;

Possibly add more roles to the list, but do not forget the role public.
Possibly add more schemas to the list, but do not forget the schema public.
Details in the manual.

Superusers (like postgres) ignore permissions. A trigger would be an alternative to include them, too.

like image 119
Erwin Brandstetter Avatar answered Oct 04 '22 10:10

Erwin Brandstetter