Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the privileges of a table in postgresql?

I try to grant specific privileges to my table "MEMBERS" in postgresql but nothing changes. More specifically I do this (through pgadmin console):

    CREATE DATABASE login;
    CREATE USER loginUser WITH PASSWORD 'xxxxxxxxxxxxx';

    CREATE TABLE members (
     id serial NOT NULL,
     username varchar(30) NOT NULL
     PRIMARY KEY(id)
    )

    ALTER USER loginuser WITH SUPERUSER;
    ALTER TABLE members OWNER TO loginuser;

    GRANT SELECT, UPDATE, INSERT, DELETE ON members TO loginuser;

The query is returned successfully but when I check the table's privileges through the pgadmin gui all of them are selected.

What am I missing?

like image 990
user1919 Avatar asked Oct 18 '25 13:10

user1919


1 Answers

By default, a table's owner has full privileges on it. If you want "loginuser" to have only select, update, insert, and delete privileges, you would normally revoke all privileges first, then grant just those four.

revoke all on members from loginuser;
grant select, update, insert, delete on members to loginuser;

This will appear to work for you, but it really won't. A database superuser can revoke privileges from a table's owner. But you've made "loginuser" a superuser. Whatever privileges you revoke, "loginuser" can just grant to herself.

You need to think more carefully about what you're trying to accomplish here.

like image 111
Mike Sherrill 'Cat Recall' Avatar answered Oct 22 '25 06:10

Mike Sherrill 'Cat Recall'