PostgreSQL add or create a user account and grant permission for database

www‮iruttual.‬.com
PostgreSQL add or create a user account and grant permission for database

To add a new user account and grant permissions for a database in PostgreSQL, you will need to follow these steps:

  1. Connect to the PostgreSQL server as a user with privileges to create new users and grant permissions. You can connect to the PostgreSQL server using the psql command.

For example:

psql -U postgres
  1. Create the new user account. Use the CREATE USER command to create the new user account. Specify the username and the password as arguments.

For example:

CREATE USER newuser WITH PASSWORD 'password';
  1. Grant permissions to the user for the database. Use the GRANT command to grant permissions to the user for the database. Specify the permissions that you want to grant and the name of the database as arguments.

For example, to grant the user newuser all permissions on the database mydatabase, you can use the following command:

GRANT ALL PRIVILEGES ON DATABASE mydatabase TO newuser;
  1. Exit the psql prompt. Use the \q command to exit the psql prompt.

This will add the new user account and grant the specified permissions for the database.

Created Time:2017-10-30 14:27:12  Author:lautturi