ARTICLE / 2022.01.18

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 TC…

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'