Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Allow Remote Access to PostgreSQL database

I have PostgreSQL 9.2 Installed in Windows 7 and I have windows XP installed in Virtual Machine, how do I connect these two databases and allow remote access to add/edit the database from both Systems ?

like image 283
Ali4356 Avatar asked Sep 02 '13 20:09

Ali4356


People also ask

Can access connect to Postgres database?

In Microsoft Access, you can connect to your PostgreSQL data either by importing it or creating a table that links to the data. Devart ODBC drivers support all modern versions of Access.


2 Answers

In order to remotely access a PostgreSQL database, you must set the two main PostgreSQL configuration files:

postgresql.conf
pg_hba.conf

Here is a brief description about how you can set them (note that the following description is purely indicative: To configure a machine safely, you must be familiar with all the parameters and their meanings)

First of all configure PostgreSQL service to listen on port 5432 on all network interfaces in Windows 7 machine:
open the file postgresql.conf (usually located in C:\Program Files\PostgreSQL\9.2\data) and sets the parameter

listen_addresses = '*'

Check the network address of WindowsXP virtual machine, and sets parameters in pg_hba.conf file (located in the same directory of postgresql.conf) so that postgresql can accept connections from virtual machine hosts.
For example, if the machine with Windows XP have 192.168.56.2 IP address, add in the pg_hba.conf file:

host all all 192.168.56.1/24 md5

this way, PostgreSQL will accept connections from all hosts on the network 192.168.1.XXX.

Restart the PostgreSQL service in Windows 7 (Services-> PosgreSQL 9.2: right click and restart sevice). Install pgAdmin on windows XP machine and try to connect to PostgreSQL.

like image 171
AndreaBoc Avatar answered Nov 03 '22 03:11

AndreaBoc


After set listen_addresses = '*' in postgresql.conf

Edit the pg_hba.conf file and add the following entry at the very end of file:

host    all             all              0.0.0.0/0                       md5
host    all             all              ::/0                            md5

For finding the config files this link might help you.

like image 76
S.Hossein Asadollahi Avatar answered Nov 03 '22 03:11

S.Hossein Asadollahi