修改pg_hba.conf文件配置开放postgreSQL连接权限

本文介绍了如何在PostgreSQL12中修改配置以允许远程连接。涉及的文件包括pg_hba.conf和postgresql.conf。在Windows环境下,pg_hba.conf位于dataPostgreSQL10data目录下,而在Linux环境下,通过查询确定其路径为/etc/postgresql/12/main/pg_hba.conf。修改内容包括将127.0.0.1/32md5更改为0.0.0.0/0trust,并将listen_address从'localhost'改为'*'。配置修改后,需要使用pg_reload_conf()重载配置并重启服务。此外,还提供了设置PostgreSQL主用户密码的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

提示:开放访问范围非常危险,一不小心就会被攻击。

默认情况下,刚刚安装完成的 postgresSQL12 无法使用 数据库连接工具连接。需要为其修改配置,开放连接权限。

主要涉及两个配置文件的修改:

1:pg_hba.conf 

其中,它的文件存放路径,随着不同版本,可能不一致。

2:postgresql.conf

Postgre10 Windows环境:

data\PostgreSQL\10\data文件下

host   all    all    0.0.0.0/0    md5

Postgre12   Linux环境:

一次输入如下前三条命令

sudo su - postgres

psql -U postgres

postgres=# select setting from pg_settings where name like '%hba%';
               setting
-------------------------------------
 /etc/postgresql/12/main/pg_hba.conf
(1 row)

postgres=#

修改pg_hba.conf文件中关于ipv4的127.0.0.1/32 md5 改为0.0.0.0/0 trust

修改postgresql.conf文件中关于listen_address中'localhost'为'*'

修改了配置后,需要reload一下方可生效:

postgres=# select pg_reload_conf();

然后重启postgre 

sudo service postgresql start

有些在 

/var/lib/pgsql/data/pg_hba.conf

参见:

Linux安装并启动PostgreSQL_szuwangjl的博客-优快云博客_linux postgresql 启动

https://www.jianshu.com/p/47fbd8caba82

Once PostgreSQL is installed you may want to create a new user or set the password for the the main user. The instructions below will help to set the password for main postgresql user

sudo su - postgres
psql
\password
\q

Then, press “Ctrl+D” to return to main user console and connect to the database to create thingsboard DB:

psql -U postgres -d postgres -h 127.0.0.1 -W

CREATE DATABASE thingsboard;

\q

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值