When attempting to add a server (this is my first install)
Configuration:
postgres 12
centos 7
pgadmin 4
I get
could not connect to server: Permission denied
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Permission denied
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
per
SHOW listen_addresses;
listen_addresses
------------------
localhost
I can network connect from psql
psql -h localhost aps19
psql (12.1, server 9.2.24)
Type "help" for help.
aps19=>
I am listening on port 5432
I am able to make TCP connections from java from my localhost
postgres>psql
psql (12.1, server 9.2.24)
Type "help" for help.
xxx=> show port
xxx-> ;
port
------
5432
per How connect Postgres to localhost server using pgAdmin on Ubuntu?
psql (12.1, server 9.2.24)
Type "help" for help.
postgres=#
postgres=# alter user postgres with password 'postgres';
ALTER ROLE
postgres=#
also
netstat -a | grep 5432
unix 2 [ ACC ] STREAM LISTENING 30611 /tmp/.s.PGSQL.5432
unix 2 [ ACC ] STREAM LISTENING 30602 /var/run/postgresql/.s.PGSQL.5432
use the "ifconfig" cmd to find real docker ip which name is dock0.
And then use it as username to login.
Related
I got strange behavior from dblink_connect.
I run my postgresql's servers using docker, mapped 5432 to localhost:5433.
When I am connecting to it using psql everything is fine
$ psql 'postgresql://pguser:pgpass#localhost:5433/mt5?sslmode=disable'
psql (14.4, server 10.22)
But when I connect to it from another postgresql's instance using dblink_connect it fails
psql 'postgresql://pguser:pgpass#localhost:5431/pgdb?sslmode=disable'
psql (14.4, server 14.3)
Type "help" for help.
pgdb=# select dblink_connect('postgresql://pguser:pgpass#localhost:5433/mt5?sslmode=disable');
ERROR: could not establish connection
DETAIL: connection to server at "localhost" (127.0.0.1), port 5433 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (::1), port 5433 failed: Address not available
Is the server running on that host and accepting TCP/IP connections?
I found the cause of error: as both instances are docker's they can't see each other as localhost: you have to use IP address of you internal network to which they exposed, like 192.168.88.22:
pgdb=# select dblink_connect('postgresql://pguser:pgpass#192.168.88.22:5433/mt5?sslmode=disable');
dblink_connect
----------------
OK
(1 row)
I figured this out while asking question!
Suppose it will help to somebody else.
I'm running Ubuntu WSL 2 on Windows 10. Before I installed WSL I already had Postgresql installed on my Windows 10. I wanted to connect to the database from WSL but so far it fails.
When running:
psql
I get:
psql: error: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
When running:
psql -h 127.0.0.1 -p 5432 -U postgres
I get:
psql: error: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
And WSL clearly doesn't see the database. When running this:
sudo service postgresql start
It returns:
postgresql: unrecognized service
I know that one solution is to install the database in WSL but wanted to try to connect to existing instance first.
You should edit pg_hba.conf
check wsl subnet
execute ipconfig from cmd. Below is example.
Ethernet Adapter vEthernet (WSL)
IPv4 Address . . . . . . . . . . . .: 172.19.230.81
edit pg_hba.conf
pg_hba.conf path is C:\Program Files\PostgreSQL\{postgresqlVersion}\data\pg_hba.conf. if you installed Windows Postgresql default install path.
subnet mask is use value from ipconfig
host all all 172.19.230.0/24 md5
restart postgresql
you can restart postgresql from services.msc. service name is postgresql-x64-{postgresqlVersion}.
access from psql
psql -h 172.19.230.81 -p 5432 -U postgres
I have a server with Postgres installed and I want to allow the connection from external IP's. Postgres works very well for local connections, then at the end of the file /var/lib/pgsql/data/postgressql.conf I added:
listen_addresses = '*'
And in the end of /var/pgsql/data/pg_hba.conf I added:
host all all 0.0.0.0/0 md5
host all all ::/0 md5
Then I restarted postgres with: sudo systemctl restart postgresql
And tried to connect with: psql -h my.db.server.ip -U postgres
And I get:
psql: could not connect to server: No existe ninguna ruta hasta el «host»
Is the server running on host "my.db.server.ip and accepting
TCP/IP connections on port 5432?
I am using Centos 7 and PostgreSQL 9.2.23
What else should I do?
Use
netstat -an | grep 5432
on the server to see if anything is listening on port 5432.
See what port is set to in postgresql.conf.
Use lsof on the PostgreSQL server process to see what sockets PostgreSQL is listening on.
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
This question already has answers here:
Connection refused (PGError) (postgresql and rails)
(6 answers)
Closed 9 years ago.
I am trying to connect postgresql but I am getting this error.
org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
My pg_hba.conf file is like this.
TYPE DATABASE USER CIDR-ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
I would be much obliged if anyone please be so kind enough to explain whats hoing on here and how should I correct it.
The error you quote has nothing to do with pg_hba.conf; it's failing to connect, not failing to authorize the connection.
Do what the error message says:
Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections
You haven't shown the command that produces the error. Assuming you're connecting on localhost port 5432 (the defaults for a standard PostgreSQL install), then either:
PostgreSQL isn't running
PostgreSQL isn't listening for TCP/IP connections (listen_addresses in postgresql.conf)
PostgreSQL is only listening on IPv4 (0.0.0.0 or 127.0.0.1) and you're connecting on IPv6 (::1) or vice versa. This seems to be an issue on some older Mac OS X versions that have weird IPv6 socket behaviour, and on some older Windows versions.
PostgreSQL is listening on a different port to the one you're connecting on
(unlikely) there's an iptables rule blocking loopback connections
(If you are not connecting on localhost, it may also be a network firewall that's blocking TCP/IP connections, but I'm guessing you're using the defaults since you didn't say).
So ... check those:
ps -f -u postgres should list postgres processes
sudo lsof -n -u postgres |grep LISTEN or sudo netstat -ltnp | grep postgres should show the TCP/IP addresses and ports PostgreSQL is listening on
BTW, I think you must be on an old version. On my 9.3 install, the error is rather more detailed:
$ psql -h localhost -p 12345
psql: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 12345?