I would like to create an enforced append only table in my postgres db.
After a bit of research, I realized that a solution that will answer my requirements will be to revoke ALL operations on that table from ALL roles and then run an insert priveleges to all these roles, like so:
REVOKE ALL ON TABLE ticket_trail FROM PUBLIC;
GRANT INSERT ON TABLE ticket_trail TO PUBLIC;
but that doesn’t seem to work. I think that revoking it from PUBLIC does not revoke it from my admin user or other users that I have.
How can I revoke ALL from ALL roles and then GRANT INSERT to all these roles again?
Any better ways to achieve an enforced append only table?
3
Answers
You have to revoke the privileges that were granted. If you want to revoke a privilege that was granted to
admin
, you have to revoke it fromadmin
specifically. There is no wholesale command "revoke everything from everybody".If you are using
psql
, you could usegexec
:Better add a
before update or delete
trigger with a trivial trigger function that returnsnull
. This will work for all users regardless of their roles and privileges.setup
revoke all the grantee privileges in superuser session.
Now it’s clean. Only the owner and superuser can grant privilege to other role. You may want using
alter table public.ticket_trail owner to new_role
change the table ownership.