Saturday 13 May 2023

How to grant access to an user on postgres to just create a table on a particular database

To see the post better click on this link- How to grant access to an user on postgres to just create a table on a particular database (hashnode.dev)



To grant access to a user named "sashan" to create tables in a specific database in Postgres, you can follow these steps:

  1. Connect to the Postgres server using a user with administrative privileges, such as the default "postgres" user.
  2. Switch to the database where you want to grant access to the "sashan" user. You can do this by running the following command:

\c your_database_name

  1. Create a new role for the "sashan" user if they don't already have one. You can do this by running the following command:

CREATE ROLE sashan LOGIN PASSWORD 'your_password';

Replace "your_password" with a strong password for the "sashan" user.

  1. Grant the "CREATE" privilege on the database to the "sashan" user. You can do this by running the following command:

GRANT CREATE ON DATABASE your_database_name TO sashan;

This will allow the "sashan" user to create new tables in the specified database.

That's it! The "sashan" user should now be able to create tables in the database you specified.