The first thing to do if you want to connect to PostgreSQL on your Raspberry is to configure PostgreSQL to accept remote connections:
- Allow incoming/outgoing connections setting firewall rules with
$ iptables -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW, ESTABLISHED -j ACCEPT
$ iptables -A OUTPUT -o eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT
$ iptables -A OUTPUT -o eth0 -p tcp --dport 22 -m state --state NEW, ESTABLISHED -j ACCEPT
$ iptables -A INPUT -i eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT
pg_hba.conffile, insert the following raw:
# TYPE DATABASE USER ADDRESS METHOD
host all all XXX.XXX.XXX.XX/32 md5
XXX.XXX.XXX.XXis the IP address of the remote machine.
postgresql.conffile, insert the following raw:
listen_addresses = '*'
to allow listening from all sources.
…then perform the connection with pgAdminIII
The easiest way to connect with a PostgreSQL server based on a Raspberry PI from a remote machine is to use pgAdminIII. This is a graphical client that can be easily installed on a Debian machine with
sudo apt-get install pgadmin3
Once is launched, select
File from the menu and then select
fill the fields of the connection form: host name, port number, user and database. If
Store password is ticked, credentials are stored in the
Once the connection is stored, can be used just with a mouse click. Then, Raspberry PI database can be explored with the pgAdminIII browser.