server refuses connection after enabling ssl on Postgres 14 server on ubuntu 20.04 - postgresql

I am following a couple of online post to enable ssl on Postgres 14 server on ubuntu 20.04. Generate CA and server keys, setup postgresql.conf and pg_hba.conf, also stop and start the Postgres server. show ssl is on.
However sudo -U postgres and psql -h mydomain.com throws error:
psql: error: connection to server at "mydomain.com" (xxx.xxx.xxx.141), port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
It seems that the problem is with pg_hba.conf. What I did is to add the following line at the end of the file, without changing anything else:
hostssl all all 0.0.0.0/0 scram-sha-256 clientcert=verify-full

Related

connect pgadmin3 to postgres runnng on server

** new to pgadmin and postgress **
my organization uses PostgreSQL on its server with ubuntu os, I try to connect it using pgadmin 3,
these are the stapes I have taken
changed pg_hba.conf using 'sudo nano /etc/postgresql/9.3/main/pg_hba.conf'
changed listen_addresses='*' in postgresql.conf file
sudo ufw allow 5432/tcp
but still, I am unable to connect I get this error from pg admin:
Server doesn't listen
The server doesn't accept connections: the connection library reports could not connect to server: Connection timed out Is the server running on host "103.72.131.155" and accepting TCP/IP connections on port 5432?
how can I fix it,
is there any website which can guide me step by step to connect pgadmin to PostgreSQL.

Cant access database from pgAdmin

I`m using postgresql database on my web server (ubuntu + nginx) and it works with backend app. I want to connect remotely using pgAdmin
but it always throw this error:
could not connect to server: Connection timed out(0x0000274C/10060)
Is the server running on host "ip" and accepting
TCP/IP connections on port 5432?
I already add to my pg_hba.conf this line:
host all all all password
and also add to postgresql.conf line:
listen_addresses = '*'
netstat -nlt does next result, and it`s enough in tutuorials i found, but still cant access my database
Found a solution, it works as well after this command:
sudo ufw allow 5432/tcp
Open file named pg_hba.conf
sudo vi pg_hba.conf
and add this line to that file
host all all 0.0.0.0/0 md5
It allows access to all databases for all users with an encrypted password
restart your server
sudo /etc/init.d/postgresql restart

Postgres remote connection

Hello I have installed PostgresSQL 11 on CentOS Linux release 7.6.1810.
I have edited files pg_hba.conf
host all all all md5
And postgresql.conf
listen_addresses = '*'
However, following a restart I am unable to connect from pgAdmin with error:
could not connect to server: Connection refused (0x0000274D/10061) Is
the server running on host "10.190.9.130" and accepting TCP/IP
connections on port 5432?
If I run Docker container on the same server with postgres it connects successfully. Has anyone had this issue with a manual postgres install?

PSQL: SSL error: unknown protocol

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?
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

Postgresql connection via terminal - pgadmin

I have a problem connecting (using SSH) to my virtualbox(ubuntu) postgres server.
I set up all nice and correctly.
PostgreSQL settings:
postgresql.conf -> Allowed all incomming connection (*) and set ssl TRUE
pg_hba.conf -> after a lot of changes i came to the point where it seems to work with this settings:
IP4
host all all 0.0.0.0/0 trust
hostssl all all 0.0.0.0/0 trust
host all all 192.168.x.x/32 trust
hostssl all all 192.168.x.x/32 trust
I tried:
Made restart of my postgres server on the virtual machine.
Then i went to my host machine (Snow Leopard), build a ssh connection to the virtualbox (ubuntu) and it's working.
ping my guest machine on port 5432 also works.
Open pgadmin on my host machine (Snow Leopard) -> added server 192.68.56.1 and database pluto, user pippo. The connection worked and i see the DB.
Tried open TERMINAL in Snow Leopard and executed following cmd:
psql -h 192.168.56.1 -U pippo -d pluto
with ERROR:
psql: FATAL: no pg_hba.conf entry for host "192.168.56.1",
user "pippo", database "pluto", SSL off
I also tried to connect through my Java Program ans I got the same error.
What am I doing wrong?
pgAdmin tries to connect with and without SSL by default.
I suspect that you only try to connect without SSL via psql, while the server seems to require SSL for connections. Try:
psql "sslmode=require host=192.168.56.1 dbname=pluto" pippo
More about sslmode in the manual.
Open my query into pgAdmin from command line:
-f The file containing your SQL script to be loaded in the query window
-qc The connection string without password (you can also use ssl connections)
"C:\Program Files\PostgreSQL\9.4\bin\pgAdmin3.exe" -f "C:\slqFiles\FindFunctionByName.sql" -qc "host=localhost port=5432 dbname=myDatabase user=postgres"
The password will be collected from the password file located in the application folder: %APPDATA%\postgresql\pgpass.conf
You need permissions for connection. Try to add to C:\Program Files\PostgreSQL\9.6\data\pg_hba.conf next line:
host all all ::/0 trust