How do external connection in database at gcloud - postgresql

I've created an instance in compute engine.
I did the installation of postgresql 9.6, , now i'm trying to connect in external ip using pgadmin client, but it give me an error
Connection to 35.224.170.161:5432 refused. Check that the hostname and
port are correct and that the postmaster is accepting TCP/IP
connections. Connection to 35.224.170.161:5432 refused. Check that
the hostname and port are correct and that the postmaster is accepting
TCP/IP connections.
Connection refused: connect
Connection refused: connect
I just can to access my database with putty, such as below...

https://cloud.google.com/community/tutorials/setting-up-postgres#connecting-remotely
open a port in the firewall on Cloud Platform to allow your IP
Edit pg_hba.conf to allow your IP
Edit postgresql.conf to listen on *

Related

psql: error: connection to server at "localhost"

Let me first mention I don't have admin privilege on my PC, So I could not install PostgreSQL with the normal process. I just download the binary files from here enterprisedb.com/download-postgresql-binaries,
and added it to environment variable paths.
My problem when I try to start a new server from pgAdmin it gives me the below error.
connection to server at "localhost" (::1), port 5432 failed: Connection refused
(0x0000274D/10061) Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
(0x0000274D/10061) Is the server running on that host and accepting TCP/IP connections?
I searched a lot for a solution
The first recommendation I got is to restart postgress from windows services but I couldn't find it.
Second recommendation was to edit the psogress config file but also I can't find it at all they say that I can find it in the main directory of postgress.

Postgres FDW connectivity issue from Azure RDS to AWS RDS

I was using FDW extension in PostgreSQL from 2 years to load data from one database to another database. Now, one of my RDS has been moved from AWS to Azure. Now, when I tries to make connection from Azure to AWS it says the host is invalid. So, in this case FDW doesn't works if the RDS are from different service?
Error:
Detail: could not connect to server: Network is down (0x00002742/10050)
Is the server running on host "xxxxx" (10.xx.xx.xx) and accepting
TCP/IP connections on port 5432?
could not connect to server: Network is down (0x00002742/10050)
Is the server running on host "xxxxx" (10.xx.xx.xx) and accepting
TCP/IP connections on port 5432?
could not connect to server: Network is down (0x00002742/10050)
Is the server running on host "xx" (10.xx.xx.xxx) and accepting
TCP/IP connections on port 5432?
could not connect to server: Network is down (0x00002742/10050)
Is the server running on host "xx" (10.xx.xx.xx) and accepting
TCP/IP connections on port 5432?```

Postgres pg_hba.conf localhost confusion

I've run into a scenario where an application couldn't see the database. My pg_hba.conf file had the following:
local all all trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
Security aside, the application was telling me it couldn't see the database at all, while other clients could see it:
PG::ConnectionBad: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
(Sequel::DatabaseConnectionError)
I had to point my application to the public IP of that box, and add that in my pg_hba.conf for it to work. Also, it was confused with localhost, as it apparently looked at the IP6 route then the IP4 route, both throwing an error:
Could not spawn process for application /var/www/pints: The application encountered the following error: PG::ConnectionBad: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
(Sequel::DatabaseConnectionError)
Question: What is the best way to force this into using the IP4 route, and to best use IP4 resources to handle communications while on the same box? localhost was blind, as was 127.0.0.1, so I'm confused. Cheers

How to connect pgadmin 4 to an external server?

I just created a server (droplets) in digital ocean, install postgresql, up there well, it works on the console. My problem is when I try to connect through pgadmin.
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "165.22.184.123" and accepting
TCP/IP connections on port 5432?
Look for information and modify the file
/etc/postgresql/10/main/postgresql.conf
where says listen_addresses='localhost' by listen_addresses='*'.
Also add a line to host all all 0.0.0.0/0 md5 to the file /etc/postgresql/10/main/pg_hba.conf and I still have the same problem. Do I have to do some additional configuration?

Debugging a PostgreSQL Remote Connection

I'm having issues connecting to my PostgreSQL database from an online source.
PostgreSQL seems to be setup up fine it is running on it's default port 5432 and the postgresql.conf has the following line
listen_addresses = '*'
And the pg_hba.conf has the following
host dbname usname all md5
I can connect to the PostgreSQL database from a different machine using the following credentials in pgadmin
Name local
Host 192.xx.xx.xx
Port 5432
Maintenance DB dbname
Username usname
Password psword
Using these I can connect perfectly it seems to work fine.
Then I forwarded the port 192.xx.xx.xx:5432 on the ADSL router and checked it using the public IP address 197.xx.xx.xx (visible to the internet IP)
http://www.canyouseeme.org/
Where I can see the port was forwarded ok.
However when I try to connect using
Name online
Host 197.xx.xx.xx
Port 5432
Maintenance DB dbname
Username usname
Password psword
I get the server doesn't listen error message
could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "197.xx.xx.xx" and accepting TCP/IP connections on port 5432?
Why is this? Do I need to add an extra step to making it accept connections through port forwarding?