Assuming that "user" does not include any roles with superuser privileges (who can do everything), run this as owner of the table or superuser:
REVOKE ALL ON TABLE account FROM public;
GRANT SELECT, INSERT ON TABLE account TO public;
Users also need the USAGE
privilege for the SEQUENCE
attached to the serial
column:
GRANT USAGE ON SEQUENCE account_user_id_seq TO public;
About serial
:
To make sure of the name of the attached sequence, use pg_get_serial_sequence()
. See:
You also need the USAGE
privilege on the schema and CONNECT
of the database, both of which are granted by default for schema public
.
If you only want a subset of users to be affected, grant privileges to a group role instead of public
and grant membership in that role to those users. You still need to revoke privileges from the pseudo-role public
, which can be viewed as the default group role granting membership to all (irrevocably). And grant whatever is still needed to others (by way of another group role, for instance).
CREATE ROLE my_group;
GRANT my_group TO my_user1;
GRANT my_group TO my_user2; -- more?
REVOKE ... FROM public;
GRANT SELECT, INSERT ON TABLE account TO my_group;
GRANT USAGE ON SEQUENCE account_user_id_seq TO my_group;
CREATE ROLE others;
GRANT others TO other_user1;
GRANT others TO other_user2;
GRANT ... TO others;
Related:
SELECT FOR UPDATE
is not permanent (it is tied to the open transaction/session) and it is not intended to block write access for your purpose. You make a table immutable by using database and/or filesystem permissions, instead.