DEV Community

trycatch
trycatch

Posted on • Edited on

1 2

7 steps after installing PostgresQL on Ubuntu Server 20.04

Problem:

After installation (sudo apt install postgresql-12) you try to connect to your fresh PostgresQL 12 using psql, but it's responding

psql: error: could not connect to server: FATAL:  Peer authentication failed for user "postgres"
Enter fullscreen mode Exit fullscreen mode

Solution:

1) Make sure you've run pg_ctlcluster

sudo pg_ctlcluster 12 main start
Enter fullscreen mode Exit fullscreen mode

2) Check postgres port and change it to 5432 if needed

sudo nano /etc/postgresql/12/main/postgresql.conf
Enter fullscreen mode Exit fullscreen mode

in newer versions it might be 5433 by default, so it causes problems

find a string with port = 5433 and change it to port = 5432

3) Restart postgres service (just in case)

sudo service postgresql restart
Enter fullscreen mode Exit fullscreen mode

4) Sign-in into psql using sudo

sudo -u postgres psql postgres
Enter fullscreen mode Exit fullscreen mode

5) Set up postgres user's password. Don't forget the semicolon!

2 last steps on my DevOps blog

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay