gpt4 book ai didi

postgresql - Postgres systemd 单元文件如何确定要运行的 Postgres 版本?

转载 作者:行者123 更新时间:2023-11-29 12:54:51 30 4
gpt4 key购买 nike

这主要是出于好奇而提出的问题。我正在浏览 Postgres systemd 单元文件,以了解 systemd 可以做什么。 Postgres 有两个 systemd 单元文件。一个用于代替 systemd 目标的:

# systemd service for managing all PostgreSQL clusters on the system. This
# service is actually a systemd target, but we are using a service since
# targets cannot be reloaded.

[Unit]
Description=PostgreSQL RDBMS

[Service]
Type=oneshot
ExecStart=/bin/true
ExecReload=/bin/true
RemainAfterExit=on

[Install]
WantedBy=multi-user.target

第二个单元文件是在 Postgres 版本上参数化的模板。它通过使用 Before=postgresql.service 指定它将在其他单元文件之前运行:

# systemd service template for PostgreSQL clusters. The actual instances will
# be called "postgresql@version-cluster", e.g. "postgresql@9.3-main". The
# variable %i expands to "version-cluster", %I expands to "version/cluster".
# (%I breaks for cluster names containing dashes.)

[Unit]
Description=PostgreSQL Cluster %i
ConditionPathExists=/etc/postgresql/%I/postgresql.conf
PartOf=postgresql.service
ReloadPropagatedFrom=postgresql.service
Before=postgresql.service

[Service]
Type=forking
# @: use "postgresql@%i" as process name
ExecStart=@/usr/bin/pg_ctlcluster postgresql@%i --skip-systemctl-redirect %i start
ExecStop=/usr/bin/pg_ctlcluster --skip-systemctl-redirect -m fast %i stop
ExecReload=/usr/bin/pg_ctlcluster --skip-systemctl-redirect %i reload
PIDFile=/var/run/postgresql/%i.pid
SyslogIdentifier=postgresql@%i
# prevent OOM killer from choosing the postmaster (individual backends will
# reset the score to 0)
OOMScoreAdjust=-900
# restarting automatically will prevent "pg_ctlcluster ... stop" from working,
# so we disable it here. Also, the postmaster will restart by itself on most
# problems anyway, so it is questionable if one wants to enable external
# automatic restarts.
#Restart=on-failure
# (This should make pg_ctlcluster stop work, but doesn't:)
#RestartPreventExitStatus=SIGINT SIGTERM

[Install]
WantedBy=multi-user.target

我不明白的是,当我运行 systemctl start postgresql 时,systemd 如何确定要运行的 Postgres 版本。当我查看 postgresql.service 的依赖项时,我看到有一个特定的模板实例 9.5-main,它是一个依赖项:

> systemctl list-dependencies postgresql

postgresql.service
● ├─postgresql@9.5-main.service
● ├─postgresql@9.5-main.service
● ├─system.slice
● └─sysinit.target
● ├─apparmor.service
● ├─brltty.service
● ├─console-setup.service
● ├─dev-hugepages.mount
● ├─dev-mqueue.mount
● ├─friendly-recovery.service
● ├─keyboard-setup.service
● ├─kmod-static-nodes.service
● ├─lvm2-lvmetad.socket
● ├─lvm2-lvmpolld.socket
● ├─lvm2-monitor.service
● ├─plymouth-read-write.service
● ├─plymouth-start.service
● ├─proc-sys-fs-binfmt_misc.automount
● ├─resolvconf.service
● ├─setvtrgb.service
● ├─sys-fs-fuse-connections.mount
● ├─sys-kernel-config.mount

我找不到任何指定应使用 Postgres 9.5 的文件。没有任何其他 Postgres 单元文件,其他文件也根本没有提到 Postgres。这是在带有 systemd 229 和 Postgres 9.5 的 Ubuntu 16.04 上(通过 sudo apt-get install postgresql 安装)。

最佳答案

发件人:https://www.freedesktop.org/software/systemd/man/systemd.unit.html

"%i"    Instance name   For instantiated units: this is the string between the "@" character and the suffix of the unit name.

文件名为 postgres@9.3-main.service 所以 %i = 9.3-main

更新:

实例文件通常创建为模板文件的符号链接(symbolic link),链接名称包括实例标识符

file /run/systemd/generator/postgresql.service.wants/postgresql@9.4-main.service
/run/systemd/generator/postgresql.service.wants/postgresql@9.4-main.service: symbolic link to /lib/systemd/system/postgresql@.service

关于postgresql - Postgres systemd 单元文件如何确定要运行的 Postgres 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46030842/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com