Failed to start PostgreSQL 11 database server的解决办法
叉叉敌关注赞赏支持Failed to start PostgreSQL 11 database server的解决办法
[toc]
错误
在使用 PostgreSQL 过程中,我目前遇到了 2 种错误的类型,下面是具体解决办法和具体的错误信息。
连接拒绝Connection refused
在使用 Django 应用中,使用 PostgreSQL 关系数据库,在安装的时候遇到一些问题,具体如下:
Is the server running on host "host_name" (XX.XX.XX.XX)
and accepting TCP/IP connections on port 5432?
上面这个问题是没有启动数据库导致的。
启动失败
下面这个问题启动失败的问题,启动命令是
[root@VM_152_4_centos bootcamp]# service postgresql-11 start
Redirecting to /bin/systemctl start postgresql-11.service
Job for postgresql-11.service failed because the control process exited with error code. See "systemctl status postgresql-11.service" and "journalctl -xe" for details.
提示了运行status 和 journalctl -xe 可以查看到具体细节。
[root@VM_152_4_centos bootcamp]# systemctl status postgresql-11.service
● postgresql-11.service - PostgreSQL 11 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-11.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sun 2019-02-17 22:15:42 CST; 19min ago
Docs: https://www.postgresql.org/docs/11/static/
Process: 6220 ExecStartPre=/usr/pgsql-11/bin/postgresql-11-check-db-dir ${PGDATA} (code=exited, status=1/FAILURE)
Feb 17 22:15:42 VM_152_4_centos systemd[1]: Starting PostgreSQL 11 database server...
Feb 17 22:15:42 VM_152_4_centos systemd[1]: postgresql-11.service: control process exited, code=exited status=1
Feb 17 22:15:42 VM_152_4_centos systemd[1]: Failed to start PostgreSQL 11 database server.
Feb 17 22:15:42 VM_152_4_centos systemd[1]: Unit postgresql-11.service entered failed state.
Feb 17 22:15:42 VM_152_4_centos systemd[1]: postgresql-11.service failed.
然后再执行journalctl -xe命令。
[root@VM_152_4_centos bootcamp]# journalctl -xe
-- Unit postgresql-11.service has begun starting up.
Feb 17 22:35:03 VM_152_4_centos postgresql-11-check-db-dir[7789]: "/var/lib/pgsql/11/data/" is missing or empty.
解决办法
可以看到根本原因就是没有db,所以需要先初始化db。
[root@VM_152_4_centos ~]# /usr/pgsql-11/bin/postgresql-11-setup initdb
Initializing database ... OK
最后启动,然后查看状态
[root@VM_152_4_centos bootcamp]# systemctl start postgresql-11.service
[root@VM_152_4_centos bootcamp]# systemctl status postgresql-11.service
● postgresql-11.service - PostgreSQL 11 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-11.service; disabled; vendor preset: disabled)
Active: active (running) since Sun 2019-02-17 22:37:04 CST; 2s ago
小结
遇到问题不要慌,仔细查看输出的错误信息里面,有没有需要的帮助谢谢,还有一个就是通过网上查找错误信息中的关键字,找到对应的解决方法。
推荐阅读更多精彩内容
- PostgreSQL服务器管理:服务器设置和操作 阅读原文请点击 摘要:本章讨论如何设置和运行数据库服务器,以及它与操作系统的交互。 本文档为PostgreSQL ... 阿里云_云栖社区阅读 2,679评论 1 赞 13
- 极迅云课(服务端教案) 一、Python简介和环境搭建以及pip的安装 4课时实验课主要内容 【Python简介】: Python 是一个... _小老虎_阅读 2,995评论 0 赞 2
- Go database/sql文档 No.1 文档概要 在Golang中使用SQL或类似SQL的数据库的惯用方法是通过 database/sql 包操... 尼古拉斯河马阅读 11,548评论 3 赞 7
- 风俗 农历二十三,火烧豆腐汤! 文刀币阅读 32评论 0 赞 0
- 蒋雯丽出席活动霸气发言,她独有的知性美是别人学不来的! 蒋雯丽饰演过很多经典的角色,现在也已经是老演员了!她在很多剧中的表现演技可以用精湛来形容! 近日蒋雯丽出席“年度品... 彬彬说说阅读 70评论 0 赞 0