PSQL: SSL error: unknown protocol

2019-07-03 18:40发布

问题:

all. I have a new Ubuntu 17.04 server setup. I can access it through ssh successfully. Also, I have a postgresql database installed. It is already configured to accept remote connections through the following configurations:

pg_hba.conf

host all all 0.0.0.0/0  md5

postgresql.conf

listen_addresses = '*' 

But when I try to access the database from my computer, I get the following error:

psql -h [SERVER_IP]  -d db_production -U dbuser 
psql: SSL error: unknown protocol
expected authentication request from server, but received S

I also have a docker container running inside the server. If I access it through /bin/bash and also try to connect with the server db, I get this error:

psql -h [SERVER_IP]  -d db_production -U dbuser
psql: could not connect to server: Connection refused
    Is the server running on host "[SERVER_IP]" and accepting
    TCP/IP connections on port 5432?

The port 5432 is opened and the firewall is disabled. Does anybody have gone through that?

回答1:

First, do you use the local server host when you're connected into the docker? The server IP, in that case, should be localhost or 127.0.0.1.

Try to use the complete DB URL:

psql postgres://dbuser:dbPass@SERVER_IP:5432/dbname?sslmode=prefer