postgresqldatabase-permissions

Create user with grant privileges on only one database


I want to grant read/write privileges to new user only to one database, so he can't access other databases.


After I created new user with: sudo -u postgres createuser <username> What privileges this user get?

Is this all I need: GRANT ALL PRIVILEGES ON my_db TO new_user; to get access to only one database?

What is the best way to do this?

Using PostgreSQL 10


Solution

  • By default, PUBLIC (everyone) is allowed to connect to all databases. So you'd have to revoke that privilege and hand out CONNECT more judiciously.

    In addition to that, you'd have to make sure that every user has CREATE on all schemas in “his” database and the necessary privileges on all tables, because privileges on the database itself are not enough to access the objects in the database.

    It could be the simplest solution to use REASSIGN OWNED to give the user ownership of all objects in “their” database.