PostgreSql 改为全网段可以访问数据库

PostgreSql 改为全网段可以访问数据库

 

在安装目录下打开文件,我安装在D盘中的文件路径为:
"D:\Program Files\PostgreSQL\18\data\pg_hba.conf"

 

把文件使用记事本打开,拉到最下面,可以看到如下

# "local" is for Unix domain socket connections only
local   all             all                                     scram-sha-256
# IPv4 local connections:
host    all             all             127.0.0.1/32            scram-sha-256
# IPv6 local connections:
host    all             all             ::1/128                 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     scram-sha-256
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256

  第4行中的 127.0.0.1/32  就是ipv4可以访问的地址,我们把第4行改为如下

# "local" is for Unix domain socket connections only
local   all             all                                     scram-sha-256
# IPv4 local connections:
host    all             all             0.0.0.0/0            scram-sha-256
# IPv6 local connections:
host    all             all             ::1/128                 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     scram-sha-256
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256

  

然后保存文件,重启数据库服务或者重启电脑即可

posted @ 2026-07-22 15:33  爱恋的红尘  阅读(3)  评论(0)    收藏  举报