If you get an error when you try to connect to your PostgreSQL database cluster, there are several possible causes and fixes depending on the error. Look up the error you’re receiving below and try the suggested solutions.
Before you begin troubleshooting, check the DigitalOcean status page for ongoing issues in your database’s region.
psql: could not connect to server: Connection refused Is the server running on host "HOSTNAME" (HOSTNAME_DNS) and accepting TCP/IP connections on port PORT?
This error means that the server is denying the connection.
Connecting from a computer that is is not allowed in the database’s inbound sources.
Using the wrong port in the connection string
Make sure your computer is allowed in your database’s inbound sources.
Check the port in the connection string.
If you still receive this error, you may have a firewall or local DNS issue.
psql: could not connect to server: Connection refused Is the server running on host "IP_ADDRESS" and accepting TCP/IP connections on port PORT?
This error means your computer can’t find a route to the database.
Using the wrong IP address in the connection string
Using the database’s private IP address in the connection string and trying to connect from a Droplet that isn’t allowed to access the private network
Check the IP address in the connection string or use the database’s hostname. We recommend using the hostname over the IP address because the IP address may change, but the hostname will always remain the same.
If you’re using the database’s private IP address, make sure you’re connecting from a Droplet that meets the following criteria:
bash: postgresql://USERNAME:PASSWORD@HOSTNAME:PORT/DBNAME?PARAM: No such file or directory
This error means that the terminal couldn’t execute the command.
psqlbefore the text of the connection string to connect to the database. For detailed instructions, read How to Connect to PostgreSQL Databases with
psql: FATAL: password authentication failed for user "USERNAME"
This error means that the server rejected the credentials in the connection string.
Connecting to the wrong database cluster
Using the wrong username or password
psql: could not translate host name "HOSTNAME" to address: Name or service not known
This error means that
psql couldn’t find the host you were trying to connect to.
Using the wrong hostname
Problems with DNS resolution
If the hostname isn’t the problem, the computer you’re connecting from may be having problems with DNS resolution.
psql: FATAL: database "DBNAME" does not exist
This error means the server couldn’t find the database name you specified.
Connecting to the wrong cluster
Connecting to a database that doesn’t exist in the cluster
Make sure you’re using the right hostname for the cluster.
Check that you’ve created the database in the cluster.
psql: invalid URI query parameter: "PARAM"
psql: invalid PARAM value: "VALUE"
These errors mean that one of the arguments to
psql was incorrectly formatted.