简体   繁体   中英

Remote Connection to PostgreSQL in a Raspberry Pi 2

I have a raspberry pi 2 with Debian Jessie OS. I want to connect remotely to postgresql in it.

I installed postgresql with command below:

sudo apt-get install postgresql postgresql-contrib

Then I set a password for postgres user:

sudo -u postgres psql postgres

Added below line to /etc/postgresql/9.4/main/pg_hba.conf

host  all  all 192.168.1.0/24 md5

and below line to /etc/postgresql/9.4/main/postgresql.conf

listen_addresses = '*'

Finally I restarted postgresql service:

sudo /etc/init.d/postgresql reload
sudo /etc/init.d/postgresql restart

But when I tried to connect to postgresql server from another pc in 192.168.1.0/24 network I get "server doesn't listen" error from pgadmin.

Also when I use "netstat -an | grep 5432" command, there is nothing.

result of "sudo /etc/init.d/postgresql status" is:

● postgresql.service - PostgreSQL RDBMS
   Loaded: loaded (/lib/systemd/system/postgresql.service; enabled)
   Active: active (exited) since Sat 2016-02-20 15:22:22 UTC; 50min ago
  Process: 21070 ExecReload=/bin/true (code=exited, status=0/SUCCESS)
  Process: 21119 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 21119 (code=exited, status=0/SUCCESS)

Feb 20 15:22:22 raspberrypi systemd[1]: Starting PostgreSQL RDBMS...
Feb 20 15:22:22 raspberrypi systemd[1]: Started PostgreSQL RDBMS.

So I cant get the problem. Is it about Debian Jessie OS or raspberry pi 2 or another thing?

I have just done same things in an Ubuntu machine and everything is fine.

I have ran into a similar problem wherein I get an error message saying "unable to connect to server" when i try to connect through my laptop.

The precise error message is Unable to connect to server:

FATAL: no pg_hba.conf entry for host "192.168.2.6", user "vivek", database "vivekdb", SSL off FATAL: no pg_hba.conf entry for host "192.168.2.6", user "vivek", database "vivekdb", SSL on

I have followed the exact same steps stated above.

This is an old post but for some reason I ended up here too. I beleive the fix for this is to change the IPV4 and IPV6 addresses in the pg_hba config file /etc/postgresql/XX/main/pg_hba.conf to:

127.0.0.1/32 to 0.0.0.0/0 for IPv4 
::1/128 to ::/0 for IPv6 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM