Connecting to the PostgreSQL database remotely (via an SSH Tunnel)
To make a connection to the database server from a remote machine you need to setup an SSH tunnel. Direct connections to the database server are firewalled to security reasons. The SSH tunnel provides a secure and authenticated means of talking to the database server.
The SSH tunnel maps a port on your machine to the same port on the database server.
Setting up an SSH tunnel using Putty
Startup Putty on your local machine.
Go to the Connection -> SSH -> Tunnels menu.
- In the section 'Port forwarding' set the source port to 5432
- Set the destination to 127.0.0.1:5432
- Check the 'Local' option.
- Click the 'Add' button.
Then initialise an SSH connection to your web hosting account. Even if you are not using putty, the putty session needs to remain open to connect to the database.
Setting up an SSH Tunnel via the command line
From your terminal run the command:
ssh USERNAME@DOMAINNAME -L 5432 127.0.0.1:5432
- USERNAME is the username you use to connect to the server
- DOMAINNAME is your websites domain
Once this has been done you will be able to access the PostgreSQL database as if it was running on your own machine. This means you will be able to use localhost as the hostname and the usual PostgreSQL port 5432 as well as your usual postgreSQL database username and password.
If you need any assistance with this, please contact support at firstname.lastname@example.org or 1300 883 979.