普通用户安装了PostgreSQL 10。
启用并启动其服务:
sudo systemctl start postgresql-10
sudo systemctl enable postgresql-10然后使用postgres用户登录:
sudo su - postgres将此设置添加到.bash_profile文件中:
export PATH=$PATH:/usr/pgsql-10/bin/通过PostgreSQL重新启动pg_ctl:
-bash-4.2$ pg_ctl restart然后退出到普通用户并再次检查postgresql的状态,它失败了。即使用这种方式重新启动也不能成功:
sudo systemctl restart postgresql-10
sudo systemctl stop postgresql-10它总是failed。
但是如果我使用postgres用户来测试重新启动、停止、启动,它们都可以成功。
这两种方式并不能控制相同的过程?
添加PostgreSQL10服务内容
$ 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发布于 2020-03-02 08:01:50
如果您使用pg_ctl手动启动服务器,systemd就不知道了。
它将很高兴地尝试启动服务器,这将失败(因为服务器已经在运行),并且它无法停止服务器,因为它不知道它正在运行。
因此,在启动和停止服务时始终使用systemctl。重新加载pg_ctl reload是很好的。
https://dba.stackexchange.com/questions/260956
复制相似问题