Using PGD CLI
=============

PGD
CLIは、PGDクラスターを管理するための強力なコマンドラインインターフェイスです。次のようなさまざまなタスクを実行するために使用できます。

- クラスターの状態の確認

- クラスター内のノードのリスト

- クラスター内のグループのリスト

- グループオプションの設定

- ライトリーダーの切り替え

:ref:`installation guide <install>` を使用してPGDをインストールした場合、既にPGD
CLIをインストールし、それを使用してクラスターを作成しています。

PGD CLIを使用する
-----------------

PGD
CLIコマンドは、構成ファイルを使用して、接続するホストを判断します。これをオーバーライドして代替構成ファイルを使用したり、サーバーを明示的にポイントしたりできる `options <https://www.enterprisedb.com/docs/pgd/latest/reference/cli/using_cli>`_ があります。ただし、デフォルトでは、
PGD CLIはプリセットの場所で構成ファイルを検索します。

データベースへの接続は、
psqlコマンドのような他のコマンドラインユーティリティが認証されるのと同じ方法で認証されます。

他のコマンドとは異なり、 PGD
CLIは対話型でパスワードの入力を求めません。したがって、次のいずれかの方法を使用してパスワードを渡す必要があります。

- ホスト、ポート、データベース名、ユーザー名、パスワードを含むエントリを :ref:`.pgpass <Monitoring through SQL>` に追加する

- ``PGPASSWORD`` 環境変数にパスワードを設定する

- 接続文字列にパスワードを含める

他のオプションはマルチプルのデータベースクラスターでうまく拡張できないか、パスワードの機密性が危険にさらされるため、最初のオプションをお勧めします。

PGD CLIの構成と接続
^^^^^^^^^^^^^^^^^^^

- PGD CLIがインストールされていることを確認します。

- PGD CLIが既にインストールされている場合は、次のステップに移動します。

- システムの場合、そのシステムで :ref:`Step 2 - Configure repositories <Step 2 - Configure repositories>` ステップを繰り返します。

- 次に、そのプラットフォームに適切なパッケージインストールコマンドを実行します。

- RHELおよび派生製品\ ``sudo dnf install edb-pgd6-cli``

- Debian、Ubuntu、およびデリバティブ
  ``sudo apt-get install edb-pgd6-cli``

- 構成ファイルを作成します。 - これは、使用するPGD
  CLIのクラスターとエンドポイントを指定するYAMLファイルです。

- 構成ファイルのインストール.

- YAML構成ファイルをデフォルトの構成ディレクトリ\ ``/etc/edb/pgd-cli/``
  に\ ``pgd-cli-config.yml`` .

- としてコピーします PGD
  CLIを実行するシステムでこのプロセスを繰り返します。

- pgd-cliを実行します。

PGD CLIを使用してクラスターを探索する
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- ``cluster show --health`` コマンドでクラスターの状態を確認します。

- ``nodes list`` コマンドを使用して、クラスター内のノードを表示します。

- ``groups list`` コマンドでクラスター内のグループを表示する

- ``group set-option`` コマンドでグループオプションを設定します。

- ``group set-leader`` コマンドで書き込みリーダーを切り替えます。

これらのコマンドの詳細については、次の実際の例を参照してください。

また、他の構成オプションと完全なコマンドリファレンスの詳細については、
`PGD CLI documentation <https://www.enterprisedb.com/docs/pgd/latest/reference/cli/>`_ を参照してください。

実際の例
--------

PGD CLIがインストールされていることを確認します
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

この実際の例では、PostgresとPGDが既にインストールされているホスト1でPGD
CLIを構成して使用します。 PGD
CLIを再度インストールする必要はありません。

オプションで構成ファイルを作成します
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

PGD
CLI構成ファイルは、クラスターオブジェクトを含むYAMLファイルです。これには2つのプロパティがあります。

- PGDクラスターのトップレベルグループの名前\ ``name`` として

- データベースのエンドポイントの配列\ ``endpoints`` として

::

   cluster:
     name: pgd
     endpoints:
       - host=host-1 dbname=pgddb port=5444
       - host=host-2 dbname=pgddb port=5444
       - host=host-3 dbname=pgddb port=5444

この例のエンドポイントは\ ``port=5444``
を指定していることに注意してください。これはEDB Postgres Advanced
Serverインスタンスに必要です。 EDB Postgres
ExtendedおよびコミュニティPostgreSQLの場合、これを省略できます。

PGD CLI構成ディレクトリを作成します。

.. code:: shell

   sudo mkdir -p /etc/edb/pgd-cli

