Step 7 - Using PGD CLI v4
Using PGD CLI
The PGD CLI client uses a configuration file to work out which 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 is 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-pgd-cli
- Debian, Ubuntu, and derivatives:
sudo apt-get install edb-pgd-cli
- RHEL and derivatives:
- Create a configuration file.
- YAML file that specifies the cluster and endpoints for the PGD CLI application to use.
- Install the configuration file.
- Copy the YAML configuration file to a default config directory
/etc/edb/
aspgd-config.yml
. - Repeat this step on any system where you want to run PGD CLI.
- Copy the YAML configuration file to a default config directory
- Add
/usr/local/bin/
to the PATH for any user wanting to use PGD CLI.- Add
/usr/local/bin
to the path in your.bashrc
file
- Add
- Run pgd-cli with the
pgd
command.
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.
More details of these command are shown in 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
This worked example configures and uses PGD CLI on host-one
, where Postgres and PGD are already installed.
You don't need to install PGD CLI again. The example uses the enterprisedb
account as this is already configured for access to Postgres.
If you aren't logged in as enterprisedb
switch to it:
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, this can be set to port=5432
.
Install the configuration file
Create the PGD CLI configuration directory:
Then, write the configuration to the pgd-config.yml
file in the /etc/edb/
directory.
For this example, this can be run on host-one
to create the file:
This process can be repeated on any system where you need to use PGD CLI.
Add /usr/local/bin
to the Path
To add the directory where the pgd
command is installed to your path, run:
For users other than enteprisedb, add this line to your .bashrc
file to always have pgd
available.
For the enterprisedb user, add the line to /var/lib/ebd/.enterprisedb_profile
.
Run PGD CLI
With the configuration file in place, and logged is as the enterprisedb system user, you can run pgd-cli.
For example, you can use the show-nodes
command to list the nodes in your cluster and their status. For example:
Using PGD CLI to explore the cluster
Once it's configured, you can use PGD CLI to get PGD-level views of the cluster.
Check the health of the cluster
The check-health
command provides a quick way to view the health of the cluster:
Show the nodes in the cluster
As previously seen, the show-nodes
command lists the nodes in the cluster:
This view shows which group the node is a member of and its current status.
To find out what versions of PGD and Postgres are running on the nodes, use show-version
:
- On this page
- Using PGD CLI
- Worked example