Create an Postgres user in AWS RDS with createDB permissions

0

I have a db instance that contains multiples databases. I want to create one user to each database where the user can only access that database. I am using Prisma ORM, that requires that the user can create a database (known as shadow database) but I am struggling with this user creation.

I would like some tips about which SQL commands should I use.

  • The user needs to be able to create a database or perform sql actions on existing database?

  • Create Databases and have access to one database already created

已提问 7 个月前587 查看次数
1 回答
0

These commands are assuming you are using psql cli as such and can be executed via SQL gui also.

To create a user you will need to execute the following command

CREATE USER username with CREATEDB password 'qwerty12345';

To grant SELECT access to the database created already you will need to grant access as follows assuming the schema is public. Select the database to assign the access with with

\c databasename;

Then assign access to all future tables and views in public schema.

ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO username;

Then assign access to existing views and tables in the public schema as follows.

GRANT SELECT ON ALL TABLES IN SCHEMA public TO username;

Replace username, databasename and the random password with your own values.

profile picture
专家
已回答 7 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则

相关内容