由普通用户安装 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
用户来测试重启,停止,启动,它们都可以成功。
这两种方式不是控制同一个过程吗?
添加postgresql-10服务内容
$ 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
如果您使用 手动启动服务器
pg_ctl
,systemd
则不知道。它会愉快地尝试启动服务器,但会失败(因为服务器已经在运行),并且它无法停止服务器,因为它不知道它正在运行。
systemctl
所以在启动和停止服务时总是使用。重新加载pg_ctl reload
是好的。