Nasif Imtiaz Ohi
Nasif Imtiaz Ohi

Reputation: 1713

Is default username and password NULL for PostgreSQL?

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?

Upvotes: 2

Views: 1381

Answers (1)

viniciusjssouza
viniciusjssouza

Reputation: 1275

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

Upvotes: 2

Related Questions