次に、構成を\ ``/etc/edb/pgd-cli``
ディレクトリの\ ``pgd-cli-config.yml`` ファイルに書き込みます。

この例では、host-1でこれを実行してファイルを作成できます。

.. code:: shell

   cat <<EOF | sudo tee /etc/edb/pgd-cli/pgd-cli-config.yml
   cluster:
     name: pgd
     endpoints:
       - host=host-1 dbname=pgddb port=5444
       - host=host-2 dbname=pgddb port=5444
       - host=host-3 dbname=pgddb port=5444
   EOF

PGD
CLIを使用する必要があるシステムでこのプロセスを繰り返すことができます。

PGD CLIの実行
^^^^^^^^^^^^^

構成ファイルを配置し、enterprisedb
systemユーザーとしてログインすると、pgd-cliを実行できます。たとえば、
``nodes list``
コマンドを使用して、クラスター内のノードとそのステータスをリストできます。

.. code:: shell

   pgd nodes list
   __OUTPUT__
   Node Name Group Name   Node Kind Join State Node Status
   - --------  ----------- --------- ---------- -----------
   node-1     group-1         data      ACTIVE     Up
   node-2     group-1         data      ACTIVE     Up
   node-3     group-1         data      ACTIVE     Up

.. _pgd-cliを使用してクラスターを探索する-1:

PGD CLIを使用してクラスターを探索する
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

PGD
CLIが構成されたら、それを使用して、クラスターのPGDレベルのビューを取得できます。

クラスターの状態を確認する
^^^^^^^^^^^^^^^^^^^^^^^^^^

:ref:`cluster show --health <pgd cluster show>` コマンドは、クラスターの状態を表示する簡単な方法を提供します。

.. code:: shell

   pgd cluster show --health
   __OUTPUT__
   Check             Status Details
   - ---------------- ------ -----------------------------------------------
   Connections       Ok     All BDR nodes are accessible
   Raft              Ok     Raft Consensus is working correctly
   Replication Slots Ok     All PGD replication slots are working correctly
   Clock Skew        Ok     Clock drift is within permissible limit
   Versions          Ok     All nodes are running the same PGD version

クラスター内のノードを表示する
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

前述のように、
`nodes list <https://www.enterprisedb.com/docs/pgd/latest/reference/cli/command_ref/nodes/list/>`_ コマンドはクラスター内のノードをリストします。

.. code:: shell

   pgd nodes list
   __OUTPUT__
   Node Name  Group Name  Node Kind Join State Node Status
   - --------- ----------- --------- ---------- -----------
   node-1     group-1         data      ACTIVE     Up
   node-2     group-1         data      ACTIVE     Up
   node-3     group-1         data      ACTIVE     Up

このビューには、ノードがメンバーであるグループとその現在のステータスが表示されます。ノードで実行されているPGDおよびPostgresのバージョンを確認するには、
``nodes list --versions`` を使用します。

.. code:: shell

   pgd nodes list --versions
   __OUTPUT__
   Node Name  BDR Version                  Postgres Version
   - --------- ---------------------------  --------------------------------
   node-1     5.7.0 (snapshot e2534db6d)   16.6 (Debian 16.6-1EDB.bullseye)
   node-2     5.7.0 (snapshot e2534db6d)   16.6 (Debian 16.6-1EDB.bullseye)
   node-3     5.7.0 (snapshot e2534db6d)   16.6 (Debian 16.6-1EDB.bullseye)

クラスター内のグループを表示する
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

最後に、 PGD
CLIの `groups list <https://www.enterprisedb.com/docs/pgd/latest/reference/cli/command_ref/groups/list/>`_ コマンドは、構成されているグループなどを表示します。

::

   pgd groups list
   __OUTPUT__
   Group Name   Parent Group Name Group Type Nodes
   - ----------- ----------------- ---------- -----
   pgd                            global     0
   group-1      pgd               data       3

このコマンドは次を示します。

- グループ

- そのタイプ

- その親グループ

- 各グループのノード数

グループオプションを設定する
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

`group set-option <https://www.enterprisedb.com/docs/pgd/latest/reference/cli/command_ref/group/set-option/>`_ コマンドを使用して、PGD
CLIを使用してグループオプションを設定することもできます。 ``group-1``
グループの場所を\ ``London`` に設定する場合は、次を実行します。

.. code:: shell

   pgd group group-1 set-option location London
   __OUTPUT__
   Status Message
   - ----- -----------------------------
   OK     Command executed successfully

`group get-option <https://www.enterprisedb.com/docs/pgd/latest/reference/cli/command_ref/group/get-option/>`_ コマンドを使用して、新しい場所を確認できます。

