{"id":43485523,"url":"https://github.com/syaeful16/postgresql-replication-docker","last_synced_at":"2026-02-03T09:08:55.175Z","repository":{"id":310459425,"uuid":"1039926154","full_name":"syaeful16/postgresql-replication-docker","owner":"syaeful16","description":"Playground for testing PostgreSQL replication, HAProxy load balancing, and Patroni failover.","archived":false,"fork":false,"pushed_at":"2025-08-18T07:40:15.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-18T09:28:30.555Z","etag":null,"topics":["haproxy-docker","postgresql","slave"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/syaeful16.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-18T07:37:59.000Z","updated_at":"2025-08-18T07:42:27.000Z","dependencies_parsed_at":"2025-08-18T09:28:36.523Z","dependency_job_id":"33c8f414-10ef-4d18-9876-eddd5a27097f","html_url":"https://github.com/syaeful16/postgresql-replication-docker","commit_stats":null,"previous_names":["syaeful16/postgresql-replication-docker"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/syaeful16/postgresql-replication-docker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syaeful16%2Fpostgresql-replication-docker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syaeful16%2Fpostgresql-replication-docker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syaeful16%2Fpostgresql-replication-docker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syaeful16%2Fpostgresql-replication-docker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syaeful16","download_url":"https://codeload.github.com/syaeful16/postgresql-replication-docker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syaeful16%2Fpostgresql-replication-docker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29039342,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-03T08:41:49.363Z","status":"ssl_error","status_checked_at":"2026-02-03T08:40:19.255Z","response_time":96,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["haproxy-docker","postgresql","slave"],"created_at":"2026-02-03T09:08:51.514Z","updated_at":"2026-02-03T09:08:55.169Z","avatar_url":"https://github.com/syaeful16.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# PostgreSQL Replication \u0026 HA — Docker Examples\n# Easy Testing\n\nTiga setup:\n\n1. `pg-replication-basic/` → Primary + Replica (belajar/testing, failover manual)\n2. `pg-cluster-haproxy/` → Primary + Replica + HAProxy (1 endpoint, failover manual)\n3. `pg-ha/` → Patroni + etcd + HAProxy (auto-failover, read/write split)\n\n---\n\n## Cara Jalankan\n\n### 1) Basic\n\n```bash\ncd pg-replication-basic\ndocker compose up -d\n\n# Test insert ke primary\ndocker exec -it pg_primary psql -U postgres -d mydb -c \"INSERT INTO test_table(name) VALUES ('hello');\"\n\n# Cek data di replica\ndocker exec -it pg_replica psql -U postgres -d mydb -c \"TABLE test_table;\"\n```\n\n---\n\n### 2) Cluster + HAProxy\n\n```bash\ncd pg-cluster-haproxy\ndocker compose up -d\n\n# Insert lewat HAProxy (port 5000)\nPGPASSWORD=postgres psql -h localhost -p 5000 -U postgres -d mydb -c \"INSERT INTO test_table(name) VALUES ('from haproxy');\"\n\n# Cek data di replica langsung\ndocker exec -it pg_replica1 psql -U postgres -d mydb -c \"TABLE test_table;\"\n```\n\n\u003e Failover manual: promote replica jika primary mati\n\n```bash\ndocker exec -it pg_replica1 psql -U postgres -d mydb -c \"SELECT pg_promote();\"\n```\n\n---\n\n### 3) HA dengan Patroni\n\n```bash\ncd pg-ha\ndocker compose up -d\n\n# Insert ke leader via HAProxy (port 5000 = write)\nPGPASSWORD=postgres psql -h localhost -p 5000 -U postgres -d postgres -c \"INSERT INTO test_table(name) VALUES ('from patroni leader');\"\n\n# Baca dari replica (port 5001 = read pool)\nPGPASSWORD=postgres psql -h localhost -p 5001 -U postgres -d postgres -c \"TABLE test_table;\"\n```\n\n\u003e Test failover otomatis: stop leader\n\n```bash\ndocker stop patroni1\n```\n\nPatroni otomatis promote node lain → HAProxy tetap arahkan backend ke leader baru di port `5000`.\n\n---\n\n## Endpoint\n\n- **Basic**\n\n  - Primary → `localhost:5432`\n  - Replica → `localhost:5433`\n\n- **Cluster HAProxy**\n\n  - Write → `localhost:5000`\n\n- **Patroni HA**\n\n  - Write (leader) → `localhost:5000`\n  - Read (replica pool) → `localhost:5001`\n  - HAProxy stats → [http://localhost:8404](http://localhost:8404)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyaeful16%2Fpostgresql-replication-docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyaeful16%2Fpostgresql-replication-docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyaeful16%2Fpostgresql-replication-docker/lists"}