Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To create a user in PostgreSQL via psql command by passing the username, follow these steps:

  1. Open the Terminal or Command Prompt and launch the psql command-line interface by typing in "psql" and pressing Enter.
  2. Enter the following command to create a new user, replacing "newuser" with the desired username:
CREATE USER newuser;
  1. If you want to assign a password to the new user, you can do so by running the following command, replacing "password" with the desired password.
ALTER USER newuser WITH PASSWORD 'password';
  1. You can also grant the new user privileges to access databases by running this command:
GRANT ALL PRIVILEGES ON DATABASE dbname TO newuser;

Replace "dbname" with the name of the database you want to grant access to.

  1. After you have created the new user and granted privileges, exit the psql command by typing "\q" and pressing Enter.