postgresql.serviceは起動するpostgresqlインスタンスをどのように知っていますか?

postgresql.serviceは起動するpostgresqlインスタンスをどのように知っていますか?

Ubuntu 16.04にpostgres 9.5をインストールしましたpostgresql.service[email protected]

有効になっているすべてのpostgresインスタンスが作成され、以下を使用して特定のインスタンスをpostgresql.service呼び出すことができますが、これはテンプレートファイルであり、インスタンス文字列(テンプレート内の%iまたは%Iで表される)が渡される場所は表示されません。 [email protected][email protected]postgresql.service

どのインスタンスが有効になっているかを確認しpostgresql.service、それをsystemdテンプレートファイルに渡しますか?

ベストアンサー1

この質問に答えるには、まず両方の関連ファイルの内容を調べてください。ファイルがどこにあるかわからない場合は、パッケージの内容からファイルを検索できますsystemd

 dpkg -L postgresql-common| grep systemd

ファイルを見るとpostgresql.serviceあまり多くのことをしていないことがわかります。

# 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

コメントを通して、私たちはこのファイルがシステム「ターゲット」として使用されることを知っています。テンプレートファイルに移動します。

# systemd service template for PostgreSQL clusters. The actual instances will
# be called "postgresql@version-cluster", e.g. "[email protected]". 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

興味深いガイドラインは次のとおりです。

PartOf=postgresql.service
ReloadPropagatedFrom=postgresql.service

systemdディレクティブの文書がどこにあるかわからない場合は、次の点を確認してくださいman systemd.directives。そこで我々はこれら2つのコマンドをで見つけることができますman systemd.unit

サービスを有効にすると、最大のリードが表示されます。

sudo systemctl enable [email protected]
Created symlink /etc/systemd/system/multi-user.target.wants/[email protected] → /lib/systemd/system/[email protected].

一緒に入れてください:

  • systemdサーバーの起動時にシンボリックリンクがPostgreSQL 9.6を起動する方法を知る方法 。
  • PartOf=そしてディレクティブはReloadPropagatedFrom=サービスによって保証され、stop最終的にインストールされたstartすべての関連するPostgreSQLインスタンスに適用されます。restartreloadpostgresql

おすすめ記事