Viewing PGD topology
====================

Listing PGD groups
------------------

Using :ref:`pgd-cli <../cli>` 
^^^^^^^^^^^^^^^^^^^

Use the :ref:`pgd-cli <../cli>`  ``show-groups`` command to list all groups in the
PGD cluster:

.. code:: shell

   pgd show-groups

.. code:: console

     Group    Group ID   Type            Parent Group Location Raft  Routing Write Leader
     -----    --------   ----            ------------ -------- ----  ------- ------------
     bdrgroup 1360502012 global                                true  false
     group_a  3618712053 data            bdrgroup     a        true  true    bdr-a1
     group_b  402614658  data            bdrgroup     b        true  true    bdr-b1
     group_c  2808307099 data            bdrgroup     c        false false
     group_so 2123208041 subscriber-only bdrgroup     c        false false

Using SQL
^^^^^^^^^

The following simple query lists all the PGD node groups of which the
current node is a member. It currently returns only one row from
 :ref:`bdr.local_node_summary <bdr.local_node_summary>`  .

.. code:: sql

   SELECT node_group_name
   FROM bdr.local_node_summary;

You can display the configuration of each node group using a more
complex query:

.. code:: sql

   SELECT g.node_group_name
   , ns.pub_repsets
   , ns.sub_repsets
   , g.node_group_default_repset     AS default_repset
   , node_group_check_constraints    AS check_constraints
   FROM bdr.local_node_summary ns
   JOIN bdr.node_group g USING (node_group_name);

Listing nodes in a PGD group
----------------------------

Using :ref:`pgd-cli <../cli>` 
^^^^^^^^^^^^^^^^^^^

Use the ``show-nodes`` command to list all nodes in the PGD cluster:

.. code:: shell

   pgd show-nodes

.. code:: console

     Node               Node ID    Group    Type            Current State Target State Status Seq ID
     ----               -------    -----    ----            ------------- ------------ ------ ------
     bdr-a1             3136956818 group_a  data            ACTIVE        ACTIVE       Up     6
     bdr-a2             2133699692 group_a  data            ACTIVE        ACTIVE       Up     3
     logical-standby-a1 1140256918 group_a  standby         STANDBY       STANDBY      Up     9
     witness-a          3889635963 group_a  witness         ACTIVE        ACTIVE       Up     7
     bdr-b1             2380210996 group_b  data            ACTIVE        ACTIVE       Up     1
     bdr-b2             2244996162 group_b  data            ACTIVE        ACTIVE       Up     2
     logical-standby-b1 3541792022 group_b  standby         STANDBY       STANDBY      Up     10
     witness-b          661050297  group_b  witness         ACTIVE        ACTIVE       Up     5
     witness-c          1954444188 group_c  witness         ACTIVE        ACTIVE       Up     4
     subscriber-only-c1 2448841809 group_so subscriber-only ACTIVE        ACTIVE       Up     8

Use ``grep`` with the group name to filter the list to a specific group:

.. code:: shell

   pgd show-nodes | grep group_b

.. code:: console

     bdr-b1             2380210996 group_b  data            ACTIVE        ACTIVE       Up     1
     bdr-b2             2244996162 group_b  data            ACTIVE        ACTIVE       Up     2
     logical-standby-b1 3541792022 group_b  standby         STANDBY       STANDBY      Up     10
     witness-b          661050297  group_b  witness         ACTIVE        ACTIVE       Up     5

.. _using-sql-1:

Using SQL
^^^^^^^^^

You can extract the list of all nodes in a given node group (such as
``mygroup`` ) from the :ref:`bdr.node_summary <bdr.node_summary>`  \` view. For example:

.. code:: sql

   SELECT node_name         AS name
   , node_seq_id            AS ord
   , peer_state_name        AS current_state
   , peer_target_state_name AS target_state
   , interface_connstr      AS dsn
   FROM bdr.node_summary
   WHERE node_group_name = mygroup;

The read-only state of a node, as shown in the ``current_state`` or in
the ``target_state`` query columns, is indicated as ``STANDBY`` .
