- Installation
- Create PostgreSQL Cluster
- Connect to a PostgreSQL Cluster
- psql
- pgAdmin
- Updating PostgreSQL Cluster
- High Availability
Objectives
- Set up two Compute Engine instances running Postgres.
- Create a new table for a guestbook app.
- Configure the primary server.
- Back up the primary server to the standby server.
- Configure the standby server to run in Hot Standby mode.
- Start the standby server and test it.
Creating the guestbook table on Primary Server
Create cluster
gcloud container clusters create "gke-px" \
--zone "asia-southeast1-a" \
--cluster-version "1.20.8-gke.900" \
--machine-type "n1-standard-4" \
--image-type "UBUNTU" \
--disk-type "pd-ssd" \
--disk-size "100" \
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import asyncio | |
| import psycopg2 | |
| # dbname should be the same for the notifying process | |
| conn = psycopg2.connect(host="localhost", dbname="example", user="example", password="example") | |
| conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) | |
| cursor = conn.cursor() | |
| cursor.execute(f"LISTEN match_updates;") |