0

I'm new to SQL and I'm following a tutorial on how to create a database. The new database I'm creating is called sample_db.

postgres=# create database sample_db

postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 sample_db | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(4 rows)

Everything looks great so far. I'm using Datagrip to visualise the database. However when I test the connection I get an error. (See image below):

The error message says "the server requested password-based authentication but no password was provided". However I didn't make a password and the tutorial I followed didn't either.

enter image description here

1 Answer 1

1

I believe you created the database using the Postgres local user access (trust authentication). To connect using a JDBC driver (which is the case of DataGrip), you have to create an user and grant him access to the database. This is an usual procedure using psql client:

> sudo -u postgres psql;
> CREATE USER <username> WITH PASSWORD '<password>';
> GRANT ALL PRIVILEGES ON DATABASE <database_name> TO <username>;

After this sequence of commands, you should be allowed to connect to your database using DataGrip

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

7 Comments

I'm the only user
Ok, but how did you create the database? Using PSQL or Datagrip?
I used PSQL from the bash terminal
All I did to create the database was create database sample_db
So the postgres user is the owner of the database. The default postgres config does not allow socket connections using the postgres user. You will have to create another user, with restricted permissions, as I pointed in my answer.
|

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.