To add a new user account and grant permissions for a database in PostgreSQL, you will need to follow these steps:
psql
command.For example:
psql -U postgres
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';
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;
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.