3

I have a Windows 10 machine, and I would like to access a database which is set on another machine outside local network.

Is there any possibility of achieving that using postgresql?

Thank's a lot, and I'd appreciate your effort to help me overcome this situation.

2
  • This is going to need more information. Do you have control over the other database/machine? If you have control or not do you know the connection information(host, port, db name,etc) for that database? Do you have Postgres client installed on your local machine and if so what is it? Is there a firewall between you and the remote machine? Commented Oct 5, 2020 at 23:21
  • Hello Adrian, yes I do have control of the other database machine. Actually, to be more accurate, I need to make a java application for a business, which is going to be running on a client's computer (let's consider it computer n1). But I want the data to be stored on a database outside n1's local network where of course I'm going to have full information about it(host, port, database name etc.). Yes, I have postgres installed on the client's machine (computer n1). And of course there is a firewall between n1 and the remote machine. Can I use SSH tunneling?? Thanks a lot! Commented Oct 6, 2020 at 8:23

1 Answer 1

2

It is possible, provided that:

  1. The firewall of your local network allows outgoing connections to the PostgreSQL listen port (usually 5432).
  2. The firewall of the other network allows incoming connections to the PostgreSQL listen port (usually 5432).
  3. The firewall of the PostgreSQL server allows connection on its listen port (usually 5432).
  4. The PostgreSQL server is configured to accept network connections.

You can use a network scanner such as Nmap to test things, thing to do is to get a laptop on the customer's network, and scan from there. If you can connect to the PostgreSQL from an address on the same subnet, then you know there is nothing else needed on the PostgreSQL server, and so your attention need to be on the customer's firewall. This is where things can get difficult, and you'll need to work with whoever controls that firewall / router.

Chances are that the customer's network is on an RFC 1918 subnet. If this is the case the firewall / router will need to be configured to port forward like this:


public internet
       |
 ----public address--port nnn--
|                             |
|     firewall                |
|                             |
|-----rfc 1918 address--------|
          |     
          |  
          |  
 ----rfc 1918 address--port 5432--
|                                |
|     PostgreSQL server          |
|                                |
|--------------------------------|
Sign up to request clarification or add additional context in comments.

2 Comments

So all I really need to do, is adding an inbound rule on the 'server' machine (of course for port 5432), and an outcome rule on the client's machine (again for port 5432)? How about SSH tunneling? Do you have any recommendations on trying to use that also? And if so, how can I use it in order to solve my problem? Thanks a lot!!
It all depends on the network environment - I've expanded my answer somewhat. If you can already ssh from your Windows 10 machine,to the client's PostgreSQL server, then it means that the clien't firewall is configured to allow that, and in this case, SSH tunneling is an option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.