Rel*_*yne 3 postgresql systemd debian-stretch
我在 Debian 9 上通过 apt-get 安装了 PostgresQL 11。安装后,我删除了默认数据库集群,并删除了自动启动该集群的所有服务。我现在已经运行 initdb 在自定义位置初始化一个新集群,并编写并启用了 systemd .service 文件以自动运行该文件。
我遇到了一个问题,机器启动时服务成功启动,但随后数据库立即关闭,服务立即停止。当我使用 systemctl 手动启动服务时,也会发生同样的情况。
.服务文件:
[Unit]
Description=PostgreSQL database server
Documentation=man:postgres(1)
[Service]
Environment=PGDATA=/home/(user)/.db
Environment=PGLOG=/home/(user)/postgres.log
Environment=PGSTARTTIMEOUT=270
Type=notify
User=(user)
Group=(group)
ExecStart=/usr/lib/postgresql/11/bin/pg_ctl start -D ${PGDATA} -l ${PGLOG} -t ${PGSTARTTIMEOUT}
ExecStop=/usr/lib/postgresql/11/bin/pg_ctl stop -D ${PGDATA} -m fast
ExecReload=/usr/lib/postgresql/11/bin/pg_ctl reload -D ${PGDATA}
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=300
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
手动启动集群的命令:
su (user) -c '/usr/lib/postgresql/11/bin/pg_ctl start -D /home/(user)/.db -l /home/(user)/postgres.log -t 270'
Run Code Online (Sandbox Code Playgroud)
通过 systemctl 启动时的 PostgreSQL 日志:
2019-01-13 11:36:16.506 EST [1469] 日志:监听 IPv4 地址“127.0.0.1”,端口 5432
2019-01-13 11:36:16.508 EST [1469] 日志:监听 Unix 套接字“/var/run/postgresql/.s.PGSQL.5432”
2019-01-13 11:36:16.530 EST [1470] LOG: 数据库系统于 2019 01-13 11:17:07 EST 关闭
2019-01-13 11:36:16.537 EST [1469] 日志:数据库系统已准备好接受连接
2019-01-13 11:36:16.595 EST [1469] 日志:收到快速关闭请求
2019-01-13 11:36:16.600 EST [1469] 日志:中止任何活动事务
2019-01-13 11:36:16.605 EST [1469] 日志:后台工作人员“逻辑复制启动器”(PID 1476)退出,退出代码为 1
2019-01-13 11:36:16.605 EST [1471] 日志:关闭
2019-01-13 11:36:16.625 EST [1469] LOG:数据库系统已关闭
日记ctl | grep postgres:
Jan 13 11:42:01 vps76296 systemd[1]:启动 PostgreSQL 数据库服务器...
1 月 13 日 11:42:01 vps76296 systemd[1]:启动 PostgreSQL RDBMS...
Jan 13 11:42:02 vps76296 systemd[1]:启动 PostgreSQL RDBMS。
Jan 13 11:42:02 vps76296 systemd[1]: postgres-start.service: 从 PID 749 收到通知消息,但仅允许主 PID 729 接收
Jan 13 11:42:02 vps76296 pg_ctl[729]:等待服务器启动....完成
1 月 13 日 11:42:02 vps76296 pg_ctl[729]:服务器已启动
Jan 13 11:42:02 vps76296 pg_ctl[761]:等待服务器关闭....完成
1 月 13 日 11:42:02 vps76296 pg_ctl[761]:服务器已停止
Jan 13 11:42:02 vps76296 systemd[1]:启动 PostgreSQL 数据库服务器。
strace 日志也可根据要求提供。它真的很长,所以除非需要,否则我选择不包含它。
为什么我的服务启动后立即停止?
这Type=notify让我很怀疑。根据systemd 文档:“\xe2\x80\xa6 类似于 exec;但是,预计该服务通过sd_notify(3)\xe2\x80\xa6 发送通知消息”
它pg_ctl不是守护进程本身,而是它的控制实用程序,而不是立即退出。
我建议使用不同的Type\xe2\x80\x94 oneshot。
另请注意systemctl status \xe2\x80\xa6serviceName\xe2\x80\xa6输出 \xe2\x80\x94 它可能有解释。
| 归档时间: |
|
| 查看次数: |
3017 次 |
| 最近记录: |