I'm struggling to enable remote access for Postgres DB version 9.6 on MacOS Sierra.
What I have done so far:
modify postgres.conf, set listen_addresses = "*"
modify pg_hb.conf, add these lines:
host all all 0.0.0.0/0 md5
host all all * md5
I checked the Firewall setting (GUI), and see the postgres process is allowing incoming connections.
From PgAdmin tool running on the macOS machine, I can use the ip of macOS machine to connect to the PG database.
The result of running netstat -an | grep 5432:
tcp4 0 0 *.5432 . LISTEN
tcp6 0 0 *.5432 . LISTEN
d06ae6d89823b48f stream 0 0 d06ae6d89b32fcb7 0 0 0 /tmp/.s.PGSQL.5432
However, I couldn't access to the PG database from another machine in same wifi network. (I can ping the ip of the PG database machine).
Any idea of suggestion is highly appreciate.
Thanks.
Related
I have a Debian 9 machine with a PostgreSQL (PSQL) 9.6 server installed.
This PSQL server does not accept any connexion from other machines (only from itself).
I have been doing my best to work out this problem and I guess some of you will think this is a topic for a PostgreSQL forum, BUT let me explain :
I also have a Ubuntu 16.04 machin running also a PostgreSQL 9.5 server and I don't have this problem with it.
Other-than-PSQL connexions to both the Debian and the Ubuntu machines coming from other machines (ping, x2gp) work fine. Firewalls are deactivated.
The PSQL server rules for accepting connexions is based on a config file called pg_hba.conf. Its content on the Debian machine is :
# Database administrative login by Unix domain socket
local all postgres md5
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all 192.168.1.0/24 md5
On the Ubuntu machine, the file is very similar :
# Database administrative login by Unix domain socket
local all postgres md5
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all 192.168.1.0/24 md5
I also tried copying-pasting the config_file from the Ubuntu machine to the Debian one to see if it worked. It did not.
Of course, I don't forget restarting the PSQL server.
Now when I do a netstat -an | grep 5432 (PSQL server listens on port 5432), on the Debian machine, I get :
$ netstat -an | grep 5432
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN
tcp6 0 0 ::1:5432 :::* LISTEN
unix 2 [ ACC ] STREAM LISTENING 15854569 /var/run/postgresql/.s.PGSQL.5432
From the little I understand about networks, this means indeed that the machine only listen on the 5432 port for localhost inbound connexions.
But when I do the same on the Ubuntu machine, I get :
$ netstat -an | grep 5432
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN
tcp6 0 0 :::5432 :::* LISTEN
unix 2 [ ACC ] STREAM LISTENING 19472 /var/run/postgresql/.s.PGSQL.5432
which means, I believe, it listens to inbound connexions from any IP address.
But why ?
Why this difference in behaviour between the two machines ?
Look at your postgresql.conf, look for listen_addresses, you should have 0.0.0.0 for ipv4 and :: for ipv6.
Description -> https://www.postgresql.org/docs/9.1/static/runtime-config-connection.html
And, after my comment in your answer, I just noticed that the line
#listen_addresses = 'localhost'
started with a #.
I deleted it to un-comment the line so that it is operational and now it works.
Thanks !
I'm struggling to enable remote connection on Postgres running on Ubuntu. I've done the following steps:
Opened up the firewall; running sudo netstat -ntlp | grep LISTEN gives me:
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 2947/postgres
Added in listen_addresses to postgresql.conf:
listen_addresses='*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
Added in the connection table in pg_hba.conf as follows:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
I can connect locally but I cannot connect remotely; not even connecting via telnet works. It just says connection refused. Has anyone got an idea as to the cause of the problem?
Thanks.
Cheers,
Neil
Restart postgres
Check if it's listening on all interfaces
# netstat -lnp --tcp | grep postgres
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 6096/postgres
Add host line to pg_hba.conf:
host all all 0.0.0.0/0 md5
Add a password for your user
$ sudo -u postgres psql
postgres=# \password username
I recently installed postgresql on my ubuntu 14.04 vm, but I can't seem to be able to connect to my database from localhost: postgres://127.0.0.1:5432/mydb?sslmode=disable is not found, although psql mydb brings me to the correct terminal, sudo netstat -plunt |grep postgres returns nothing, but su postgres -c "netstat -plunt |grep postgres" prints:
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 31/postgres
tcp6 0 0 ::1:5432 :::* LISTEN 31/postgres
So it's clearly there, just somehow under the postgres ubuntu user (but with the database belonging to root). I know that there is a way to reconfigure my postgresql installation such that it can be reached through localhost (postgres://127.0.0.1:5432/mydb?sslmode=disable works), and if anyone could tell me what I need to do, that would be awesome. Thank you!
I have installed Postgres 8.4 on Centos 6.4 64 bit by yum. I want to manage Postgres Databases with phpPgAdmin-5.0.4-1 installed by yun too (like MySQL and phpMyadmmin)
After install phpPgAdmin-5.0.4-1 I cannot login to phpPgAdmin by access 192.168.7.4/phpPgAdmin/ (192.168.7.4 is my Centos server), it always says "Login failed" although I'm sure that I enter username (postgres) and password right
Here are my information, hope you can help :
netstat -tupln | grep postmaster
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 771/postmaster
tcp 0 0 :::5432 :::* LISTEN 771/postmaster
/etc/phpPgAdmin/config.inc.php
$conf['servers'][0]['desc'] = 'PostgreSQL';
$conf['servers'][0]['host'] = '192.168.7.4';
$conf['extra_login_security'] = false;
/var/lib/pgsql/data/postgresql.conf
listen_addresses = '*'
/var/lib/pgsql/data/pg_hba.conf
local all all ident
# IPv4 local connections:
host all all 127.0.0.1/32 ident
# IPv6 local connections:
host all all ::1/128 ident
Thanks in advance.
Your setup if fine except for pg_hba.conf which lacks an entry for 192.168.7.4.
Consider adding it and reload the postgresql service:
host all all 192.168.7.4/32 md5
I tried the above solution but still got the 'Login Failed' message. To resolve, I had to ensure IPv6 is set to password in the pg_hba.conf file. So do: vi /var/lib/pgsql/9.4/data/pg_hba.conf and edit accordingly. Then restart both httpd & postgresql (whatever the version you are using)
Hello all :) I'm a having a little trouble connecting this.
On Windows 7 about my Debian 6 on VitualBox configured with Host-only Adapter:
>nmap -T4 -A -v 192.168.56.1
[...]
5432/tcp unknown postgresql
On the Debian, PostgreSQl is listening:
>netstat -tulpn
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 2432/postgres
tcp6 0 0 :::5432 :::* LISTEN 2432/postgres
.. and the port is opened
>iptables -nL
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0./0 tcp dpt:5432
.. and Postgres is accepting all the connections in postgresql.conf
listen-addresses = '*'
port = 5432
In Windows I have this error message from pdAdmin:
Server doesn't listen
The server doesn't accept connections: the connection library reports
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "192.168.56.1" and accepting TCP/IP
connections on port 5432?
If you encounter this message, please check if the server you're trying
to contact is actually running PostgreSQL on the given port.
Test if you have network connectivity from your client to the server
host using ping or equivalent tools. Is your network / VPN / SSH tunnel /
firewall configured correctly?
For security reasons, PostgreSQL does not listen on all available
IP addresses on the server machine initially. In order to access
the server over the network, you need to enable listening on the
address first.
For PostgreSQL servers starting with version 8.0, this is controlled
using the "listen_addresses" parameter in the postgresql.conf file.
Here, you can enter a list of IP addresses the server should listen
on, or simply use '*' to listen on all available IP addresses. For
earlier servers (Version 7.3 or 7.4), you'll need to set the
"tcpip_socket" parameter to 'true'.
You can use the postgresql.conf editor that is built into pgAdmin III
to edit the postgresql.conf configuration file. After changing this
file, you need to restart the server process to make the setting effective.
If you double-checked your configuration but still get this error
message, it's still unlikely that you encounter a fatal PostgreSQL
misbehaviour. You probably have some low level network connectivity
problems (e.g. firewall configuration). Please check this thoroughly
before reporting a bug to the PostgreSQL community.
Best regards
What about your pg_hba.conf file?
Have you configured it to accept connections from hosts in the 192.168.56.0 network?
Try to add this line and restart Postgres:
# VitualBox Host-Only Adapter
host all all 192.168.56.0/24 md5
If it's a testing environment you could even replace 192.168.56.0/24 with 0.0.0.0/0 and forget about it.