I have a server with PostgreSQL installed and there are scripts that are constantly modifying data in the database. PostgreSQL is running on it's default port 5432.

I would like to be able to connect to the database from my website, which is just a standard bought hosting with godaddy.

I know I can't reach the database because it is not accessible to the web but is it possible to make my database available online so that my website can communicate with it?


You need the GoDaddy server to be allowed to be connected outside. This is not always the case with hosted websites: since they're only expected to allow others to connect on ports 80 or 443, and possibly send out connections to the hoster's email or database servers, all other connections may be firewalled out.

Then you need your server to be allowed to accept connections. One workaround would be to be allowed to establish a VPN between the GoDaddy server and the PostgreSQL server. Otherwise the PostgreSQL server's firewall must be opened towards GoDaddy (or towards anyone). This entails a security risk.

Using SSH, you can use port forwarding (also known as ssh tunnel) from the psql machine to the apache machine. You can open the connection from either side (but the syntax is slightly different). e.g.

ssh useronpostgres@postgresmachine [other options] -L 5432:localhost:5432

run on the webmachine, will create a local PostgreSQL port on the webmachine, so that the website can "see" a local PostgreSQL which is actually running on the PostgreSQL machine.

Finally your website needs to be able to "speak" PostgreSQL. Simple connection is not enough, i.e., having the port available is necessary, but not sufficient per se. If the site is developed in, say, Perl or PHP, there are PDO modules with pgsql/psql drivers; chances are that they're currently not installed, the usual choice being MySQL, not PostgreSQL. If that's really the case, you'll need to request a configuration change.

There also are "thin connectors" for several databases that allow REST access to MySQL or PostgreSQL through REST APIs (e.g. ArrestDB or others; see also this SO question); if there is not already a web server on the PostgreSQL server, you can try installing one of those. This would allow access from the website through port 80, with some limitations in syntax and capabilities, but no need of specialized drivers on the GoDaddy side. You need to evaluate whether this last is an acceptable compromise.

A wide access to PostgreSQL can also be supplied by installing phpPgAdmin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.