Creating your first cluster v6.5.0

Create a local cluster using Docker Compose to get familiar with the EDB Postgres Distributed (PGD) features and functionality.

Prerequisites

  • Docker and Docker Compose installed on your local machine.

Install the PGD Docker Quickstart kit

To create your first PGD cluster, use the Docker Compose file provided by EDB to set up a local cluster with three nodes.

  1. Make sure you have Docker and Docker Compose installed on your local machine. You can follow the Docker installation guide if you haven't done so already.

  2. Open a terminal and on the machine where you have docker installed, create a new directory for your PGD cluster, for example:

    mkdir pgd-cluster
    cd pgd-cluster
  3. Download the PGD Docker Compose file:

     curl -L https://enterprisedb.com/docs/pgd/latest/quickstart/assets/pgd_quickstart.sh | bash

The command downloads the PGD Docker Quickstart kit, which includes the Docker Compose file and other necessary files to get started with PGD.

  1. Once the download is complete, prepare the environment for the PGD cluster.

    ./qs.sh prepare

    The command creates the necessary directories and files for the PGD cluster.

  2. Build the Docker images for the PGD cluster:

    export EDB_SUBSCRIPTION_TOKEN=...
    ./qs.sh build

    The command builds the Docker image needed for the PGD Quickstart cluster.

  3. After the images are built, start the PGD cluster :

    ./qs.sh start

    The command starts the Docker containers and creates a local cluster with the default configuration.

Accessing the PGD Cluster

  1. Once the containers are up and running, access the PGD cluster:

    docker compose exec host-1 psql pgddb

    The command connects to the first node of the cluster using the psql command-line interface.

    Connect to the database via the first node for maintenance and management tasks.

  2. For application and user access, you connect using Connection Manager which, by default, is running on TCP port 6432 of all the hosts in the cluster. Connect to the write leader node in the cluster using the following command:

    docker compose exec host-1 psql -h host-1 -p 6432 pgddb

    Replace -h host-1 with the name of any host in the cluster, as they all run Connection Manager.

    If you have the psql client installed on your local machine, you can also connect to the cluster using the following command:

    export PGPASSWORD=secret
    psql -h localhost -p 6432 -U postgres pgddb

    The command connects to the connection manager running on the host-3 container on port 6432. This is then routed to the write leader node in the cluster.

    select node_name from bdr.local_node_summary;
    Output
    node_name
    -----------
    node-1
    (1 row)
  3. To use the PGD CLI from outside the containers, run the following command:

    docker compose exec host-1 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

    The command lists the nodes in the cluster and their status.

  4. Alternatively, open a shell on the host-1 container and run the pgd command directly:

    docker compose exec host-1 bash
    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

    The command gives you access to the PGD CLI and allows you to run any PGD commands directly on the host-1 container.

Next Steps