psql with source IP anchoring - postgresql

I am using PostgreSQL flexible server by MSAzure.
The server is not setting any connection restriction and allows connections from all IPs.
I can access to the server with psql command normally.
psql "host=.postgres.database.azure.com port=5432 dbname=postgres user=myadmin password= sslmode=require"
However, with the Source IP anchoring function by Zscaler Internet Access, it fails.
psql: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request.
I could not find the error logs from server side.
Also I checked the packet and it seems the server sends RST packet as soon as it received connection request message from client.
enter image description here
Source IP Anchoring(SIPA) is a function which fixes source IP by transferring the packet to the proxy cloud, and from proxy cloud to private VM. The VM takes over the connection to the destination server.
Client <-> Proxy Cloud <-> VM <-> sql server
So from client side, it looks like the client is connecting to the proxy cloud.
And from sql server, it seems the server is connecting to VM.
The VM only performs outbound connection and never allows inbound connection.
This means connection pushed from server to client is not supported (like P2P, Application lelvel gateway, SIP, RTSP, Bittorent).
Does Postgresql connection requires inbound connection from server to client?
I tried disabling SSL connection, but the result was same.
The client version and server version are both same.
Also I tried connecting from pgAdmin 4, but failed again.
I'll appreciate any clue on this.

Related

Synapse Notebook throws timeout error while connecting to AWS RDS SQL Server

I am working in the Synapse Workspace and trying to connect to AWS RDS from the Synapse Notebook.
Whenever I try to connect, it throws the below timeout error -
The TCP/IP connection to the host my-host, port 1433 has failed.
Error: "connect timed out.
Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port.
Make sure that TCP connections to the port are not blocked by a firewall.
To check whether I can ping the host from the Synapse Notebook - I tried the below code -
import subprocess
temp = subprocess.Popen(
['ping', '-c 1', 'my-host'], stdout = subprocess.PIPE)
output = str(temp.communicate())
print(output)
and this throws
ping statistics ---\n1 packets transmitted, 0 received, 100% packet loss
I get that this is the timeout error and the notebook cannot reach the server.
What is surprising is, if I try to connect to the same AWS RDS Server by creating a linked service from the Synapse pipeline, it connects successfully.
On my source AWS RDS, do I need to open the firewall for Synapse notebooks specifically? Is there any endpoint that I should mention in my notebook?
Also, Isn't it handled at the resource group level?
Any help is appreciated.
Thank you,
Sanket Kelkar
If you have already configured your database to listen on TCP/IP traffic on port 1433 then it could be any of following three reasons:
JDBC connection string might be incorrect.
Firewall is blocking the incoming connection. Make sure that it is publicly accessible. You can check this when you check the availability.
AWS RDS SQL database is not running. Ensure that "available" is shown as the status.
make sure you specify the port 1433 while creating SQL server.
Check to see if your DB instance can be accessed by the inbound rules of your VPC security group. For more information, see Can't connect to Amazon RDS DB instance.

PostgreSQL remote connection outside local network

I manage a postgresql DB on a windows server, the local connection with a client workstation on the postgresql server works perfectly, but when leaving the local network, the connection fails. I have tried several configurations offered on similar topics, but without success.
Here are some solutions already tried:
listen_addresses = '*'
port = 5432
host all all 0.0.0.0/0 md5 ... host all all 0.0.0.0/0 trust ... client side and server side postgresql
I disabled Windows Firewall and created specific inbound / outbound traffic rules for port 5432 ... client side and server windows side
I tried to create an ssh tunnel via psql, python or the pgAgmin interface but I got stuck on this message: "Failed to create the SSH tunnel. Error: Could not establish session to SSH gateway"
I am convinced that I am wrong on a configuration, but which one? This is the subject of my request ...
Does anyone know how to help me?
thank you,

PGAdmin III cannot connect AWS RDS

