この設定例では、3台の<productname>Pgpool-II</productname>を使って<productname>PostgreSQL</productname>(プライマリ1台、スタンバイ2台)を管理し、単一障害点やスプリットブレインの起きない堅牢なクラスタを運用することが可能です。
</para>
<para>
- この設定例では<productname>PostgreSQL</productname> 16を使っていますが、
+ この設定例では<emphasis><productname>PostgreSQL</productname> 17</emphasis>を使っていますが、
各種スクリプトは<productname>PostgreSQL</productname> 10以降での動作確認を行っています。
</para>
<sect2 id="example-cluster-requirement">
<title>全体構成</title>
<para>
今回は、Linuxサーバを3台用意し、それぞれのホスト名は<literal>server1</literal>、<literal>server2</literal>、<literal>server3</literal>とします。
- 使用するOSはすべてRocky Linux 8とします。
+ 使用するOSはすべて<emphasis>Rocky Linux 9</emphasis>とします。
それぞれのサーバに<productname>PostgreSQL</productname>と<productname>Pgpool-II</productname>をインストールします。
3台の<productname>PostgreSQL</productname>がストリーミングレプリケーション構成になります。全体構成図は以下の通りです。
</para>
<tbody>
<row>
<entry>PostgreSQLバージョン</entry>
- <entry>16.0</entry>
+ <entry>17.0</entry>
<entry>-</entry>
</row>
<row>
</row>
<row>
<entry>$PGDATA</entry>
- <entry>/var/lib/pgsql/16/data</entry>
+ <entry>/var/lib/pgsql/17/data</entry>
<entry>-</entry>
</row>
<row>
<entry>アーカイブモード</entry>
- <entry>有効</entry>
- <entry>/var/lib/pgsql/archivedir</entry>
+ <entry>無効</entry>
+ <entry>-</entry>
</row>
<row>
<entry>レプリケーションスロット</entry>
<tbody>
<row>
<entry>Pgpool-IIバージョン</entry>
- <entry>4.5.0</entry>
+ <entry>4.6.0</entry>
<entry>-</entry>
</row>
<row>
<tbody>
<row>
<entry morerows='1'>自動フェイルオーバ</entry>
- <entry><ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/failover.sh.sample;hb=refs/heads/V4_5_STABLE">/etc/pgpool-II/sample_scripts/failover.sh.sample</ulink></entry>
+ <entry><ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/failover.sh.sample;hb=refs/heads/V4_6_STABLE">/etc/pgpool-II/sample_scripts/failover.sh.sample</ulink></entry>
<entry>フェイルオーバを実行するスクリプト。<xref linkend="GUC-FAILOVER-COMMAND">で使用します。</entry>
</row>
<row>
- <entry><ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/follow_primary.sh.sample;hb=refs/heads/V4_5_STABLE">/etc/pgpool-II/sample_scripts/follow_primary.sh.sample</ulink></entry>
+ <entry><ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/follow_primary.sh.sample;hb=refs/heads/V4_6_STABLE">/etc/pgpool-II/sample_scripts/follow_primary.sh.sample</ulink></entry>
<entry>上記フェイルオーバスクリプトが実行された後に、新しいプライマリサーバとスタンバイサーバを同期させるスクリプト。<xref linkend="GUC-FOLLOW-PRIMARY-COMMAND">で使用します。 PostgreSQLサーバが2台の場合はこのスクリプトの設定は不要です。</entry>
</row>
<row>
<entry morerows='1'>オンラインリカバリ</entry>
- <entry><ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/recovery_1st_stage.sample;hb=refs/heads/V4_5_STABLE">/etc/pgpool-II/sample_scripts/recovery_1st_stage.sample</ulink></entry>
+ <entry><ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/recovery_1st_stage.sample;hb=refs/heads/V4_6_STABLE">/etc/pgpool-II/sample_scripts/recovery_1st_stage.sample</ulink></entry>
<entry>スタンバイサーバをリカバリするスクリプト。<xref linkend="GUC-RECOVERY-1ST-STAGE-COMMAND">で使用します。</entry>
</row>
<row>
- <entry><ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/pgpool_remote_start.sample;hb=refs/heads/V4_5_STABLE">/etc/pgpool-II/sample_scripts/pgpool_remote_start.sample</ulink></entry>
+ <entry><ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/pgpool_remote_start.sample;hb=refs/heads/V4_6_STABLE">/etc/pgpool-II/sample_scripts/pgpool_remote_start.sample</ulink></entry>
<entry>上記<xref linkend="GUC-RECOVERY-1ST-STAGE-COMMAND">が実行された後に、スタンバイノードを起動させるスクリプト。</entry>
</row>
<row>
<entry morerows='1'>Watchdog</entry>
- <entry><ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/escalation.sh.sample;hb=refs/heads/V4_5_STABLE">/etc/pgpool-II/sample_scripts/escalation.sh.sample</ulink></entry>
+ <entry><ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/escalation.sh.sample;hb=refs/heads/V4_6_STABLE">/etc/pgpool-II/sample_scripts/escalation.sh.sample</ulink></entry>
<entry>
任意の設定。Pgpool-IIのリーダー/スタンバイ切り替え時に、旧Watchdogリーダープロセスの異常終了によって旧Watchdogリーダーで仮想IPが起動したまま、新しいリーダーノードで仮想IPが起動されることを防ぐために、新しいリーダー以外で起動している仮想IPを停止するスクリプト。<xref linkend="guc-wd-escalation-command">で使用します。
</entry>
<productname>PostgreSQL</productname>のインストールは<productname>PostgreSQL</productname>コミュニティのリポジトリを使います。
</para>
<programlisting>
-[全サーバ]# dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
+[全サーバ]# dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
[全サーバ]# dnf -qy module disable postgresql
-[全サーバ]# dnf install -y postgresql16-server
+[全サーバ]# dnf install -y postgresql17-server
</programlisting>
<para>
exclude=pgpool*
+[pgdg17]
+...
+exclude=pgpool*
+
[pgdg16]
...
exclude=pgpool*
[pgdg12]
...
-exclude=pgpool*
-
-[pgdg11]
-...
exclude=pgpool*
</programlisting>
<para>
<productname>Pgpool-II</productname>をインストールします。
+ <productname>Pgpool-II</productname>のインストールに必要なlibmemcachedライブラリをインストールするために、<literal>crb</literal>リポジトリを有効にする必要があります。
+ <literal>Rocky Linux 8</literal>を使用する場合、<literal>crb</literal>リポジトリではなく、<literal>powertools</literal>リポジトリを使用してください。
+
</para>
<programlisting>
-[全サーバ]# dnf install -y https://www.pgpool.net/yum/rpms/4.5/redhat/rhel-8-x86_64/pgpool-II-release-4.5-1.noarch.rpm
-[全サーバ]# dnf install -y pgpool-II-pg16-*
+[全サーバ]# dnf install -y https://www.pgpool.net/yum/rpms/4.6/redhat/rhel-9-x86_64/pgpool-II-release-4.6-1.noarch.rpm
+[全サーバ]# dnf install -y --enablerepo=crb pgpool-II-pg17-*
</programlisting>
</sect2>
Pgpool-IIの設定の前に、以下の設定を行ってください。
</para>
- <sect3 id="example-cluster-before-starting-primary">
- <title>プライマリのセットアップ</title>
+ <sect3 id="example-cluster-before-starting-ssh">
+ <title>SSH公開鍵認証の設定</title>
+ <para>
+ 自動フェイルオーバ、オンラインリカバリ機能を利用するには、すべての<productname>Pgpool-II</productname>ノード間で<literal>postgres</literal>ユーザ(Pgpool-IIのデフォルトの起動ユーザ。Pgpool-II 4.0以前、デフォルトの起動ユーザは<literal>root</literal>)として双方向にSSH公開鍵認証(パスワードなし)で接続できるように設定する必要があります。
+ </para>
<para>
- <productname>PostgreSQL</productname>プライマリサーバでストリーミングレプリケーションの設定を行います。
- この設定の例ではアーカイブリカバリを行うように設定します。
</para>
<para>
- まず、すべてのサーバにて<acronym>WAL</acronym>を格納するディレクトリ<filename>/var/lib/pgsql/archivedir</filename>を事前に作成します。この設定例では、プライマリサーバのみで<acronym>WAL</acronym>アーカイブをローカルで実施します。
+ まず、全サーバで以下のコマンドを実行し、SSH鍵ファイルを作成します。
+ この設定例では生成される鍵ファイル名は<literal>id_rsa_pgpool</literal>とします。
</para>
<programlisting>
[全サーバ]# su - postgres
-[全サーバ]$ mkdir /var/lib/pgsql/archivedir
+[全サーバ]$ mkdir ~/.ssh && chmod 700 ~/.ssh
+[全サーバ]$ ssh-keygen -t rsa -f ~/.ssh/id_rsa_pgpool
</programlisting>
+ <para>
+ 次に、公開鍵<literal>id_rsa_pgpool.pub</literal>を各サーバの<filename>/var/lib/pgsql/.ssh/authorized_keys</filename>ファイルに追加します。
+ </para>
+ <para>
+ 設定後、<literal>postgres</literal>ユーザで<command>ssh postgres@serverX -i ~/.ssh/id_rsa_pgpool</command>コマンドを実行し、パスワードなしでログインできることを確認してください。
+ </para>
+ <note>
+ <para>
+ 公開鍵認証によるログインに失敗した場合には、以下を確認してください。
+ <itemizedlist>
+ <listitem>
+ <para>
+ <filename>/etc/ssh/sshd_config</filename>で公開鍵認証が許可されていることを確認します。
+ </para>
+ </listitem>
+ </itemizedlist>
+ <programlisting>
+PubkeyAuthentication yes
+ </programlisting>
+ <itemizedlist>
+ <listitem>
+ <para>
+ SELinuxを有効化している場合は、SSH公開鍵認証(パスワードなし)が失敗する可能性があるので、すべてのサーバで以下のコマンドを実行する必要があります。
+ </para>
+ </listitem>
+ </itemizedlist>
+ <programlisting>
+[全サーバ]# su - postgres
+[全サーバ]$ restorecon -Rv ~/.ssh
+ </programlisting>
+ </para>
+ </note>
+ </sect3>
+
+ <sect3 id="example-cluster-before-starting-firewall">
+ <title>firewallの設定</title>
+ <para>
+ <productname>Pgpool-II</productname>や<productname>PostgreSQL</productname>に接続する際には、ファイアーウォールによって目的のポートが開けられていなければなりません。
+ <systemitem>Rocky Linux 9/RHEL 9</systemitem>の場合、以下のように設定します。
+ </para>
+ <programlisting>
+[全サーバ]# firewall-cmd --permanent --zone=public --add-service=postgresql
+[全サーバ]# firewall-cmd --permanent --zone=public --add-port=9999/tcp --add-port=9898/tcp --add-port=9000/tcp --add-port=9694/udp
+[全サーバ]# firewall-cmd --reload
+ </programlisting>
+ </sect3>
+
+ <sect3 id="example-cluster-before-starting-primary">
+ <title>プライマリのセットアップ</title>
<para>
- <literal>server1</literal>で<productname>PostgreSQL</productname>プライマリサーバの初期化を行います。
+ <literal>server1</literal>で<productname>PostgreSQL</productname>プライマリサーバのセットアップを行います。
+ </para>
+ <para>
+ まず、データベースクラスタの初期化を行います。
+ <productname>PostgreSQL</productname> 17ではデータベースクラスタのデフォルトの作成先は<filename>/var/lib/pgsql/17/data</filename>で、<literal>postgres</literal>ユーザの設定ファイル<filename>~/.bash_profile</filename>で環境変数<varname>PGDATA</varname>に指定されています。
+ 必要に応じて変更してください。
+ </para>
+ <para>
+ <command>initdb</command>コマンドを実行して、データベースクラスタの初期化を行います。
+ 必要に応じて、<literal>--encoding</literal>や<literal>--locale</literal><ulink url="https://www.postgresql.org/docs/17/app-initdb.html">オプション</ulink>を指定して、データベースのエンコーディングやロケールを設定してください。
</para>
<programlisting>
-[server1]# su - postgres
-[server1]$ /usr/pgsql-16/bin/initdb -D $PGDATA
+[root@server1 ~]# su - postgres
+[postgres@server1 ~]$ /usr/pgsql-17/bin/initdb
</programlisting>
<para>
次に<literal>server1</literal>で設定ファイル<filename>$PGDATA/postgresql.conf</filename>を以下のように編集します。
- <application>pg_rewind</application>を使うために<varname>wal_log_hints</varname>を有効にしておきます。
- プライマリが後でスタンバイになる可能性があるので、<literal>hot_standby = on</literal>にしておきます。
+ <application>pg_rewind</application>を使うために<varname>wal_log_hints</varname>を有効にします。
</para>
<programlisting>
+[postgres@server1 ~]$ vi $PGDATA/postgresql.conf
listen_addresses = '*'
-archive_mode = on
-archive_command = 'cp "%p" "/var/lib/pgsql/archivedir/%f"'
-max_wal_senders = 10
-max_replication_slots = 10
-wal_level = replica
-hot_standby = on
wal_log_hints = on
</programlisting>
<para>
- <literal>server1</literal>でPostgreSQLプライマリを起動します。
+ 最後に、<literal>server1</literal>で<productname>PostgreSQL</productname>を起動します。
</para>
<programlisting>
-[server1]# su - postgres
-[server1]$ /usr/pgsql-16/bin/pg_ctl start -D $PGDATA
+[postgres@server1 ~]$ /usr/pgsql-17/bin/pg_ctl start
</programlisting>
</sect3>
</para>
<table id="example-cluster-user">
- <title>ユーザ</title>
+ <title>PostgreSQLユーザ</title>
<tgroup cols="3">
<thead>
<row>
</table>
<programlisting>
-[server1]# psql -U postgres -p 5432
+[postgres@server1 ~]$ psql
postgres=# SET password_encryption = 'scram-sha-256';
postgres=# CREATE ROLE pgpool WITH LOGIN;
postgres=# CREATE ROLE repl WITH REPLICATION LOGIN;
以下のコマンドで<literal>pgpool</literal>ユーザをそのグループに所属させます。
</para>
<programlisting>
-GRANT pg_monitor TO pgpool;
+postgres=# GRANT pg_monitor TO pgpool;
+postgres=# \q
</programlisting>
<note>
</note>
<para>
- <productname>Pgpool-II</productname>サーバと<productname>PostgreSQL</productname>バックエンドサーバが同じサブネットワークにあることを想定し、各ユーザが<acronym>scram-sha-256</acronym>認証方式で接続するように、<filename>pg_hba.conf</filename>を編集しておきます。
+ この設定例では、<productname>Pgpool-II</productname>サーバと<productname>PostgreSQL</productname>バックエンドサーバが同じサブネットワークにあることを想定し、各ユーザが<acronym>scram-sha-256</acronym>認証方式で接続するように、<filename>$PGDATA/pg_hba.conf</filename>を編集しておきます。
</para>
<programlisting>
+[postgres@server1 ~]$ vi $PGDATA/pg_hba.conf
+(以下を追加)
host all pgpool samenet scram-sha-256
host all postgres samenet scram-sha-256
-host replication all samenet scram-sha-256
- </programlisting>
- </sect3>
-
- <sect3 id="example-cluster-before-starting-ssh">
- <title>SSH公開鍵認証の設定</title>
- <para>
- 自動フェイルオーバ、オンラインリカバリ機能を利用するには、すべての<productname>Pgpool-II</productname>ノード間で<literal>postgres</literal>ユーザ(Pgpool-IIのデフォルトの起動ユーザ。Pgpool-II 4.0以前、デフォルトの起動ユーザは<literal>root</literal>)として双方向にSSH公開鍵認証(パスワードなし)で接続できるように設定する必要があります。
- </para>
- <para>
- </para>
- <para>
- まず、全サーバで以下のコマンドを実行し、SSH鍵ファイルを作成します。
- この設定例では生成される鍵ファイル名は<literal>id_rsa_pgpool</literal>とします。
- </para>
- <programlisting>
-[全サーバ]# su - postgres
-[全サーバ]$ mkdir ~/.ssh
-[全サーバ]$ chmod 700 ~/.ssh
-[全サーバ]$ cd ~/.ssh
-[全サーバ]$ ssh-keygen -t rsa -f id_rsa_pgpool
+host replication repl samenet scram-sha-256
</programlisting>
- <para>
- 次に、公開鍵<literal>id_rsa_pgpool.pub</literal>を各サーバの<filename>/var/lib/pgsql/.ssh/authorized_keys</filename>ファイルに追加します。
- </para>
- <para>
- 設定後、<literal>postgres</literal>ユーザで<command>ssh postgres@serverX -i ~/.ssh/id_rsa_pgpool</command>コマンドを実行し、パスワードなしでログインできることを確認してください。
- </para>
-
- <note>
- <para>
- 公開鍵認証によるログインに失敗した場合には、以下を確認してください。
- <itemizedlist>
- <listitem>
- <para>
- <filename>/etc/ssh/sshd_config</filename>で公開鍵認証が許可されていることを確認します。
- </para>
- </listitem>
- </itemizedlist>
- <programlisting>
-PubkeyAuthentication yes
- </programlisting>
- <itemizedlist>
- <listitem>
- <para>
- SELinuxを有効化している場合は、SSH公開鍵認証(パスワードなし)が失敗する可能性があるので、すべてのサーバで以下のコマンドを実行する必要があります。
- </para>
- </listitem>
- </itemizedlist>
- <programlisting>
-[全サーバ]# su - postgres
-[全サーバ]$ restorecon -Rv ~/.ssh
- </programlisting>
- </para>
- </note>
</sect3>
<sect3 id="example-cluster-before-starting-pgpass">
パスワード入力なしで、ストリーミングレプリケーションや<application>pg_rewind</application>を実行するために、すべてのサーバで<literal>postgres</literal>ユーザのホームディレクトリ<filename>/var/lib/pgsql</filename>に<filename>.pgpass</filename>を作成し、パーミッションを600に設定しておきます。
</para>
<programlisting>
-[全サーバ]# su - postgres
-[全サーバ]$ vi /var/lib/pgsql/.pgpass
-(以下を追加)
+[postgres@server1 ~]$ vi ~/.pgpass
server1:5432:replication:repl:<replユーザのパスワード>
server2:5432:replication:repl:<replユーザのパスワード>
server3:5432:replication:repl:<replユーザのパスワード>
server1:5432:postgres:postgres:<postgresユーザのパスワード>
server2:5432:postgres:postgres:<postgresユーザのパスワード>
server3:5432:postgres:postgres:<postgresユーザのパスワード>
-[全サーバ]$ chmod 600 /var/lib/pgsql/.pgpass
+
+[postgres@server1 ~]$ chmod 600 ~/.pgpass
+ </programlisting>
+ <para>
+ server2およびserver3のpostgresユーザのホームディレクトリにコピーします。
+ </para>
+ <programlisting>
+[postgres@server1 ~]$ scp -i ~/.ssh/id_rsa_pgpool -p ~/.pgpass postgres@server2:
+[postgres@server1 ~]$ scp -i ~/.ssh/id_rsa_pgpool -p ~/.pgpass postgres@server3:
</programlisting>
</sect3>
+ </sect2>
- <sect3 id="example-cluster-before-starting-firewall">
- <title>firewallの設定</title>
+ <sect2 id="pcp-authentication">
+ <title>PCP接続認証の設定</title>
+ <para>
+ PCPコマンドを使用するには、<literal>username:encryptedpassword</literal>形式のPCPユーザ名とmd5暗号化パスワードを<filename>pcp.conf</filename>に登録する必要があります。
+ </para>
+ <para>
+ この設定例では、PCPユーザ名を<literal>pgpool</literal>、パスワードを<literal>pgpool_password</literal>に設定します。
+ 必要に応じて、ユーザ名とパスワードを変更してください。
+ </para>
+ <para>
+ 以下のように、pg_md5を使用して、pcpユーザpgpoolの暗号化されたパスワードエントリを作成します。
+ </para>
+ <programlisting>
+[postgres@server1 ~]$ echo 'pgpool:'`pg_md5 pgpool_password` >> /etc/pgpool-II/pcp.conf
+
+[postgres@server1 ~]$ cat /etc/pgpool-II/pcp.conf
+# USERID:MD5PASSWD
+pgpool:4aa0cb9673e84b06d4c8a848c80eb5d0
+ </programlisting>
+ <para>
+ 後述の<filename>follow_primary.sh</filename>のスクリプトでパスワード入力なしで<literal>PCP</literal>コマンドを実行する必要があるので、<productname>Pgpool-II</productname>の起動ユーザ(postgresユーザ)のホームディレクトリに<filename>.pcppass</filename>を作成します。
+ </para>
+ <programlisting>
+[postgres@server1 ~]$ echo 'localhost:9898:pgpool:pgpool_password' > ~/.pcppass
+[postgres@server1 ~]$ chmod 600 ~/.pcppass
+ </programlisting>
<para>
- <productname>Pgpool-II</productname>や<productname>PostgreSQL</productname>に接続する際には、ファイアーウォールによって目的のポートが開けられていなければなりません。
- <systemitem>Rocky Linux 8/RHEL 8</systemitem>の場合、以下のように設定します。
+ server2およびserver3のpostgresユーザのホームディレクトリにコピーします。
</para>
<programlisting>
-[全サーバ]# firewall-cmd --permanent --zone=public --add-service=postgresql
-[全サーバ]# firewall-cmd --permanent --zone=public --add-port=9999/tcp --add-port=9898/tcp --add-port=9000/tcp --add-port=9694/udp
-[全サーバ]# firewall-cmd --reload
- </programlisting>
- </sect3>
+[postgres@server1 ~]$ scp -i ~/.ssh/id_rsa_pgpool -p ~/.pcppass postgres@server2:
+[postgres@server1 ~]$ scp -i ~/.ssh/id_rsa_pgpool -p ~/.pcppass postgres@server3:
+[postgres@server1 ~]$ exit
+ </programlisting>
</sect2>
<sect2 id="example-cluster-pgpool-node-id">
<literal>server1</literal>
</para>
<programlisting>
-[server1]# cat /etc/pgpool-II/pgpool_node_id
+[root@server1 ~]# echo 0 > /etc/pgpool-II/pgpool_node_id
+[root@server1 ~]# cat /etc/pgpool-II/pgpool_node_id
0
</programlisting>
</listitem>
<literal>server2</literal>
</para>
<programlisting>
-[server2]# cat /etc/pgpool-II/pgpool_node_id
+[root@server2 ~]# echo 1 > /etc/pgpool-II/pgpool_node_id
+[root@server2 ~]# cat /etc/pgpool-II/pgpool_node_id
1
</programlisting>
</listitem>
<literal>server3</literal>
</para>
<programlisting>
-[server3]# cat /etc/pgpool-II/pgpool_node_id
+[root@server3 ~]# echo 2 > /etc/pgpool-II/pgpool_node_id
+[root@server3 ~]# cat /etc/pgpool-II/pgpool_node_id
2
</programlisting>
</listitem>
</itemizedlist>
</sect2>
- <sect2 id="pcp-authentication">
- <title>PCP接続認証の設定</title>
- <para>
- PCPコマンドを使用するには、<literal>username:encryptedpassword</literal>形式のPCPユーザ名とmd5暗号化パスワードを<filename>pcp.conf</filename>に登録する必要があります。
- </para>
- <para>
- この例では、PCPユーザ名を<literal>pgpool</literal>、パスワードを<literal>pgpool_password</literal>に設定します。
- 以下のように、pg_md5を使用して、pgpoolユーザの暗号化されたパスワードエントリを作成します。
- </para>
- <programlisting>
-[全サーバ]# echo 'pgpool:'`pg_md5 pgpool_password` >> /etc/pgpool-II/pcp.conf
-
-[全サーバ]# cat /etc/pgpool-II/pcp.conf
-# USERID:MD5PASSWD
-pgpool:4aa0cb9673e84b06d4c8a848c80eb5d0
- </programlisting>
- </sect2>
-
<sect2 id="example-cluster-pgpool-config">
<title><productname>Pgpool-II</productname>の設定</title>
<para>
<sect3 id="example-cluster-pgpool-config-config-file">
<title>クラスタリングモード</title>
<para>
- <productname>Pgpool-II</productname>ã\81«ã\81¯ã\81\84ã\81\8fã\81¤ã\81\8bã\81®ã\82¯ã\83©ã\82¹ã\82¿ã\83ªã\83³ã\82°ã\83¢ã\83¼ã\83\89ã\81\8cã\81\82ã\82\8aã\81¾ã\81\99ã\80\82
- ã\82¯ã\83©ã\82¹ã\82¿ã\83ªã\83³ã\82°ã\83¢ã\83¼ã\83\89ã\81®è¨å®\9aã\81«ã\81¯<xref linkend="GUC-BACKEND-CLUSTERING-MODE">を使用します。
- 今回の設定例では、ストリーミングレプリケーションモードを設定します。
+ <productname>Pgpool-II</productname>ã\81«ã\81¯ã\81\84ã\81\8fã\81¤ã\81\8bã\81®ã\82¯ã\83©ã\82¹ã\82¿ã\83ªã\83³ã\82°ã\83¢ã\83¼ã\83\89ã\81\8cã\81\82ã\82\8aã\80\81
+ ã\82¯ã\83©ã\82¹ã\82¿ã\83ªã\83³ã\82°ã\83¢ã\83¼ã\83\89ã\82\92è¨å®\9aã\81\99ã\82\8bã\81«ã\81¯<xref linkend="GUC-BACKEND-CLUSTERING-MODE">ã\81¨ã\81\84ã\81\86ã\83\91ã\83©ã\83¡ã\83¼ã\82¿を使用します。
+ この設定例では、ストリーミングレプリケーションモードを使用します。
</para>
<programlisting>
+[root@server1 ~]# vi /etc/pgpool-II/pgpool.conf
backend_clustering_mode = 'streaming_replication'
</programlisting>
</sect3>
末尾にノードIDを表す数字を付加することで複数のバックエンドを指定することができます。
</para>
<programlisting>
-# - Backend Connection Settings -
-
backend_hostname0 = 'server1'
backend_port0 = 5432
backend_weight0 = 1
-backend_data_directory0 = '/var/lib/pgsql/16/data'
+backend_data_directory0 = '/var/lib/pgsql/17/data'
backend_flag0 = 'ALLOW_TO_FAILOVER'
backend_hostname1 = 'server2'
backend_port1 = 5432
backend_weight1 = 1
-backend_data_directory1 = '/var/lib/pgsql/16/data'
+backend_data_directory1 = '/var/lib/pgsql/17/data'
backend_flag1 = 'ALLOW_TO_FAILOVER'
backend_hostname2 = 'server3'
backend_port2 = 5432
backend_weight2 = 1
-backend_data_directory2 = '/var/lib/pgsql/16/data'
+backend_data_directory2 = '/var/lib/pgsql/17/data'
backend_flag2 = 'ALLOW_TO_FAILOVER'
</programlisting>
ここではそれぞれのホスト名を設定します。
<varname>backend_application_nameX</varname>に設定された値が、<varname>primary_conninfo</varname>の<varname>application_name</varname>に設定された値と一致していることを確認してください。
<programlisting>
-...
backend_application_name0 = 'server1'
-...
backend_application_name1 = 'server2'
-...
backend_application_name2 = 'server3'
</programlisting>
</para>
</para>
</note>
<para>
- サンプルスクリプト<ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/failover.sh.sample;hb=refs/heads/V4_5_STABLE">failover.sh</ulink>及び
- <ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/follow_primary.sh.sample;hb=refs/heads/V4_5_STABLE">follow_primary.sh</ulink>は
+ サンプルスクリプト<ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/failover.sh.sample;hb=refs/heads/V4_6_STABLE">failover.sh</ulink>及び
+ <ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/follow_primary.sh.sample;hb=refs/heads/V4_6_STABLE">follow_primary.sh</ulink>は
<filename>/etc/pgpool-II/</filename>配下にインストールされていますので、これらのファイルをコピーして作成します。
</para>
<programlisting>
-[全サーバ]# cp -p /etc/pgpool-II/sample_scripts/failover.sh.sample /etc/pgpool-II/failover.sh
-[全サーバ]# cp -p /etc/pgpool-II/sample_scripts/follow_primary.sh.sample /etc/pgpool-II/follow_primary.sh
-[全サーバ]# chown postgres:postgres /etc/pgpool-II/{failover.sh,follow_primary.sh}
+[root@server1 ~]# cp -p /etc/pgpool-II/sample_scripts/failover.sh.sample /etc/pgpool-II/failover.sh
+[root@server1 ~]# cp -p /etc/pgpool-II/sample_scripts/follow_primary.sh.sample /etc/pgpool-II/follow_primary.sh
+[root@server1 ~]# chown postgres:postgres /etc/pgpool-II/{failover.sh,follow_primary.sh}
</programlisting>
<para>
基本的には<emphasis>PGHOME</emphasis>を環境に合わせて変更すれば、動作します。
</para>
<programlisting>
-[全サーバ]# vi /etc/pgpool-II/failover.sh
+[root@server1 ~]# vi /etc/pgpool-II/failover.sh
...
-PGHOME=/usr/pgsql-16
+PGHOME=/usr/pgsql-17
...
-[全サーバ]# vi /etc/pgpool-II/follow_primary.sh
+[root@server1 ~]# vi /etc/pgpool-II/follow_primary.sh
...
-PGHOME=/usr/pgsql-16
+PGHOME=/usr/pgsql-17
...
</programlisting>
<para>
この設定例では、前述の<xref linkend="PCP-AUTHENTICATION">セクションですでに登録済みです。
</para>
<programlisting>
-# cat /etc/pgpool-II/follow_primary.sh
+[root@server1 ~]# vi /etc/pgpool-II/follow_primary.sh
...
PCP_USER=pgpool
...
- </programlisting>
- <para>
- 前述の<filename>follow_primary.sh</filename>のスクリプトでパスワード入力なしで<literal>PCP</literal>コマンドを実行できるように、すべてのサーバで<productname>Pgpool-II</productname>の起動ユーザのホームディレクトリに<filename>.pcppass</filename>を作成します。
- </para>
- <para>
- この例では、PCPユーザが<literal>pgpool</literal>で、パスワードが<literal>pgpool_password</literal>とします。
- </para>
- <programlisting>
-[全サーバ]# su - postgres
-[全サーバ]$ echo 'localhost:9898:pgpool:pgpool_password' > ~/.pcppass
-[全サーバ]$ chmod 600 ~/.pcppass
</programlisting>
<note>
<para>
recovery_1st_stage_command = 'recovery_1st_stage'
</programlisting>
<para>
- オンラインリカバリ用のサンプルスクリプト<ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/recovery_1st_stage.sample;hb=refs/heads/V4_5_STABLE">recovery_1st_stage</ulink>
- 及び<ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/pgpool_remote_start.sample;hb=refs/heads/V4_5_STABLE">pgpool_remote_start</ulink>は
+ オンラインリカバリ用のサンプルスクリプト<ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/recovery_1st_stage.sample;hb=refs/heads/V4_6_STABLE">recovery_1st_stage</ulink>
+ 及び<ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/pgpool_remote_start.sample;hb=refs/heads/V4_6_STABLE">pgpool_remote_start</ulink>は
<filename>/etc/pgpool-II/</filename>配下にインストールされていますので、
これらのファイルをプライマリサーバ(<literal>server1</literal>)のデータベースクラスタ配下に配置します。
</para>
<programlisting>
-[server1]# cp -p /etc/pgpool-II/sample_scripts/recovery_1st_stage.sample /var/lib/pgsql/16/data/recovery_1st_stage
-[server1]# cp -p /etc/pgpool-II/sample_scripts/pgpool_remote_start.sample /var/lib/pgsql/16/data/pgpool_remote_start
-[server1]# chown postgres:postgres /var/lib/pgsql/16/data/{recovery_1st_stage,pgpool_remote_start}
+[root@server1 ~]# su - postgres -c "cp -p /etc/pgpool-II/sample_scripts/recovery_1st_stage.sample $PGDATA/recovery_1st_stage"
+[root@server1 ~]# su - postgres -c "cp -p /etc/pgpool-II/sample_scripts/pgpool_remote_start.sample $PGDATA/pgpool_remote_start"
</programlisting>
<para>
基本的には<emphasis>PGHOME</emphasis>を環境に合わせて変更すれば、動作します。
</para>
<programlisting>
-[server1]# vi /var/lib/pgsql/16/data/recovery_1st_stage
+[root@server1 ~]# vi /var/lib/pgsql/17/data/recovery_1st_stage
...
-PGHOME=/usr/pgsql-16
+PGHOME=/usr/pgsql-17
...
-[server1]# vi /var/lib/pgsql/16/data/pgpool_remote_start
+[root@server1 ~]# vi /var/lib/pgsql/17/data/pgpool_remote_start
...
-PGHOME=/usr/pgsql-16
+PGHOME=/usr/pgsql-17
...
</programlisting>
<literal>server1</literal>のtemplate1に<function>pgpool_recovery</function>をインストールしておきます。
</para>
<programlisting>
-[server1]# su - postgres
-[server1]$ psql template1 -c "CREATE EXTENSION pgpool_recovery"
+[root@server1 ~]# psql -U postgres template1 -c "CREATE EXTENSION pgpool_recovery"
</programlisting>
<note>
<para>
この設定例では、<productname>Pgpool-II</productname>に接続しているアプリケーションが同じサブネット内にあると想定しています。
</para>
<programlisting>
+[root@server1 ~]# vi /etc/pgpool-II/pool_hba.conf
+(以下を追加)
host all pgpool samenet scram-sha-256
host all postgres samenet scram-sha-256
</programlisting>
<para>
<productname>Pgpool-II</productname>のクライアント認証で用いるデフォルトのパスワードファイル名は<filename>pool_passwd</filename>です。
<acronym>scram-sha-256</acronym>認証を利用する場合、<productname>Pgpool-II</productname>はそれらのパスワードを復号化するために復号鍵が必要となります。
- 全サーバで復号鍵ファイルを<productname>Pgpool-II</productname>の起動ユーザ<literal>postgres</literal> (<productname>Pgpool-II</productname> 4.0以前のバージョンでは
- <literal>root</literal>) のホームディレクトリ配下に作成します。
+ 復号鍵ファイルを<productname>Pgpool-II</productname>の起動ユーザ<literal>postgres</literal>(<productname>Pgpool-II</productname> 4.0以前のバージョンでは<literal>root</literal>)のホームディレクトリ配下に作成し、<literal>server2</literal>および<literal>server3</literal>にコピーします。
</para>
<programlisting>
-[全サーバ]# su - postgres
-[全サーバ]$ echo '任意の文字列' > ~/.pgpoolkey
-[全サーバ]$ chmod 600 ~/.pgpoolkey
+[root@server1 ~]# su - postgres -c "echo '任意の文字列' > ~/.pgpoolkey"
+[root@server1 ~]# su - postgres -c "chmod 600 ~/.pgpoolkey"
+[root@server1 ~]# su - postgres -c "scp -i ~/.ssh/id_rsa_pgpool -p ~/.pgpoolkey postgres@server2:"
+[root@server1 ~]# su - postgres -c "scp -i ~/.ssh/id_rsa_pgpool -p ~/.pgpoolkey postgres@server3:"
</programlisting>
<para>
<command>pg_enc -m -k /path/to/.pgpoolkey -u username -p</command>を実行すると、ユーザ名と<acronym>AES256</acronym>で暗号化したパスワードのエントリが<xref linkend="GUC-POOL-PASSWD">に登録されます。
<xref linkend="GUC-POOL-PASSWD"> がまだ存在しなければ、<filename>pgpool.conf</filename>と同じディレクトリ内に作成されます。
</para>
<programlisting>
-[全サーバ]# su - postgres
-[全サーバ]$ pg_enc -m -k ~/.pgpoolkey -u pgpool -p
-db password: [pgpoolユーザのパスワード]
-[全サーバ]$ pg_enc -m -k ~/.pgpoolkey -u postgres -p
-db password: [postgresユーザのパスワード]
+[root@server1 ~]# pg_enc -m -k /var/lib/pgsql/.pgpoolkey -u pgpool -p
+db password: (pgpoolユーザのパスワードを入力)
+trying to read key from file /var/lib/pgsql/.pgpoolkey
+
+[root@server1 ~]# pg_enc -m -k /var/lib/pgsql/.pgpoolkey -u postgres -p
+db password: (postgresユーザのパスワードを入力)
+trying to read key from file /var/lib/pgsql/.pgpoolkey
-# cat /etc/pgpool-II/pool_passwd
+[root@server1 ~]# cat /etc/pgpool-II/pool_passwd
pgpool:AESheq2ZMZjynddMWk5sKP/Rw==
postgres:AESHs/pWL5rtXy2IwuzroHfqg==
</programlisting>
<para>
仮想IPの起動/停止、<command>ARP</command>リクエストの送信を行う設定パラメータ
- <xref linkend="GUC-IF-UP-CMD">、<xref linkend="GUC-IF-DOWN-CMD">、<xref linkend="GUC-ARPING-CMD">に、ネットワーク環境に合わせてネットワークインターフェース名を設定します。
+ <xref linkend="GUC-IF-UP-CMD">ã\80\81<xref linkend="GUC-IF-DOWN-CMD">ã\80\81<xref linkend="GUC-ARPING-CMD">ã\81«ã\80\81ã\83\8dã\83\83ã\83\88ã\83¯ã\83¼ã\82¯ç\92°å¢\83ã\81«å\90\88ã\82\8fã\81\9bã\81¦ã\83\8dã\83\83ã\83\88ã\83\9eã\82¹ã\82¯ã\81\8aã\82\88ã\81³ã\83\8dã\83\83ã\83\88ã\83¯ã\83¼ã\82¯ã\82¤ã\83³ã\82¿ã\83¼ã\83\95ã\82§ã\83¼ã\82¹å\90\8dã\82\92è¨å®\9aã\81\97ã\81¾ã\81\99ã\80\82
この設定例で使用しているネットワークインターフェースは<literal>enp0s8</literal>となります。
<varname>if_up/down_cmd</varname>や<varname>arping_cmd</varname>を実行するにはroot権限が必要となりますので、
一般ユーザで実行できるように<command>ip/arping</command>コマンドに<literal>setuid</literal>を設定するか、<productname>Pgpool-II</productname>起動ユーザ、デフォルトでは<literal>postgres</literal>ユーザ (<productname>Pgpool-II</productname> 4.1以降) がパスワードなしに<command>sudo</command>を実行できるように設定する必要があります。
wd_escalation_command = '/etc/pgpool-II/escalation.sh'
</programlisting>
<para>
- サンプルスクリプト<ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/escalation.sh.sample;hb=refs/heads/V4_5_STABLE">escalation.sh</ulink>は
+ サンプルスクリプト<ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/escalation.sh.sample;hb=refs/heads/V4_6_STABLE">escalation.sh</ulink>は
<filename>/etc/pgpool-II/</filename>配下にインストールされています。
</para>
<programlisting>
-[全サーバ]# cp -p /etc/pgpool-II/sample_scripts/escalation.sh.sample /etc/pgpool-II/escalation.sh
-[全サーバ]# chown postgres:postgres /etc/pgpool-II/escalation.sh
+[root@server1 ~]# cp -p /etc/pgpool-II/sample_scripts/escalation.sh.sample /etc/pgpool-II/escalation.sh
+[root@server1 ~]# chown postgres:postgres /etc/pgpool-II/escalation.sh
</programlisting>
<para>
サーバのホスト名、仮想IP、仮想IPを設定するネットワークインターフェース名を環境に合わせて変更してください。
</para>
<programlisting>
-[全サーバ]# vi /etc/pgpool-II/escalation.sh
+[root@server1 ~]# vi /etc/pgpool-II/escalation.sh
...
PGPOOLS=(server1 server2 server3)
VIP=192.168.100.50
DEVICE=enp0s8
+CIDR_NETMASK=24
...
</programlisting>
<title>ログの設定</title>
<para>
<productname>Pgpool-II</productname> 4.2以降、ログ収集プロセスが追加されました。
- ここでは、ログ収集プロセス(<literal>logging_collector</literal>)を有効にします。
+ RPM パッケージを使用してインストールした場合、ログ収集プロセス(<literal>logging_collector</literal>)はデフォルトで有効になっています。
+ ログファイルはデフォルトで<filename>/var/log/pgpool_log</filename>に出力されます。
+ 要件に合わせて、ログ関連の設定パラメータを適切に調整してください。
</para>
<programlisting>
log_destination = 'stderr'
log_filename = 'pgpool-%a.log'
log_truncate_on_rotation = on
log_rotation_age = 1d
-log_rotation_size = 10MB
</programlisting>
<para>
- すべてのサーバでログファイルを格納するディレクトリを作成します。
- </para>
- <programlisting>
-[全サーバ]# mkdir /var/log/pgpool_log/
-[全サーバ]# chown postgres:postgres /var/log/pgpool_log/
- </programlisting>
-
- <para>
- これで、<literal>server1</literal>での<filename>pgpool.conf</filename>の設定は完了です。
- 最後に、<literal>server1</literal>の<filename>pgpool.conf</filename>を他のサーバ<literal>server2</literal>、<literal>server3</literal>にコピーします。
+ これで、<literal>server1</literal>における<productname>Pgpool-II</productname>の設定は完了です。
+ 最後に、設定ファイルを他のサーバ<literal>server2</literal>および<literal>server3</literal>にコピーします。
</para>
<programlisting>
-[server1]# scp -p /etc/pgpool-II/pgpool.conf root@server2:/etc/pgpool-II/pgpool.conf
-[server1]# scp -p /etc/pgpool-II/pgpool.conf root@server3:/etc/pgpool-II/pgpool.conf
+[root@server1 ~]# scp -p /etc/pgpool-II/{*.conf,*.sh,pool_passwd} server2:/etc/pgpool-II/
+[root@server1 ~]# ssh server2 "chown postgres:postgres /etc/pgpool-II/{*.conf,*.sh,pool_passwd}"
+[root@server1 ~]# scp -p /etc/pgpool-II/{*.conf,*.sh,pool_passwd} server3:/etc/pgpool-II/
+[root@server1 ~]# ssh server3 "chown postgres:postgres /etc/pgpool-II/{*.conf,*.sh,pool_passwd}"
</programlisting>
</sect3>
</sect2>
<productname>PostgreSQL</productname>プライマリサーバがまだ起動していない場合は、まず次のコマンドを実行して<productname>PostgreSQL</productname>起動します。
</para>
<programlisting>
-[server1]# su - postgres
-[server1]$ /usr/pgsql-16/bin/pg_ctl start -D $PGDATA
+[root@server1 ~]# su - postgres -c "/usr/pgsql-17/bin/pg_ctl start"
</programlisting>
<para>
<literal>server1</literal>、<literal>server2</literal>および<literal>server3</literal>で以下のコマンドを実行し、<productname>Pgpool-II</productname>を起動します。
<productname>Pgpool-II</productname>が起動している状態でPostgreSQLを停止する、想定外のフェイルオーバが起きてしまうので、ご注意ください。
</para>
<programlisting>
-# systemctl stop pgpool.service
+[全サーバ]# systemctl stop pgpool.service
</programlisting>
</listitem>
</itemizedlist>
<literal>server1</literal>の<productname>Pgpool-II</productname>を停止するには<productname>Pgpool-II</productname>を停止するか、マシンをシャットダウンします。ここでは、<productname>Pgpool-II</productname>を停止します。
</para>
<programlisting>
-[server1]# systemctl stop pgpool.service
+[root@server1 ~]# systemctl stop pgpool.service
-[server1]# pcp_watchdog_info -p 9898 -h 192.168.100.50 -U pgpool -W
+[root@server1 ~]# pcp_watchdog_info -p 9898 -h 192.168.100.50 -U pgpool -W
Password:
3 3 YES server2:9999 Linux server2 server2
先ほど停止した<productname>Pgpool-II</productname>を再起動し、スタンバイとして起動していることを確認します。
</para>
<programlisting>
-[server1]# systemctl start pgpool.service
+[root@server1 ~]# systemctl start pgpool.service
-[server1]# pcp_watchdog_info -p 9898 -h 192.168.100.50 -U pgpool -W
+[root@server1 ~]# pcp_watchdog_info -p 9898 -h 192.168.100.50 -U pgpool -W
Password:
3 3 YES server2:9999 Linux server2 server2
フェイルオーバするかどうか確認してみます。
</para>
<programlisting>
-[server1]$ pg_ctl -D /var/lib/pgsql/16/data -m immediate stop
+[root@server1 ~]# su - postgres -c "/usr/pgsql-17/bin/pg_ctl -m immediate stop"
</programlisting>
<para>
<literal>ノード1</literal>を停止した後に、フェイルオーバが発生し、<literal>server2</literal>が
servers to create a robust cluster system and avoid the single point of failure or split brain.
</para>
<para>
- <productname>PostgreSQL</productname> 16 is used in this configuration example.
+ <emphasis><productname>PostgreSQL</productname> 17</emphasis> is used in this configuration example.
All scripts have been tested with <productname>PostgreSQL</productname> 10 and later.
</para>
<sect2 id="example-cluster-requirement">
<sect2 id="example-cluster-structure">
<title>Cluster System Configuration</title>
<para>
- We use three servers with Rocky Linux 8 installed and
+ We use three servers with <emphasis>Rocky Linux 9</emphasis> installed and
the hostnames of the three servers are <literal>server1</literal>
<literal>server2</literal> and <literal>server3</literal> respectively.
We install <productname>PostgreSQL</productname> and <productname>Pgpool-II</productname> on each server.
<tbody>
<row>
<entry>PostgreSQL Version</entry>
- <entry>16.0</entry>
+ <entry>17.0</entry>
<entry>-</entry>
</row>
<row>
</row>
<row>
<entry>$PGDATA</entry>
- <entry>/var/lib/pgsql/16/data</entry>
+ <entry>/var/lib/pgsql/17/data</entry>
<entry>-</entry>
</row>
<row>
<entry>Archive mode</entry>
- <entry>on</entry>
- <entry>/var/lib/pgsql/archivedir</entry>
+ <entry>off</entry>
+ <entry>-</entry>
</row>
<row>
<entry>Replication Slots</entry>
<tbody>
<row>
<entry>Pgpool-II Version</entry>
- <entry>4.5.0</entry>
+ <entry>4.6.0</entry>
<entry>-</entry>
</row>
<row>
<tbody>
<row>
<entry morerows='1'>Failover</entry>
- <entry><ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/failover.sh.sample;hb=refs/heads/V4_5_STABLE">/etc/pgpool-II/sample_scripts/failover.sh.sample</ulink></entry>
+ <entry><ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/failover.sh.sample;hb=refs/heads/V4_6_STABLE">/etc/pgpool-II/sample_scripts/failover.sh.sample</ulink></entry>
<entry>Run by <xref linkend="GUC-FAILOVER-COMMAND"> to perform failover</entry>
</row>
<row>
- <entry><ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/follow_primary.sh.sample;hb=refs/heads/V4_5_STABLE">/etc/pgpool-II/sample_scripts/follow_primary.sh.sample</ulink></entry>
+ <entry><ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/follow_primary.sh.sample;hb=refs/heads/V4_6_STABLE">/etc/pgpool-II/sample_scripts/follow_primary.sh.sample</ulink></entry>
<entry>Run by <xref linkend="GUC-FOLLOW-PRIMARY-COMMAND"> to synchronize the Standby with the new Primary after failover.</entry>
</row>
<row>
<entry morerows='1'>Online recovery</entry>
- <entry><ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/recovery_1st_stage.sample;hb=refs/heads/V4_5_STABLE">/etc/pgpool-II/sample_scripts/recovery_1st_stage.sample</ulink></entry>
+ <entry><ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/recovery_1st_stage.sample;hb=refs/heads/V4_6_STABLE">/etc/pgpool-II/sample_scripts/recovery_1st_stage.sample</ulink></entry>
<entry>Run by <xref linkend="GUC-RECOVERY-1ST-STAGE-COMMAND"> to recovery a Standby node</entry>
</row>
<row>
- <entry><ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/pgpool_remote_start.sample;hb=refs/heads/V4_5_STABLE">/etc/pgpool-II/sample_scripts/pgpool_remote_start.sample</ulink></entry>
+ <entry><ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/pgpool_remote_start.sample;hb=refs/heads/V4_6_STABLE">/etc/pgpool-II/sample_scripts/pgpool_remote_start.sample</ulink></entry>
<entry>Run after <xref linkend="GUC-RECOVERY-1ST-STAGE-COMMAND"> to start the Standby node</entry>
</row>
<row>
<entry morerows='1'>Watchdog</entry>
- <entry><ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/escalation.sh.sample;hb=refs/heads/V4_5_STABLE">/etc/pgpool-II/sample_scripts/escalation.sh.sample</ulink></entry>
+ <entry><ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/escalation.sh.sample;hb=refs/heads/V4_6_STABLE">/etc/pgpool-II/sample_scripts/escalation.sh.sample</ulink></entry>
<entry>Optional Configuration. Run by <xref linkend="guc-wd-escalation-command"> to switch the Leader/Standby Pgpool-II safely</entry>
</row>
</tbody>
Install <productname>PostgreSQL</productname> from <productname>PostgreSQL</productname> YUM repository.
</para>
<programlisting>
-[all servers]# dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
+[all servers]# dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
[all servers]# dnf -qy module disable postgresql
-[all servers]# dnf install -y postgresql16-server
+[all servers]# dnf install -y postgresql17-server
</programlisting>
<para>
Since <productname>Pgpool-II</productname> related packages are also included in <productname>PostgreSQL</productname> YUM repository,
...
exclude=pgpool*
+[pgdg17]
+...
+exclude=pgpool*
+
[pgdg16]
...
exclude=pgpool*
[pgdg12]
...
-exclude=pgpool*
-
-[pgdg11]
-...
exclude=pgpool*
</programlisting>
<para>
- Install <productname>Pgpool-II</productname> from Pgpool-II YUM repository.
+ Install <productname>Pgpool-II</productname> from
+ <productname>Pgpool-II</productname> YUM repository.
+ To install the required libmemcached library for Pgpool-II,
+ you need to enable <literal>crb</literal> repository.
+ If you're using <literal>Rocky Linux 8</literal>,
+ use <literal>powertools</literal> repository instead of
+ <literal>crb</literal> repository.
</para>
<programlisting>
-[all servers]# dnf install -y https://www.pgpool.net/yum/rpms/4.5/redhat/rhel-8-x86_64/pgpool-II-release-4.5-1.noarch.rpm
-[all servers]# dnf install -y pgpool-II-pg16-*
+[all servers]# dnf install -y https://www.pgpool.net/yum/rpms/4.6/redhat/rhel-9-x86_64/pgpool-II-release-4.6-1.noarch.rpm
+[all servers]# dnf install -y --enablerepo=crb pgpool-II-pg17-*
</programlisting>
</sect2>
Before you start the configuration process, please check the following prerequisites.
</para>
- <sect3 id="example-cluster-before-starting-primary">
- <title>Setting up streaming replication on Primary</title>
+ <sect3 id="example-cluster-before-starting-ssh">
+ <title>Setting up SSH public key authentication</title>
<para>
- Set up <productname>PostgreSQL</productname> streaming replication on the primary server.
- In this example, we use WAL archiving.
+ To use the automated failover and online recovery of <productname>Pgpool-II</productname>,
+ it is required to configure <emphasis>SSH public key authentication
+ (passwordless SSH login)</emphasis> to all backend servers using
+ <literal>postgres</literal> user (the default user Pgpool-II is running as.
+ Pgpool-II 4.0 or before, the default user is <literal>root</literal>).
</para>
<para>
- First, we create the directory <filename>/var/lib/pgsql/archivedir</filename> to store
- <acronym>WAL</acronym> segments on all servers. In this example, only Primary node archives
- <acronym>WAL</acronym> locally.
+ Execute the following command on all servers to generate a key pair using
+ the RSA algorithm. In this example, we assume that the generated key file
+ name is <literal>id_rsa_pgpool</literal>.
</para>
<programlisting>
[all servers]# su - postgres
-[all servers]$ mkdir /var/lib/pgsql/archivedir
+[all servers]$ mkdir ~/.ssh && chmod 700 ~/.ssh
+[all servers]$ ssh-keygen -t rsa -f ~/.ssh/id_rsa_pgpool
</programlisting>
+ <para>
+ Then add the public key <filename>id_rsa_pgpool.pub</filename> to
+ <filename>/var/lib/pgsql/.ssh/authorized_keys</filename> file
+ on each server.
+ </para>
+ <para>
+ After setting SSH, make sure that you can run
+ <command>ssh postgres@serverX -i ~/.ssh/id_rsa_pgpool</command> command
+ as <literal>postgres</literal> user to login to each server
+ without entering a password.
+ </para>
+ <note>
+ <para>
+ If you failed to login using SSH public key authentication, please check the following:
+ <itemizedlist>
+ <listitem>
+ <para>
+ Ensure the public key authentication option <literal>PubkeyAuthentication</literal> are allowed in <filename>/etc/ssh/sshd_config</filename>:
+ </para>
+ </listitem>
+ </itemizedlist>
+ <programlisting>
+PubkeyAuthentication yes
+ </programlisting>
+ <itemizedlist>
+ <listitem>
+ <para>
+ If SELinux is enabled, SSH public key authentication (passwordless SSH) may fail.
+ You need to run the following command on all servers.
+ </para>
+ </listitem>
+ </itemizedlist>
+ <programlisting>
+[all servers]# su - postgres
+[all servers]$ restorecon -Rv ~/.ssh
+ </programlisting>
+ </para>
+ </note>
+ </sect3>
+
+ <sect3 id="example-cluster-before-starting-firewall">
+ <title>Setting up firewall</title>
<para>
- Initialize <productname>PostgreSQL</productname> on the primary server.
+ When connect to <productname>Pgpool-II</productname> and <productname>PostgreSQL</productname> servers, the target port must be accessible by enabling firewall management softwares. Following is an example for <systemitem>Rocky Linux 8/RHEL 8</systemitem>.
</para>
<programlisting>
-[server1]# su - postgres
-[server1]$ /usr/pgsql-16/bin/initdb -D $PGDATA
+[all servers]# firewall-cmd --permanent --zone=public --add-service=postgresql
+[all servers]# firewall-cmd --permanent --zone=public --add-port=9999/tcp --add-port=9898/tcp --add-port=9000/tcp --add-port=9694/udp
+[all servers]# firewall-cmd --reload
+ </programlisting>
+ </sect3>
+
+ <sect3 id="example-cluster-before-starting-primary">
+ <title>Setting up PostgreSQL primary</title>
+ <para>
+ Set up the PostgreSQL primary server on <literal>server1</literal>.
+ </para>
+
+ <para>
+ First, initialize the database cluster.
+ In <productname>PostgreSQL</productname> 17, the default directory
+ for creating the database cluster is <filename>/var/lib/pgsql/17/data</filename>,
+ and this is specified in the environment variable <varname>PGDATA</varname>
+ in the <filename>~/.bash_profile</filename> of the <literal>postgres</literal>
+ user. Modify it if you want to change the default path.
+ </para>
+ <para>
+ Run <command>initdb</command> to initialize the database cluster.
+ Specify <ulink url="https://www.postgresql.org/docs/17/app-initdb.html">options</ulink>
+ such as <literal>--encoding</literal> and <literal>--locale</literal>
+ if you need to configure the database encoding and locale settings.
+ </para>
+ <programlisting>
+[root@server1 ~]# su - postgres
+[postgres@server1 ~]$ /usr/pgsql-17/bin/initdb
</programlisting>
<para>
- Then we edit the configuration file <filename>$PGDATA/postgresql.conf</filename>
- on <literal>server1</literal> (primary) as follows. Enable <literal>wal_log_hints</literal>
+ Then edit the configuration file <filename>$PGDATA/postgresql.conf</filename>
+ on <literal>server1</literal> as follows. Enable <literal>wal_log_hints</literal>
to use <literal>pg_rewind</literal>.
- Since the Primary may become a Standby later, we set <varname>hot_standby = on</varname>.
</para>
<programlisting>
+[postgres@server1 ~]$ vi $PGDATA/postgresql.conf
listen_addresses = '*'
-archive_mode = on
-archive_command = 'cp "%p" "/var/lib/pgsql/archivedir/%f"'
-max_wal_senders = 10
-max_replication_slots = 10
-wal_level = replica
-hot_standby = on
wal_log_hints = on
</programlisting>
<para>
- Start PostgreSQL primary server on <literal>server1</literal>.
+ Start <productname>PostgreSQL</productname> on <literal>server1</literal>.
</para>
<programlisting>
-[server1]# su - postgres
-[server1]$ /usr/pgsql-16/bin/pg_ctl start -D $PGDATA
+[postgres@server1 ~]$ /usr/pgsql-17/bin/pg_ctl start
</programlisting>
</sect3>
<sect3 id="example-cluster-before-starting-standby">
- <title>Setting up streaming replication on Standby</title>
+ <title>Setting up PostgreSQL standby</title>
<para>
There are multiple methods to setup a standby server, such as:
<itemizedlist>
<listitem>
<para>
- use pg_basebackup to backup the data directory of the primary from the standby.
+ use <command>pg_basebackup</command> to backup the data directory of the primary from the standby.
</para>
</listitem>
<listitem>
</table>
<programlisting>
-[server1]# psql -U postgres -p 5432
+[postgres@server1 ~]$ psql
postgres=# SET password_encryption = 'scram-sha-256';
postgres=# CREATE ROLE pgpool WITH LOGIN;
postgres=# CREATE ROLE repl WITH REPLICATION LOGIN;
to <literal>pgpool</literal>:
</para>
<programlisting>
-GRANT pg_monitor TO pgpool;
+postgres=# GRANT pg_monitor TO pgpool;
+postgres=# \q
</programlisting>
<note>
<para>
</para>
</note>
<para>
- Assuming that all the <productname>Pgpool-II</productname> servers and the
+ In this example, assuming that all the <productname>Pgpool-II</productname> servers and the
<productname>PostgreSQL</productname> servers are in the same subnet and edit <filename>pg_hba.conf</filename> to
enable <literal>scram-sha-256</literal> authentication method.
</para>
<programlisting>
+[postgres@server1 ~]$ vi $PGDATA/pg_hba.conf
+(Add the following entries)
host all pgpool samenet scram-sha-256
host all postgres samenet scram-sha-256
host replication repl samenet scram-sha-256
</programlisting>
</sect3>
- <sect3 id="example-cluster-before-starting-ssh">
- <title>Setting up SSH public key authentication</title>
- <para>
- To use the automated failover and online recovery of <productname>Pgpool-II</productname>,
- it is required to configure <emphasis>SSH public key authentication
- (passwordless SSH login)</emphasis> to all backend servers using
- <literal>postgres</literal> user (the default user Pgpool-II is running as.
- Pgpool-II 4.0 or before, the default user is <literal>root</literal>).
- </para>
- <para>
- Execute the following command on all servers to generate a key pair using
- the RSA algorithm. In this example, we assume that the generated key file
- name is <literal>id_rsa_pgpool</literal>.
- </para>
- <programlisting>
-[all servers]# su - postgres
-[all servers]$ mkdir ~/.ssh
-[all servers]$ chmod 700 ~/.ssh
-[all servers]$ cd ~/.ssh
-[all servers]$ ssh-keygen -t rsa -f id_rsa_pgpool
- </programlisting>
- <para>
- Then add the public key <filename>id_rsa_pgpool.pub</filename> to
- <filename>/var/lib/pgsql/.ssh/authorized_keys</filename> file
- on each server.
- </para>
- <para>
- After setting SSH, make sure that you can run
- <command>ssh postgres@serverX -i ~/.ssh/id_rsa_pgpool</command> command
- as <literal>postgres</literal> user to login to each server
- without entering a password.
- </para>
-
- <note>
- <para>
- If you failed to login using SSH public key authentication, please check the following:
- <itemizedlist>
- <listitem>
- <para>
- Ensure the public key authentication option <literal>PubkeyAuthentication</literal> are allowed in <filename>/etc/ssh/sshd_config</filename>:
- </para>
- </listitem>
- </itemizedlist>
- <programlisting>
-PubkeyAuthentication yes
- </programlisting>
- <itemizedlist>
- <listitem>
- <para>
- If SELinux is enabled, SSH public key authentication (passwordless SSH) may fail.
- You need to run the following command on all servers.
- </para>
- </listitem>
- </itemizedlist>
- <programlisting>
-[all servers]# su - postgres
-[all servers]$ restorecon -Rv ~/.ssh
- </programlisting>
- </para>
- </note>
- </sect3>
-
<sect3 id="example-cluster-before-starting-pgpass">
<title>Creating .pgpass</title>
<para>
user without providing a password for streaming replication and failover.
</para>
<programlisting>
-[all servers]# su - postgres
-[all servers]$ vi /var/lib/pgsql/.pgpass
+[postgres@server1 ~]$ vi ~/.pgpass
server1:5432:replication:repl:<repl user password>
server2:5432:replication:repl:<repl user password>
server3:5432:replication:repl:<repl user password>
server1:5432:postgres:postgres:<postgres user password>
server2:5432:postgres:postgres:<postgres user password>
server3:5432:postgres:postgres:<postgres user password>
-[all servers]$ chmod 600 /var/lib/pgsql/.pgpass
- </programlisting>
- </sect3>
- <sect3 id="example-cluster-before-starting-firewall">
- <title>Setting up firewall</title>
+[postgres@server1 ~]$ chmod 600 ~/.pgpass
+ </programlisting>
<para>
- When connect to <productname>Pgpool-II</productname> and <productname>PostgreSQL</productname> servers, the target port must be accessible by enabling firewall management softwares. Following is an example for <systemitem>Rocky Linux 8/RHEL 8</systemitem>.
+ Copy it to the home directory of <literal>postgres</literal> user
+ on <literal>server2</literal> and <literal>server3</literal>.
</para>
<programlisting>
-[all servers]# firewall-cmd --permanent --zone=public --add-service=postgresql
-[all servers]# firewall-cmd --permanent --zone=public --add-port=9999/tcp --add-port=9898/tcp --add-port=9000/tcp --add-port=9694/udp
-[all servers]# firewall-cmd --reload
+[postgres@server1 ~]$ scp -i ~/.ssh/id_rsa_pgpool -p ~/.pgpass postgres@server2:
+[postgres@server1 ~]$ scp -i ~/.ssh/id_rsa_pgpool -p ~/.pgpass postgres@server3:
</programlisting>
</sect3>
</sect2>
+ <sect2 id="pcp-authentication">
+ <title>PCP connection authentication</title>
+ <para>
+ To use PCP commands PCP user names and md5 encrypted passwords must be
+ declared in <filename>pcp.conf</filename> in format
+ "<literal>username:encrypted password</literal>".
+ </para>
+ <para>
+ In this example, we set PCP username to "<literal>pgpool</literal>"
+ and password to "<literal>pgpool_password</literal>".
+ Use <xref linkend="PG-MD5"> to create the encrypted password entry for
+ <literal>pgpool</literal> user as below:
+ </para>
+ <programlisting>
+[postgres@server1 ~]$ echo 'pgpool:'`pg_md5 pgpool_password` >> /etc/pgpool-II/pcp.conf
+
+[postgres@server1 ~]$ cat /etc/pgpool-II/pcp.conf
+# USERID:MD5PASSWD
+pgpool:4aa0cb9673e84b06d4c8a848c80eb5d0
+ </programlisting>
+ <para>
+ Since <filename>follow_primary.sh</filename> script mentioned
+ later must execute PCP command without entering a password,
+ create <filename>.pcppass</filename> in
+ <literal>postgres</literal> user's home directory
+ (the home directory of the user Pgpool-II is running as).
+ The format of <filename>.pcppass</filename> is
+ "<literal>hostname:port:username:password</literal>".
+ </para>
+ <para>
+ In this example, we assume that the PCP user is <literal>pgpool</literal>
+ and the password is <literal>pgpool_password</literal>.
+ </para>
+ <programlisting>
+[postgres@server1 ~]$ echo 'localhost:9898:pgpool:pgpool_password' > ~/.pcppass
+[postgres@server1 ~]$ chmod 600 ~/.pcppass
+ </programlisting>
+ <para>
+ Copy to <literal>server2</literal> and <literal>server3</literal>.
+ </para>
+ <programlisting>
+[postgres@server1 ~]$ scp -i ~/.ssh/id_rsa_pgpool -p ~/.pcppass postgres@server2:
+[postgres@server1 ~]$ scp -i ~/.ssh/id_rsa_pgpool -p ~/.pcppass postgres@server3:
+[postgres@server1 ~]$ exit
+ </programlisting>
+ </sect2>
+
<sect2 id="example-cluster-pgpool-node-id">
<title>Create pgpool_node_id</title>
<para>
<literal>server1</literal>
</para>
<programlisting>
-[server1]# cat /etc/pgpool-II/pgpool_node_id
+[root@server1 ~]# echo 0 > /etc/pgpool-II/pgpool_node_id
+[root@server1 ~]# cat /etc/pgpool-II/pgpool_node_id
0
</programlisting>
</listitem>
<literal>server2</literal>
</para>
<programlisting>
-[server2]# cat /etc/pgpool-II/pgpool_node_id
+[root@server2 ~]# echo 1 > /etc/pgpool-II/pgpool_node_id
+[root@server2 ~]# cat /etc/pgpool-II/pgpool_node_id
1
</programlisting>
</listitem>
<literal>server3</literal>
</para>
<programlisting>
-[server3]# cat /etc/pgpool-II/pgpool_node_id
+[root@server3 ~]# echo 2 > /etc/pgpool-II/pgpool_node_id
+[root@server3 ~]# cat /etc/pgpool-II/pgpool_node_id
2
</programlisting>
</listitem>
</itemizedlist>
</sect2>
- <sect2 id="pcp-authentication">
- <title>PCP connection authentication</title>
- <para>
- To use PCP commands PCP user names and md5 encrypted passwords must be
- declared in <filename>pcp.conf</filename> in format
- "<literal>username:encrypted password</literal>".
- </para>
- <para>
- In this example, we set PCP username to "<literal>pgpool</literal>"
- and password to "<literal>pgpool_password</literal>".
- Use <xref linkend="PG-MD5"> to create the encrypted password entry for
- <literal>pgpool</literal> user as below:
- </para>
- <programlisting>
-[all servers]# echo 'pgpool:'`pg_md5 pgpool_password` >> /etc/pgpool-II/pcp.conf
-
-[all servers]# cat /etc/pgpool-II/pcp.conf
-# USERID:MD5PASSWD
-pgpool:4aa0cb9673e84b06d4c8a848c80eb5d0
- </programlisting>
- </sect2>
-
<sect2 id="example-cluster-pgpool-config">
<title><productname>Pgpool-II</productname> Configuration</title>
<para>
example, streaming replication mode is used.
</para>
<programlisting>
+[root@server1 ~]# vi /etc/pgpool-II/pgpool.conf
backend_clustering_mode = 'streaming_replication'
</programlisting>
</sect3>
Multiple backends can be specified by adding a number at the end of the parameter name.
</para>
<programlisting>
-# - Backend Connection Settings -
-
backend_hostname0 = 'server1'
backend_port0 = 5432
backend_weight0 = 1
-backend_data_directory0 = '/var/lib/pgsql/16/data'
+backend_data_directory0 = '/var/lib/pgsql/17/data'
backend_flag0 = 'ALLOW_TO_FAILOVER'
backend_hostname1 = 'server2'
backend_port1 = 5432
backend_weight1 = 1
-backend_data_directory1 = '/var/lib/pgsql/16/data'
+backend_data_directory1 = '/var/lib/pgsql/17/data'
backend_flag1 = 'ALLOW_TO_FAILOVER'
backend_hostname2 = 'server3'
backend_port2 = 5432
backend_weight2 = 1
-backend_data_directory2 = '/var/lib/pgsql/16/data'
+backend_data_directory2 = '/var/lib/pgsql/17/data'
backend_flag2 = 'ALLOW_TO_FAILOVER'
</programlisting>
<para>
of <varname>primary_conninfo</varname>.
</para>
<programlisting>
-...
backend_application_name0 = 'server1'
-...
backend_application_name1 = 'server2'
-...
backend_application_name2 = 'server3'
</programlisting>
</sect3>
</para>
</note>
<para>
- Sample scripts <ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/failover.sh.sample;hb=refs/heads/V4_5_STABLE">failover.sh</ulink>
- and <ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/follow_primary.sh.sample;hb=refs/heads/V4_5_STABLE">follow_primary.sh</ulink>
+ Sample scripts <ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/failover.sh.sample;hb=refs/heads/V4_6_STABLE">failover.sh</ulink>
+ and <ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/follow_primary.sh.sample;hb=refs/heads/V4_6_STABLE">follow_primary.sh</ulink>
are installed in <filename>/etc/pgpool-II/</filename>. Create failover scripts using these sample files.
</para>
<programlisting>
-[all servers]# cp -p /etc/pgpool-II/sample_scripts/failover.sh.sample /etc/pgpool-II/failover.sh
-[all servers]# cp -p /etc/pgpool-II/sample_scripts/follow_primary.sh.sample /etc/pgpool-II/follow_primary.sh
-[all servers]# chown postgres:postgres /etc/pgpool-II/{failover.sh,follow_primary.sh}
+[root@server1 ~]# cp -p /etc/pgpool-II/sample_scripts/failover.sh.sample /etc/pgpool-II/failover.sh
+[root@server1 ~]# cp -p /etc/pgpool-II/sample_scripts/follow_primary.sh.sample /etc/pgpool-II/follow_primary.sh
+[root@server1 ~]# chown postgres:postgres /etc/pgpool-II/{failover.sh,follow_primary.sh}
</programlisting>
<para>
Basically, it should work if you change <emphasis>PGHOME</emphasis> according to
PostgreSQL installation directory.
</para>
<programlisting>
-[all servers]# vi /etc/pgpool-II/failover.sh
+[root@server1 ~]# vi /etc/pgpool-II/failover.sh
...
-PGHOME=/usr/pgsql-16
+PGHOME=/usr/pgsql-17
...
-[all servers]# vi /etc/pgpool-II/follow_primary.sh
+[root@server1 ~]# vi /etc/pgpool-II/follow_primary.sh
...
-PGHOME=/usr/pgsql-16
+PGHOME=/usr/pgsql-17
...
</programlisting>
In this example, we have created in <xref linkend="PCP-AUTHENTICATION">
</para>
<programlisting>
-# cat /etc/pgpool-II/follow_primary.sh
+[root@server1 ~]# cat /etc/pgpool-II/follow_primary.sh
...
PCP_USER=pgpool
...
- </programlisting>
- <para>
- Since <filename>follow_primary.sh</filename> script must execute PCP command without
- entering a password, we need to create <filename>.pcppass</filename> in
- <literal>postgres</literal> user's home directory on each server
- (the home directory of the user Pgpool-II is running as).
- The format of <filename>.pcppass</filename> is
- "<literal>hostname:port:username:password</literal>".
- </para>
- <para>
- In this example, we assume that the PCP user is <literal>pgpool</literal>
- and the password is <literal>pgpool_password</literal>.
- </para>
- <programlisting>
-[all servers]# su - postgres
-[all servers]$ echo 'localhost:9898:pgpool:pgpool_password' > ~/.pcppass
-[all servers]$ chmod 600 ~/.pcppass
</programlisting>
<note>
<para>
primary server (server1).
</para>
<para>
- The sample scripts of online recovery <ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/recovery_1st_stage.sample;hb=refs/heads/V4_5_STABLE">recovery_1st_stage</ulink>
- and <ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/pgpool_remote_start.sample;hb=refs/heads/V4_5_STABLE">pgpool_remote_start</ulink>
+ The sample scripts of online recovery <ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/recovery_1st_stage.sample;hb=refs/heads/V4_6_STABLE">recovery_1st_stage</ulink>
+ and <ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/pgpool_remote_start.sample;hb=refs/heads/V4_6_STABLE">pgpool_remote_start</ulink>
are installed in <filename>/etc/pgpool-II/</filename>. Copy these files to the data directory of the primary server (server1).
</para>
<programlisting>
-[server1]# cp -p /etc/pgpool-II/sample_scripts/recovery_1st_stage.sample /var/lib/pgsql/16/data/recovery_1st_stage
-[server1]# cp -p /etc/pgpool-II/sample_scripts/pgpool_remote_start.sample /var/lib/pgsql/16/data/pgpool_remote_start
-[server1]# chown postgres:postgres /var/lib/pgsql/16/data/{recovery_1st_stage,pgpool_remote_start}
+[root@server1 ~]# su - postgres -c "cp -p /etc/pgpool-II/sample_scripts/recovery_1st_stage.sample $PGDATA/recovery_1st_stage"
+[root@server1 ~]# su - postgres -c "cp -p /etc/pgpool-II/sample_scripts/pgpool_remote_start.sample $PGDATA/pgpool_remote_start"
</programlisting>
<para>
Basically, it should work if you change <emphasis>PGHOME</emphasis> according to PostgreSQL installation directory.
</para>
<programlisting>
-[server1]# vi /var/lib/pgsql/16/data/recovery_1st_stage
+[root@server1 ~]# vi /var/lib/pgsql/17/data/recovery_1st_stage
...
-PGHOME=/usr/pgsql-16
+PGHOME=/usr/pgsql-17
...
-[server1]# vi /var/lib/pgsql/16/data/pgpool_remote_start
+[root@server1 ~]# vi /var/lib/pgsql/17/data/pgpool_remote_start
...
-PGHOME=/usr/pgsql-16
+PGHOME=/usr/pgsql-17
...
</programlisting>
<literal>server1</literal>.
</para>
<programlisting>
-[server1]# su - postgres
-[server1]$ psql template1 -c "CREATE EXTENSION pgpool_recovery"
+[root@server1 ~]# psql -U postgres template1 -c "CREATE EXTENSION pgpool_recovery"
</programlisting>
<note>
<para>
is in the same subnet.
</para>
<programlisting>
+[root@server1 ~]# vi /etc/pgpool-II/pool_hba.conf
+(Add the following entries)
host all pgpool samenet scram-sha-256
host all postgres samenet scram-sha-256
</programlisting>
(the user Pgpool-II is running as. <productname>Pgpool-II</productname> 4.0 or before,
<productname>Pgpool-II</productname> is running as <literal>root</literal> by default)
<programlisting>
-[all servers]# su - postgres
-[all servers]$ echo 'some string' > ~/.pgpoolkey
-[all servers]$ chmod 600 ~/.pgpoolkey
+[root@server1 ~]# su - postgres -c "echo 'some string' > ~/.pgpoolkey"
+[root@server1 ~]# su - postgres -c "chmod 600 ~/.pgpoolkey"
+[root@server1 ~]# su - postgres -c "scp -i ~/.ssh/id_rsa_pgpool -p ~/.pgpoolkey postgres@server2:"
+[root@server1 ~]# su - postgres -c "scp -i ~/.ssh/id_rsa_pgpool -p ~/.pgpoolkey postgres@server3:"
</programlisting>
</para>
<para>
<filename>pgpool.conf</filename>.
</para>
<programlisting>
-[all servers]# su - postgres
-[all servers]$ pg_enc -m -k ~/.pgpoolkey -u pgpool -p
-db password: [pgpool user's password]
-[all servers]$ pg_enc -m -k ~/.pgpoolkey -u postgres -p
-db password: [postgres user's password]
+[root@server1 ~]# pg_enc -m -k /var/lib/pgsql/.pgpoolkey -u pgpool -p
+db password: (Enter the password for pgpool user)
+trying to read key from file /var/lib/pgsql/.pgpoolkey
-# cat /etc/pgpool-II/pool_passwd
+[root@server1 ~]# pg_enc -m -k /var/lib/pgsql/.pgpoolkey -u postgres -p
+db password: (Enter the password for postgres user)
+trying to read key from file /var/lib/pgsql/.pgpoolkey
+
+[root@server1 ~]# cat /etc/pgpool-II/pool_passwd
pgpool:AESheq2ZMZjynddMWk5sKP/Rw==
postgres:AESHs/pWL5rtXy2IwuzroHfqg==
</programlisting>
</programlisting>
<para>
- To bring up/down the virtual IP and send the ARP requests, we set <xref linkend="GUC-IF-UP-CMD">, <xref linkend="GUC-IF-DOWN-CMD"> and <xref linkend="GUC-ARPING-CMD">.
- The network interface used in this example is "enp0s8".
+ To bring up/down the virtual IP and send the ARP requests,
+ we set <xref linkend="GUC-IF-UP-CMD">, <xref linkend="GUC-IF-DOWN-CMD"> and <xref linkend="GUC-ARPING-CMD">.
+ Set the netmask and network interface name according to your network environment.
+ The network interface used in this example is <literal>enp0s8</literal>.
Since root privilege is required to execute <varname>if_up/down_cmd</varname> or
<varname>arping_cmd</varname> command, use setuid on these command or allow
<literal>postgres</literal> user (the user Pgpool-II is running as) to run
wd_escalation_command = '/etc/pgpool-II/escalation.sh'
</programlisting>
<para>
- The sample script <ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/escalation.sh.sample;hb=refs/heads/V4_5_STABLE">escalation.sh</ulink> is installed in <filename>/etc/pgpool-II/</filename>.
+ The sample script <ulink url="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob_plain;f=src/sample/scripts/escalation.sh.sample;hb=refs/heads/V4_6_STABLE">escalation.sh</ulink> is installed in <filename>/etc/pgpool-II/</filename>.
</para>
<programlisting>
-[all servers]# cp -p /etc/pgpool-II/sample_scripts/escalation.sh.sample /etc/pgpool-II/escalation.sh
-[all servers]# chown postgres:postgres /etc/pgpool-II/escalation.sh
+[root@server1 ~]# cp -p /etc/pgpool-II/sample_scripts/escalation.sh.sample /etc/pgpool-II/escalation.sh
+[root@server1 ~]# chown postgres:postgres /etc/pgpool-II/escalation.sh
</programlisting>
<para>
DEVICE is the network interface for the virtual IP.
</para>
<programlisting>
-[all servers]# vi /etc/pgpool-II/escalation.sh
+[root@server1 ~]# vi /etc/pgpool-II/escalation.sh
...
PGPOOLS=(server1 server2 server3)
VIP=192.168.100.50
DEVICE=enp0s8
+CIDR_NETMASK=24
...
</programlisting>
<sect3 id="example-cluster-pgpool-config-log">
<title>Logging</title>
<para>
- Since Pgpool-II 4.2, the logging collector process has been implemented.
- In the example, we enable logging collector.
+ Since <productname>Pgpool-II</productname> 4.2,
+ the logging collector process has been implemented.
+ When installed using the RPM packages, the logging
+ collector process (<xref linkend="guc-logging-collector">)
+ is enabled by default. Log files are output to
+ <filename>/var/log/pgpool_log</filename> by default.
+ Configure the logging related configuration parameters
+ as needed to meet your requirements.
</para>
<programlisting>
log_destination = 'stderr'
log_filename = 'pgpool-%a.log'
log_truncate_on_rotation = on
log_rotation_age = 1d
-log_rotation_size = 10MB
- </programlisting>
- <para>
- Create the log directory on all servers.
- </para>
- <programlisting>
-[all servers]# mkdir /var/log/pgpool_log/
-[all servers]# chown postgres:postgres /var/log/pgpool_log/
</programlisting>
<para>
- The configuration of <filename>pgpool.conf</filename> on server1 is completed.
- Copy the <filename>pgpool.conf</filename> to other
- <productname>Pgpool-II</productname> nodes (server2 and server3).
+ The configurations of Pgpool-II on <literal>server1</literal> are completed.
+ Finally, copy the configuration files to <literal>server2</literal>
+ and <literal>server3</literal>.
</para>
<programlisting>
-[server1]# scp -p /etc/pgpool-II/pgpool.conf root@server2:/etc/pgpool-II/pgpool.conf
-[server1]# scp -p /etc/pgpool-II/pgpool.conf root@server3:/etc/pgpool-II/pgpool.conf
+[root@server1 ~]# scp -p /etc/pgpool-II/{*.conf,*.sh,pool_passwd} server2:/etc/pgpool-II/
+[root@server1 ~]# ssh server2 "chown postgres:postgres /etc/pgpool-II/{*.conf,*.sh,pool_passwd}"
+[root@server1 ~]# scp -p /etc/pgpool-II/{*.conf,*.sh,pool_passwd} server3:/etc/pgpool-II/
+[root@server1 ~]# ssh server3 "chown postgres:postgres /etc/pgpool-II/{*.conf,*.sh,pool_passwd}"
</programlisting>
</sect3>
</sect2>
using the following command.
</para>
<programlisting>
-[server1]# su - postgres
-[server1]$ /usr/pgsql-16/bin/pg_ctl start -D $PGDATA
+[root@server1 ~]# su - postgres -c "/usr/pgsql-17/bin/pg_ctl start"
</programlisting>
<para>
Start <productname>Pgpool-II</productname> on <literal>server1</literal>,
<productname>Pgpool-II</productname> service.
</para>
<programlisting>
-[server1]# systemctl stop pgpool.service
+[root@server1 ~]# systemctl stop pgpool.service
-[server1]# pcp_watchdog_info -p 9898 -h 192.168.100.50 -U pgpool -W
+[root@server1 ~]# pcp_watchdog_info -p 9898 -h 192.168.100.50 -U pgpool -W
Password:
3 3 YES server2:9999 Linux server2 server2
as a <literal>STANDBY</literal>.
</para>
<programlisting>
-[server1]# systemctl start pgpool.service
+[root@server1 ~]# systemctl start pgpool.service
-[server1]# pcp_watchdog_info -p 9898 -h 192.168.100.50 -U pgpool -W
+[root@server1 ~]# pcp_watchdog_info -p 9898 -h 192.168.100.50 -U pgpool -W
Password:
3 3 YES server2:9999 Linux server2 server2
and verify the backend information.
</para>
<programlisting>
-# psql -h 192.168.100.50 -p 9999 -U pgpool postgres -c "show pool_nodes"
+[any server]# psql -h 192.168.100.50 -p 9999 -U pgpool postgres -c "show pool_nodes"
Password for user pgpool:
node_id | hostname | port | status | pg_status | lb_weight | role | pg_role | select_cnt | load_balance_node | replication_delay | replication_state | replication_sync_state | last_status_change
---------+----------+------+--------+-----------+-----------+---------+---------+------------+-------------------+-------------------+-------------------+------------------------+---------------------
automatically.
</para>
<programlisting>
-[server1]$ pg_ctl -D /var/lib/pgsql/16/data -m immediate stop
+[root@server1 ~]# su - postgres -c "/usr/pgsql-17/bin/pg_ctl -m immediate stop"
</programlisting>
<para>
After stopping <productname>PostgreSQL</productname> on
</para>
<programlisting>
-[server3]# psql -h server3 -p 5432 -U pgpool postgres -c "select pg_is_in_recovery()"
+[any server]# psql -h server3 -p 5432 -U pgpool postgres -c "select pg_is_in_recovery()"
pg_is_in_recovery
-------------------
t
-[server2]# psql -h server2 -p 5432 -U pgpool postgres -c "select pg_is_in_recovery()"
+[any server]# psql -h server2 -p 5432 -U pgpool postgres -c "select pg_is_in_recovery()"
pg_is_in_recovery
-------------------
f
-[server2]# psql -h server2 -p 5432 -U pgpool postgres -c "select * from pg_stat_replication" -x
+[any server]# psql -h server2 -p 5432 -U pgpool postgres -c "select * from pg_stat_replication" -x
-[ RECORD 1 ]----+------------------------------
pid | 7198
usesysid | 16385