2

I have installed postgresql through homebrew.

There was a default database named "postgres". I also created a new database by running the command "create " from the terminal. However, postgresql never prompted me to set up any user name and password. When I use a GUI (Datagrip) to navigate these databases, I can keep the username and password field blank while connecting to these databases.

I am new to postgresql and I know MySQL. In MySQL, there is a root account from where I can create new accounts with certain privileges. Is the default setting in postgresql NULL?

1 Answer 1

2

By default, postgres come only with login (peer) authentication. You should use psql (postgres command line client) to add a new login and password. To access psql, run:

sudo -u postgres psql

Inside psql, create a role with the command:

postgres=# CREATE USER myuser with password 'mypass';

Finally, grant permission on some database to this new role:

GRANT ALL ON DATABASE mydb to myuser;

After that, you will be able to access the database using this new user in DataGrip.

Another (more advanced) option, is to edit the pg_hba.conf file to enable local other authentication methods. This page may help you: https://www.postgresql.org/docs/9.1/auth-methods.html

Sign up to request clarification or add additional context in comments.

2 Comments

I cannot run sudo -u postgres psql. It gives sudo: unknown user: postgres
It's because you are using MacOS. Try just psql and look if you get logged in

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.