postgresql 外网访问设置

自己的一台破电脑被用来做服务器了,上面装了postgresql,需要能在局域网内访问,就查阅了写资料,总结如下。如果要外网访问的话,相似的改动相应ip就可以了。

1. select name, setting from pg_settings where category = ‘File Locations’   找到配置文件地址。

我使用的是9.5版本, 返回结果如下

《postgresql 外网访问设置》 查询返回结果

2. 上述的查询结果中,有hba_file的地址,打开 /etc/postgresql/9.5/main/pg_hba.conf 并做相应修改 

《postgresql 外网访问设置》 hba_file修改前

《postgresql 外网访问设置》 hba_file修改后

3. 在第一个查询的返回结果中,同样有 config_file的地址,打开 /etc/postgresql/9.5/main/postgresql.conf 并做相应修改。在其中添加 `   listen_addresses = ‘*’   `

4.  重启数据库  sudo service postgresql restart

    原文作者:风一样的男人1990
    原文地址: https://www.jianshu.com/p/a46f9aa8dd78
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