Report this

What is the reason for this report?

Warning: pg_connect(): Unable to connect to PostgreSQL server:

Posted on January 4, 2017

i ve postgreSQL in my droplet ( ip= 139.59.xx.xx ) i can connect it with pgadminIII and valentina studio without problem. https://puu.sh/tblvZ/e6c876ed75.png

but im running php script on my Name.com hosting server and im getting some error

Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: Connection timed out Is the server running on host “139.59.xx.xx” and accepting TCP/IP connections on port 5432? in /home/f*****/public_html/xxxxx.xxxx.net/new.php on line 2 Error : Unable to open database

here is my php script which is running @ Name.com hosting server to connecto my droplet pgsql( ip= 139.59.xx.xx )

<?php $db = pg_connect(“host=139.59.xx.xx port=5432 dbname=xxxxxxx user=xxxxxx password=xxxxxxxx”); if(!$db){ echo “Error : Unable to open database\n”; } else { echo “Opened database successfully\n”; } ?>

what should i do about it ?

thanks



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

@canf113378ba95d

Run the following command via SSH (on your Droplet):

sudo ufw status

… to see if ufw is enabled (your firewall, which is standard on Ubuntu 16.x). If it is, you will need to allow the connection through the firewall.

To do this, you’d need to get the Dedicated or Shared IP address from name.com and then run:

sudo ufw allow from NAME_IP to any port 5432

… replace NAME_IP with the IP for your account.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.