To create a user in PostgreSQL via psql command by passing the username, follow these steps:
- Open the Terminal or Command Prompt and launch the psql command-line interface by typing in "psql" and pressing Enter.
- Enter the following command to create a new user, replacing "newuser" with the desired username:
CREATE USER newuser;
- 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';
- 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.
- After you have created the new user and granted privileges, exit the psql command by typing "\q" and pressing Enter.