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

查看:33
本文介绍了如何允许远程访问 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 FilesPostgreSQL9.2data)并设置参数

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 FilesPostgreSQL9.2data) and sets the parameter

listen_addresses = '*'

检查WindowsXP虚拟机的网络地址,并在pg_hba.conf文件(与postgresql.conf同目录)中设置参数,使postgresql可以接受来自虚拟机主机的连接.
例如,如果Windows XP的机器有192.168.56.2的IP地址,则在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天全站免登陆