Step 8 - Using PGD CLI v5.6
Using PGD CLI
The PGD CLI command uses a configuration file to work out the hosts to connect to. There are options that allow you to override this to use alternative configuration files or explicitly point at a server. But, by default, PGD CLI looks for a configuration file in preset locations.
The connection to the database is authenticated in the same way as other command line utilities, like the psql command, are authenticated.
Unlike other commands, PGD CLI doesn't interactively prompt for your password. Therefore, you must pass your password using one of the following methods:
- Adding an entry to your
.pgpass
password file, which includes the host, port, database name, user name, and password - Setting the password in the
PGPASSWORD
environment variable - Including the password in the connection string
We recommend the first option, as the other options don't scale well with multiple database clusters, or they compromise password confidentiality.
Configuring and connecting PGD CLI
- Ensure PGD CLI is installed.
- If PGD CLI was already installed, move to the next step.
- For any system, repeat the configure repositories step on that system.
- Then run the package installation command appropriate for that platform.
- RHEL and derivatives:
sudo dnf install edb-pgd5-cli
- Debian, Ubuntu, and derivatives:
sudo apt-get install edb-pgd5-cli
- RHEL and derivatives:
- Create a configuration file.
- This is a YAML file that specifies the cluster and endpoints for PGD CLI to use.
- Install the configuration file.
- Copy the YAML configuration file to a default config directory
/etc/edb/pgd-cli/
aspgd-cli-config.yml
. - Repeat this process on any system where you want to run PGD CLI.
- Copy the YAML configuration file to a default config directory
- Run pgd-cli.
Use PGD CLI to explore the cluster
- Check the health of the cluster with the
check-health
command. - Show the nodes in the cluster with the
show-nodes
command. - Show the proxies in the cluster with the
show-proxies
command. - Show the groups in the cluster with the
show-groups
command. - Set a group option with the
set-group-options
command. - Switch write leader with the
switchover
command.
For more details about these commands, see the worked example that follows.
Also consult the PGD CLI documentation for details of other configuration options and a full command reference.
Worked example
Ensure PGD CLI is installed
In this worked example, you configure and use PGD CLI on host-one, where you've already installed Postgres and PGD. You don't need to install PGD CLI again.
Create a configuration file
The PGD CLI configuration file is similar to the PGD Proxy configuration file. It's a YAML file that contains a cluster object. This has two properties:
- The name of the PGD cluster's top-level group (as
name
) - An array of endpoints of databases (as
endpoints
)
Note that the endpoints in this example specify port=5444
.
This is necessary for EDB Postgres Advanced Server instances.
For EDB Postgres Extended and community PostgreSQL, you can omit this.
Install the configuration file
Create the PGD CLI configuration directory: