Why the hell can’t I login to PostgreSQL?

Some possible reasons and solutions

Wrong host

Use the “-h” flag:

psql -h localhost -U phisaver --password

Wrong syntax

Use -U and -W flags for user and password

psql -U fred -W

> prompts for password

Not allowed

Check your conf file/s. Google dat.

Ensure TCP access is allowed for remote access, as local Unix socket access is the default.

Admin account

I get password failure with:

psql -h localhost -U phisaver --password

And instead need to switch to the user in shell to execute psql

sudo -u postgres psql

psql>

Finally

Maybe you get a ‘peer authentication’ failure, which means psql is asking the OS to authenticate. Edit /etc/postgresql/12/main/pg_hba.conf and change ‘local’ connections from ‘peer’ (the default) to ‘md5’

Leave a Reply

Your email address will not be published. Required fields are marked *