Skip to content

Instantly share code, notes, and snippets.

@akhdaniel
akhdaniel / PostgreSQL HA on Kubernetes.md
Last active January 23, 2024 07:57
PostgreSQL HA on Kubernetes

PostgreSQL High Availibility on Kubernetes

  • 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" \
@akhdaniel
akhdaniel / PostgreSQL Clustering CITUS.md
Last active December 26, 2024 14:11
PostgreSQL Clustering CITUS

Install Steps on Worker:

curl https://install.citusdata.com/community/deb.sh | sudo bash

sudo apt-get -y install postgresql-13-citus-10.0

sudo pg_conftool 13 main set shared_preload_libraries citus
@kissgyorgy
kissgyorgy / listen.py
Created September 4, 2020 16:37
How to use PostgreSQL's LISTEN/NOTIFY as a simple message queue with psycopg2 and asyncio
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;")