0

I am trying to connect to the PostgreSQL-11 using psql-11 and pgpass as I want to avoid password request.

I used following post: Run a PostgreSQL .sql file using command line arguments. I checked other resources but wasn't able to identify issue.

Content of ~/.pgpass (chmod 0600)

*:*:*:postgres:postgres

Content of pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            trust
host    replication     all             ::1/128                 trust

I am using following command to connect to the Database:

psql -U postgres -h 10.20.110.43 -p 5432 -d PostgreDB -w

It is working when I am excluding -w, but in this case I have to type in a password. I also can see that pgpass will be checked, as when I am using wrong permissions system ask me to change it to 0600.

Thanks for your help!

Kosta
  • 45
  • 2
  • 7
  • 1
    First, the pg_hba.conf you show is not requiring a password for any connections as you have ```trust``` set. Are you sure this is the correct pg_hba.conf? Second it is only accepting connections on localhost and socket. You are connecting to ```10.20.110.43```. Again are you on the correct database. Also what is ```listen_addresses ``` set to in postgresql.conf? – Adrian Klaver Jul 18 '20 at 21:25
  • Yes you are right. I checked the postgresql.conf and realized that I was using wrong file. After changing it, I am able to login to the server with configuration trust. How ever when I am changing the mothod to md5 or password I am againt getting the same error message. Thank for your help. Atleast now I can start with tests... – Kosta Jul 19 '20 at 12:50
  • So if you set md5, don't use ```-w``` and enter the password you can connect? – Adrian Klaver Jul 19 '20 at 15:13
  • Yes, I can. Sorry I didn't mention that I added aditional line in pg_hba.conf `host all all 10.20110.0/0 md5` – Kosta Jul 19 '20 at 16:23
  • So you only see the failure when the connection needs to fetch the password from .pgpass, correct? What is the actual error message you get? – Adrian Klaver Jul 19 '20 at 16:45
  • Yes. I am getting following error: `fe_sendauth: no password supplied with pgpass`. You can see the pgpass content in my post. I also can see that pgpass will be checked, as when I am using wrong permissions system ask me to change it to 0600. So right now it is on 0600. – Kosta Jul 19 '20 at 18:19
  • I can't find ```fe_sendauth: no password supplied with pgpass``` anywhere in the community Postgres 11 source. When I replicate your issue I get ```psql: error: could not connect to server: fe_sendauth: no password supplied``` Where did you get your Postgres software and how was it installed? – Adrian Klaver Jul 19 '20 at 19:15
  • Further testing git this:```psql: error: could not connect to server: FATAL: password authentication failed for user "postgres" password retrieved from file "/home/aklaver/.pgpass"``` for the case where the user ```postgres``` had no password set in the database. Have you created a password for the ```postgres``` user? – Adrian Klaver Jul 19 '20 at 19:26
  • Sorry for late response. Sorry this was my mistake. Error is `psql: fe_sendauth: no password supplied`. I can't tell you from where Software is comming. I got the server with already pre installed application. I just installed psql on my machine. – Kosta Jul 21 '20 at 07:29
  • Postgres has a password. To be sure I just created a new user and configured it in the same way to make sure that it has a password. But I am getting the same output. I was using following command on DB Server for user creation `sudo -u postgres createuser -P -d UserName`. – Kosta Jul 21 '20 at 07:47
  • When you created new user did you add them to .pgpass? Have you tried reentering the information in .pgpass, maybe there is a hidden character causing problems? What OS and version? Did the preinstalled server already have psql? Might want to search for versions of psql to see if this is version library issue? – Adrian Klaver Jul 21 '20 at 14:37
  • Yes I did and also tried to reenter the data into .pgpass... It hasn't so I installed psql by maself. I used the same version as postgres server (11). For now I am running tests and can leave with trust setting. In a future I will try to reinstall this. It seems to be an unusual issue. Thanks for your support! – Kosta Jul 26 '20 at 09:18

0 Answers0