pg数据库开启远程连接_如何运行远程客户端连接postgresql数据库

本文详细介绍了如何开启PostgreSQL数据库的远程连接。首先,你需要在`pg_hba.conf`文件中配置允许远程客户端连接的规则,然后重新加载配置使其生效。接着,确保`postgresql.conf`配置文件中的`listen_addresses`设置为'*',以监听所有端口。通过这些步骤,你可以成功实现远程访问PostgreSQL数据库。
摘要由CSDN通过智能技术生成

如何运行远程客户端连接

postgresql

数据库

前提条件是

2

个:

1

pg_hba.conf

里面配置了运行远程客户机连接

pg_hba.conf

配置后需要重新加载

reload

生效。

2

默认监听只监听本机,需要让监听程序来监听外边连接的端口。

做法:

1

,配置

pg_hba.conf

配置文件在

/opt/postgres/9.0/data

目录,备份后,进行

vi

编辑:

# IPv4 local connections:

host

all

all

127.0.0.1

/

32

password

host

all

all

192.168.1.0/

24

password

host

all

all

192.168.10.0/

24

password

#

加入这行表示运行

192

这个网段的机

器访问所有的数据库。

然后

reload

配置

,指定数据库的数据的目录,其实就是

pg_hba.conf

的目录

[root@fia ~]# /opt/postgres/

9.0/bin/pg_ctl

reload -D /opt/postgres/9.0/data

pg_ctl: cannot be run as root

用户权限不对,

root

也不行

Please log in (using, e.g., "su") as the (unprivileged) user that will

own the server process.

[root@fia ~]# id

uid=0(root) gid=0(root) groups=0(root)

[root@fia ~]# su - postgres

必须用

postgres

用户才能运行

-bash-3.2$ /opt/postgres/

9.0/bin/pg_ctl

reload -D /opt/postgres/9.0/data

server signaled

2

,监听程序

PostgreSQL

默认只监听本地端口,用

netstat -tuln

只会看到“

tcp 127.0.0.1:5432 LISTEN

修改

postgresql.conf

中的

listen_address=*

监听所有端口,

这样远程才能通过

TCP/IP

登录数

据库,

netstat -tuln

会看到“

tcp 0.0.0.0:5432 LISTEN

[root@fia /]# netstat -tuln |grep 5432

tcp

0

0 0.0.0.0:5432

0.0.0.0:*

LISTEN

tcp

0

0 :::5432

:::*

LISTEN

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值