I am trying to connect AWS RDS PostgreSql from PgAdmin 3. I followed the below link
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToPostgreSQLInstance.html
In Security Group, I also added PostgreSQL and All traffic as below
The "publicly accessible" flag was enabled (updated after Mark B's comment)
I got the error from PGAdmin3
Very appreciate for any suggestion
******UPDATE*******
I can connect pgAdminIII to AWS RDS successfully using home wifi, but cannot connect using office wifi.
My concern is:
Was the port 5432 blocked by office wifi?
How can I configure/update the port without impacting to current API?
Note: My current API is working well (CRUD)
Can you can test your connection to a DB instance using common Linux or Windows tools first?
From a Linux or Unix terminal, you can test the connection by typing the following (replace with the endpoint and with the port of your DB instance):
$nc -zv DB-instance-endpoint port
For example, the following shows a sample command and the return value:
$nc -zv postgresql1.c6c8mn7tsdgv0.us-west-2.rds.amazonaws.com 8299
Connection to postgresql1.c6c8mn7tsdgv0.us-west-2.rds.amazonaws.com
8299 port [tcp/vvr-data] succeeded!
Windows users can use Telnet to test the connection to a DB instance. Note that Telnet actions are not supported other than for testing the connection. If a connection is successful, the action returns no message. If a connection is not successful, you receive an error message such as the following:
C:>telnet sg-postgresql1.c6c8mntzhgv0.us-west-2.rds.amazonaws.com
8299
Connecting To sg-postgresql1.c6c8mntzhgv0.us-west-2.rds.amazonaws.com...Could not
open connection to the host, on port 819: Connect failed
If Telnet actions return success, then you are good to go.
If you are trying to access it from a network which is not listed for that port. you need to add inbound rules for those network IPs from AMAZON RDS system
You will also need to set Public accessibility true under Connect & security tab in RDS console.
Read this post.In your security group go to unbound rules and add my ip.
and make sure your database is public.
https://serverfault.com/questions/656079/unable-to-connect-to-public-postgresql-rds-instance

Is there any issue using the same postgresql database for two different servers?

I am using postgres database which is accessed by jboss and tomcat server.
My server accidentally restarted and then postgres service was not showing in the services list.
When I tried to open postgres local host server using pgadminIII it showed following error:
Server doesn't listen
The server doesn't accept connections: the connection library reports
could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?
If you encounter this message, please check if the server you're trying to contact is actually running PostgreSQL on the given port. Test if you have network connectivity from your client to the server host using ping or equivalent tools. Is your network / VPN / SSH tunnel / firewall configured correctly?
For security reasons, PostgreSQL does not listen on all available IP addresses on the server machine initially. In order to access the server over the network, you need to enable listening on the address first.
For PostgreSQL servers starting with version 8.0, this is controlled using the "listen_addresses" parameter in the postgresql.conf file. Here, you can enter a list of IP addresses the server should listen on, or simply use '*' to listen on all available IP addresses. For earlier servers (Version 7.3 or 7.4), you'll need to set the "tcpip_socket" parameter to 'true'.
You can use the postgresql.conf editor that is built into pgAdmin III to edit the postgresql.conf configuration file. After changing this file, you need to restart the server process to make the setting effective.
If you double-checked your configuration but still get this error message, it's still unlikely that you encounter a fatal PostgreSQL misbehaviour. You probably have some low level network connectivity problems (e.g. firewall configuration). Please check this thoroughly before reporting a bug to the PostgreSQL community.
Does this problem arise due to accessing same DB by two different servers?
My server accidentally restarted and then postgres service was not
showing in the services list.
You can't connect because it's not running. You can have as many clients connecting to a PostgreSQL server as your hardware can support - there is no problem with that.
Restart your PostgreSQL service. If it won't, check the logs for why. If you don't know where your PostgreSQL logs are now is a good time to find out. I can't tell you how to restart the service because you haven't said what OS you are running or how you installed PG. Check your documentation.

EC2 Internal Sockets

I'm trying to have two process communicate through a socket connection. One of these is a python app, and the other is a php script.
I've created and tested the client/server combination on my home computer and it functions properly. However, when I deploy onto an EC2 instance (ubuntu 10.10 64bit ami + apache + php) I get an unable to connect to socket error (111 Connection Refused) from the php script. The python app is able to bind to the socket and listen to messages but the php script is unable to send messages.
I've opened the required ports in the amazon security group and I can connect to the port externally using telnet. However if I attempt to connect with telnet from within the server I get the same connection refused error.
How can I solve this issue?
Edit: Both processes are on the same instance
The issue had nothing to do with EC2 explicitly. I was not binding to localhost, but instead binding to my hostname. On a local network that was the same as my localhost ip, however on ec2 it was not. Switching to binding to localhost fixed the issue.