如何允许远程访问PostgreSQL数据库 [英] How to Allow Remote Access to PostgreSQL database

查看:365
本文介绍了如何允许远程访问PostgreSQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 7中安装了PostgreSQL 9.2,并且在虚拟机中安装了Windows XP,如何连接这两个数据库并允许远程访问从这两个系统中添加/编辑数据库?

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 ?

推荐答案

要远程访问PostgreSQL数据库,必须设置两个主要的PostgreSQL配置文件:

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

postgresql.conf
pg_hba.conf

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)

首先将PostgreSQL服务配置为侦听Windows 7计算机中所有网络接口上的端口5432: 打开文件postgresql.conf(通常位于C:\ Program Files \ PostgreSQL \ 9.2 \ data中)并设置参数

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 = '*'

检查WindowsXP虚拟机的网络地址,并在pg_hba.conf文件(位于postgresql.conf的同一目录中)中设置参数,以便postgresql可以接受来自虚拟机主机的连接. 例如,如果使用Windows XP的计算机的IP地址为192.168.56.2,则添加pg_hba.conf文件:

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

这样,PostgreSQL将接受来自网络192.168.1.XXX上所有主机的连接.

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

在Windows 7中重新启动PostgreSQL服务(服务"-> PosgreSQL 9.2:右键单击并重新启动服务).在Windows XP计算机上安装pgAdmin,然后尝试连接到PostgreSQL.

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.

这篇关于如何允许远程访问PostgreSQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