Ask Your Question
1

How can a user be created for an SQL file by passing their username through the psql command?

asked 2021-05-12 11:00:00 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-09-13 05:00:00 +0000

plato gravatar image

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.
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-05-12 11:00:00 +0000

Seen: 8 times

Last updated: Sep 13 '22