【postgresql 】postgresql 安装后配置远程连接

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/you_xian/article/details/74343916

linux中安装 postgresql 安装官方教程一步一步执行命令就可以了。https://www.postgresql.org/download/linux/redhat/

当安装完成 切换到 postgres 用户(安装过程自动创建),使用psql便可登陆终端。

如果需要使用外部机器(非本机) 连接postgresql , 则需要配置 pg_hba,postgresql.conf。

第一步,找到这两个文件,可以通过 ps -ef |grep postgre 来查找 postgre的data目录。

第二步,编辑 pg_hba ,根据需要进行ip授权。

第三步,编辑postgresql.conf 将listen_address 修改为 listen_address=‘*’ (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”。)

第四步,使用pg_ctl reload重新读取pg_hba.conf文件,如果pg_ctl找不到数据库,则用-D /.../pgsql/data/ 指定数据库目录,或export PGDATA=/.../pgsql/data/ 导入环境变量。如果pg_ctl 找不到,则用ps -ef | grep postgre 去查找,

最后 ,注意系统防火墙。

centos的防火墙查看命令: 

service iptables status

关闭命令:

service iptables stop 

永久关闭防火墙:

chkconfig iptables off 

猜你喜欢

转载自blog.csdn.net/you_xian/article/details/74343916