.. code:: shell

   pgd group group-1 get-option location
   __OUTPUT__
   Option Name Option Value
   - ---------- ------------
   location    London

書き込みリーダーを設定する
^^^^^^^^^^^^^^^^^^^^^^^^^^

グループ内の書き込みリーダーを変更して、ホストのメンテナンスを有効にする必要がある場合、
PGD CLIは `group set-leader <https://www.enterprisedb.com/docs/pgd/latest/reference/cli/command_ref/group/set-leader/>`_ コマンドを提供します。 ``group``
の後にグループ名を入力し、\ ``set leader``
の後にスイッチするノードの名前を入力します。

.. code:: shell

   pgd group group-1 set-leader node-2
   __OUTPUT__
   Status Message
   - ----- -----------------------------
   OK     Command executed successfully

``--summary option``
で :ref:`group show command <pgd cluster show>` を使用して、書き込みリーダーを検証できます。

.. code:: shell

   pgd group group-1 show --summary
   __OUTPUT__
   Group Property    Value
   - ---------------- ------------
   Group Name        group-1
   Parent Group Name pgd
   Group Type        data
   Write Leader      node-2
   Commit Scope

PGD CLIで使用可能なコマンドの詳細については、
`PGD CLI command reference <https://www.enterprisedb.com/docs/pgd/latest/reference/cli/command_ref/>`_ を参照してください。

PGD エッセンシャルコンストレイン
--------------------------------

クラスターアーキテクチャの検証
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

クラスターが以下にリストされているPGD Essential制約を満たさない場合、
``pgd cluster verify`` コマンドは\ ``Warning`` を表示します。

- PGD Essentialクラスターには、最大3つのデータノードが必要です。

- PGD
  Essentialクラスターでは、グローバルグループのみにルーティングを有効にする必要があります。

.. code:: shell

   pgd cluster verify --arch
   __OUTPUT__
    Check                       | Status  | Groups
   - ----------------------------+---------+--------
    Cluster has data nodes      | Ok      |
    Max data nodes in a cluster | Warning | dc-1
    Witness nodes per group     | Ok      |
    Witness-only groups         | Ok      |
    Data nodes per group        | Ok      |
    Routing enabled groups      | Warning | dc-1
    Empty groups                | Ok      |
    Nodes have node kind set    | Ok      |

PGD互換性評価
^^^^^^^^^^^^^

``pgd assess`` コマンドは、 PGD
Essentialの互換性についてPostgresサーバーの以下にリストされている評価を実行しません。

- 複数の一意のインデックスを持つテーブル

- 行レベルのロックの使用

- ロックテーブルの使用法

- リッスン通知の使用法

PGD Essentialクラスターのコマンド出力は以下のようになります。

.. code:: shell

   pgd assess --dsn "host=pgd-a2 port=5432 dbname=pgddb user=postgres "
   __OUTPUT__
    Assessment                   | Result                     | Details
   - -----------------------------+----------------------------+-------------------------------------------------------
    Multiple Databases           | Compatible                 | Found only one user database
    Materialized Views           | Compatible                 | No materialized views found
    EPAS Queue Tables            | Compatible                 | No EPAS Queue Tables found
    DDL Command Usage            | Requires workload analysis | Cannot be checked automatically at this time
    Advisory Lock Usage          | Potentially compatible     | No advisory lock commands found in pg_stat_statements
    Large Objects                | Compatible                 | No large objects found
    Trigger/Reference Privileges | Compatible                 | No triggers with incompatible privileges found

コミットスコープ管理コマンド
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

``pgd commit-scope create`` 、\ ``pgd commit-scope update``
、および\ ``pgd commit-scope drop`` コマンドは、PGD
Essentialクラスターではサポートされていません。コマンドは次のアドバイスを表示して終了します。

.. code:: shell

   Operation not supported for PGD Essential version.
   HINT: This limit doesnt exist in the PGD Expanded version

.. _グループオプションを設定する-1:

グループオプションを設定する
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

``pgd group set-option`` コマンドでは、 PGD
Essentialクラスターのグループオプション\ ``enable_raft``
、\ ``enable_routing`` 、\ ``enable_wal_decoder``
、および\ ``streaming_mode``
の更新はできません。コマンドは以下のアドバイスで終了します。

.. code:: shell

   Operation not supported for PGD Essential version.
   HINT: This limit doesnt exist in the PGD Expanded version

PGDノードのセットアップ
^^^^^^^^^^^^^^^^^^^^^^^

``pgd node setup`` コマンドは、\ ``global``
グループのルーティングを有効にし、\ ``subgroup(s)``
で同じを無効にします。
