首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么PostgreSQL的服务在系统服务和pg_ctl之间是不同的?

为什么PostgreSQL的服务在系统服务和pg_ctl之间是不同的?
EN

Database Administration用户
提问于 2020-03-02 01:50:44
回答 1查看 2K关注 0票数 3

普通用户安装了PostgreSQL 10。

启用并启动其服务:

代码语言:javascript
复制
sudo systemctl start postgresql-10
sudo systemctl enable postgresql-10

然后使用postgres用户登录:

代码语言:javascript
复制
sudo su - postgres

将此设置添加到.bash_profile文件中:

代码语言:javascript
复制
export PATH=$PATH:/usr/pgsql-10/bin/

通过PostgreSQL重新启动pg_ctl

代码语言:javascript
复制
-bash-4.2$ pg_ctl restart

然后退出到普通用户并再次检查postgresql的状态,它失败了。即使用这种方式重新启动也不能成功:

代码语言:javascript
复制
sudo systemctl restart postgresql-10
sudo systemctl stop postgresql-10

它总是failed

但是如果我使用postgres用户来测试重新启动、停止、启动,它们都可以成功。

这两种方式并不能控制相同的过程?

添加PostgreSQL10服务内容

代码语言:javascript
复制
$ sudo systemctl cat postgresql-10.service

# /usr/lib/systemd/system/postgresql-10.service
# It's not recommended to modify this file in-place, because it will be
# overwritten during package upgrades.  If you want to customize, the
# best way is to create a file "/etc/systemd/system/postgresql-10.service",
# containing
#       .include /usr/lib/systemd/system/postgresql-10.service
#       ...make your changes here...
# For more info about custom unit files, see
# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F

# Note: changing PGDATA will typically require adjusting SELinux
# configuration as well.

# Note: do not use a PGDATA pathname containing spaces, or you will
# break postgresql-setup.
[Unit]
Description=PostgreSQL 10 database server
Documentation=https://www.postgresql.org/docs/10/static/
After=syslog.target
After=network.target

[Service]
Type=notify

User=postgres
Group=postgres

# Note: avoid inserting whitespace in these Environment= lines, or you may
# break postgresql-setup.

# Location of database directory
Environment=PGDATA=/var/lib/pgsql/10/data/

# Where to send early-startup messages from the server (before the logging
# options of postgresql.conf take effect)
# This is normally controlled by the global default set by systemd
# StandardOutput=syslog

# Disable OOM kill on the postmaster
OOMScoreAdjust=-1000
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0

ExecStartPre=/usr/pgsql-10/bin/postgresql-10-check-db-dir ${PGDATA}
ExecStart=/usr/pgsql-10/bin/postmaster -D ${PGDATA}
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT


# Do not set any timeout value, so that systemd will not kill postmaster
# during crash recovery.
TimeoutSec=0

[Install]
WantedBy=multi-user.target
EN

回答 1

Database Administration用户

回答已采纳

发布于 2020-03-02 08:01:50

如果您使用pg_ctl手动启动服务器,systemd就不知道了。

它将很高兴地尝试启动服务器,这将失败(因为服务器已经在运行),并且它无法停止服务器,因为它不知道它正在运行。

因此,在启动和停止服务时始终使用systemctl。重新加载pg_ctl reload是很好的。

票数 6
EN
页面原文内容由Database Administration提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://dba.stackexchange.com/questions/260956

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档