psql: error: could not connect to server: 拒绝连接解决

本文介绍了在尝试连接PostgreSQL数据库时遇到的“拒绝连接”错误,并详细记录了排查过程,包括关闭防火墙、检查服务状态、启动服务及加载环境变量等步骤。

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

在部署启动postgresql数据库时遇到这样的问题
通过以下方式得以解决

[pg13@machine ~]$ psql -d postgres
psql: error: could not connect to server: 拒绝连接
        Is the server running locally and accepting
        connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

1.检查并关闭防火墙状态

[root@machine postgresql-13.5]# systemctl stop firewalld.service
[root@machine postgresql-13.5]# systemctl disable firewalld.service

2.检查服务是否启动,我这边是发现并没有启动

[pg13@machine ~]$ pg_ctl status
pg_ctl: no server running

启动

[pg13@machine ~]$ pg_ctl start
***中间省略***
 done
server started

3.加载环境变量


[pg13@machine ~]$ source /home/pg13/.bash_profile
[pg13@machine ~]$ source /home/pg13/.bashrc

4.重新连接,成功

[pg13@machine ~]$ psql -d postgres
psql (13.5)
Type "help" for help.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值