postgres启动服务状态卡前台窗口

问题描述

执行systemct start postgresql-16.service,前台窗口一直不退出。检查postgres服务状态,运行正常。

问题分析

症状就是 systemctl start 一直卡在前台窗口。
因为 systemd 没收到 PostgreSQL 服务启动完成的状态通知,才会一直卡在前台窗口。这种问题主要出现在自编译安装或第三方安装的postgres数据库中,如编译过程中没有添加参数 --with-systemd

cat /usr/lib/systemd/system/postgresql-16.service
[Unit]
Description=PostgreSQL 16 database server
Documentation=https://www.postgresql.org/docs/16/static/
After=network.target
[Service]
Type=notify #问题点,编译未添加 --with-systemd
User=postgres
Group=postgres
Environment=PGDATA=/xxx/pgdata/
ExecStart=/xxx/bin/postgres -D ${PGDATA}
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=0
OOMScoreAdjust=-1000
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0
[Install]
WantedBy=multi-user.target

问题解决

将notify更改为simple, systemd 只要看到主进程postgres启动就当服务已启动,不等待额外通知。
[Service]
Type=simple

发表评论

邮箱地址不会被公开。 必填项已用*标注