Note:

Deploy a PostgreSQL Cluster on Oracle Cloud Infrastructure Compute Instances

Introduction

PostgreSQL is an open source object-relational database management system. It is highly extensible, highly scalable, and has many features. PostgreSQL supports data replication across multiple data centers.

This tutorial shows a typical three-node deployment of a PostgreSQL cluster on Oracle Cloud Infrastructure (OCI) Compute instances. In this tutorial, the servers are configured in master and standby configuration and use streaming replication.

You can find the automation instructions here: terraform-oci-arch-postgresql.

Note: It will automatically install postgis34 and pgvector.

Architecture Diagram

PostgreSQL Cluster Architecture

Objectives

Prerequisites

Task 1: Deploy the Terraform Code using OCI Resource Manager

The deployment can be done in two ways, using terraform Command Line Interface (CLI), or OCI Resource Manager. In this tutorial, we will be using OCI Resource Manager.

For terraform CLI, see the repository documentation here: terraform-oci-arch-postgresql.

  1. Click the following image to start the OCI Resource Manager process that will deploy the resources.

    Clink on image to deploy using Resource Manager.

  2. If you are not already signed in, enter the tenancy and user credentials, review and accept the terms and conditions, select region, compartment where you want the stack to reside and click Next that will take you to the next step to Configure variables.

  3. In Configure variables, enter the following information to configure the variables.

    • Compartment: Select the compartment in which you want to deploy the resources.
    • Availability Domain for master PostgreSQL: Select the availability domain for the master compute instance.
    • PostgreSQL Version: You can select versions 9.6, 10, 11, 12 or 13.
    • PostgreSQL Password: Set a Password to access PostgreSQL.
    • Deploy first PostgreSQL HotStandby: Select if you want to deploy the first standby.
    • Deploy second PostgreSQL HotStandby: Select if you want to deploy the second standby.
    • Create in Private Subnet: Select if you want the instances to be created in a private subnet.

    Note:

    • Deploying the first and second PostgreSQL HotStandby allows you to deploy one, two, or three nodes.
    • If you select to create in a private subnet, an OCI Bastion service will be created to allow access.
  4. Click Show advanced options to enter additional configurable variables information.

    • Network Optional Configuration: This allows you to specify the VCN and subnet CIDRs and whether or not to create a Dynamic Routing Gateway (DRG).
    • Compute, Storage & Backup Optional Configuration: This allows you to add a public SSH key to access the PostgreSQL instances and configure backups.
    • PostgreSQL Master Optional Configuration: Specify PostgreSQL master instance fault domain, shape, CPU and memory for flex shapes.
    • PostgreSQL HotStandby1 Optional Configuration: Specify PostgreSQL first standby instance availability domain, fault domain, shape, CPU and memory for flex shapes.
    • PostgreSQL HotStandby2 Optional Configuration: Specify PostgreSQL second standby instance availability domain, fault domain, shape, CPU and memory for flex shapes.
  5. Click Next to review the information.

    Note:

    • Deselect Run apply if you want to run a plan first.
    • If you select Run apply, it will trigger the terraform apply command and it will automatically start provisioning the resources.
  6. Click Create.

Task 2: Destroy the Deployment

To destroy your resources, simply go to the Stack Details page and click Destroy.

Understand how PostgreSQL is Installed and Configured

This information is useful if you need to modify the way PostgreSQL works.

It will help you understand:

Note: This will not cover how to customize the automation. Depending on the changes, it might require modifications in multiple terraform files.

Acknowledgments

More Learning Resources

Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.

For product documentation, visit Oracle Help Center.