追加読書

追加読書

apt-getを介してUbuntu 18.04にPostgreSQL-11をインストールし、以下に基づいています。ここ、ポート5432、5433に2つのpostgreSQLインスタンスをインストールしました。

私の質問は、両方のインスタンスに対して別々の起動停止スクリプトを持つことができるかどうかです。私の他のサーバーはCentos 7でpostgresql 9.6を実行しているので、いくつかの起動スクリプトがあります。

postgresql-9.6-instanceA.service postgresql-9.6-instanceB.service postgresql-9.6-instanceC.service postgresql-9.6-instanceD.service postgresql-9.6-instanceE.service

これらのファイルは環境内でのみ異なります(注環境部分):

[root@root]# cat /etc/systemd/system/postgresql-9.6-instanceA.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-9.6.service",
# containing
#       .include /lib/systemd/system/postgresql-9.6.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 9.6 database server
Documentation=https://www.postgresql.org/docs/9.6/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/instanceA/9.6/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-9.6/bin/postgresql96-check-db-dir ${PGDATA}
ExecStart=/usr/pgsql-9.6/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

私が読んだ内容によるとここ、ソースコードインストールの場合、上記のスクリプトを生成できるため、systemdユニットファイルを追加する必要があります。

これは私のUbuntuサーバーのsystemdスクリプトの内容です。postgresql.service私のUbuntu 18.04のファイルは次のとおりです。最初のファイルは/var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/postgresql.service空です。

root@hostname:~# ls -lah /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/postgresql.service
-rw-r--r-- 1 root root 0 Feb 25 03:50 /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/postgresql.service

2番目と3番目のファイルの内容は同じです。

/etc/systemd/system/multi-user.target.wants/postgresql.service /lib/systemd/system/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

それでは、私のUbuntuサーバーでもこれが起こりますか?これにより、編集する場所やファイルがわからないため、両方のpostgresインスタンスに対して起動 - 停止 - 再ロード - 再起動スクリプトを持つことができます。

ベストアンサー1

Debian パッケージは 2014 年からこの作業を行ってきました。/etc/postgresql/systemdユニットジェネレータは、設定ファイルに基づいてユニットを自動的に作成して有効にします。postgresql@instance.service

これについては、システムのReadmeファイルに記載されています/usr/share/doc/postgresql-common/。このディレクトリーとこのディレクトリー内の他のすべての文書をお読みください。

追加読書

おすすめ記事