{"id":13625819,"url":"https://github.com/toluaina/pgsync","last_synced_at":"2026-01-04T15:16:15.705Z","repository":{"id":37690003,"uuid":"202871973","full_name":"toluaina/pgsync","owner":"toluaina","description":"Postgres to Elasticsearch/OpenSearch sync","archived":false,"fork":false,"pushed_at":"2025-03-12T16:07:21.000Z","size":1600,"stargazers_count":1277,"open_issues_count":197,"forks_count":196,"subscribers_count":20,"default_branch":"main","last_synced_at":"2025-05-11T00:42:40.066Z","etag":null,"topics":["change-data-capture","elasticsearch","elasticsearch-sync","etl","kibana","opensearch","postgresql","python","sql"],"latest_commit_sha":null,"homepage":"https://pgsync.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/toluaina.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.rst","contributing":"CONTRIBUTING.rst","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.rst","dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["toluaina"],"patreon":"toluaina","open_collective":"tolu-aina1","ko_fi":"toluaina","tidelift":null,"community_bridge":null,"liberapay":"taina","issuehunt":null,"otechie":null,"custom":["https://www.paypal.me/toluaina"]}},"created_at":"2019-08-17T11:23:28.000Z","updated_at":"2025-05-10T16:12:51.000Z","dependencies_parsed_at":"2023-12-22T14:48:46.454Z","dependency_job_id":"7cabc04c-37bc-4543-ab80-7c2c75300e0e","html_url":"https://github.com/toluaina/pgsync","commit_stats":{"total_commits":524,"total_committers":20,"mean_commits":26.2,"dds":0.07442748091603058,"last_synced_commit":"e27f4284f1bc06f78b6d5e08c9d0d0517e0a2f91"},"previous_names":[],"tags_count":46,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toluaina%2Fpgsync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toluaina%2Fpgsync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toluaina%2Fpgsync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toluaina%2Fpgsync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toluaina","download_url":"https://codeload.github.com/toluaina/pgsync/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254041367,"owners_count":22004710,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["change-data-capture","elasticsearch","elasticsearch-sync","etl","kibana","opensearch","postgresql","python","sql"],"created_at":"2024-08-01T21:02:02.754Z","updated_at":"2026-01-04T15:16:15.699Z","avatar_url":"https://github.com/toluaina.png","language":"Python","readme":"\u003cdiv align=\"center\"\u003e\n\n# PGSync\n\n### Real-time PostgreSQL to Elasticsearch/OpenSearch sync\n\n**Keep your relational database as the source of truth while powering lightning-fast search**\n\n[![PyPI version](https://img.shields.io/pypi/v/pgsync?color=blue\u0026logo=pypi\u0026logoColor=white)](https://pypi.org/project/pgsync)\n[![Python versions](https://img.shields.io/pypi/pyversions/pgsync?logo=python\u0026logoColor=white)](https://pypi.org/project/pgsync)\n[![Build status](https://img.shields.io/github/actions/workflow/status/toluaina/pgsync/python-build.yml?branch=main\u0026logo=github)](https://github.com/toluaina/pgsync/actions)\n[![codecov](https://img.shields.io/codecov/c/github/toluaina/pgsync?logo=codecov\u0026logoColor=white)](https://codecov.io/gh/toluaina/pgsync)\n[![Downloads](https://img.shields.io/pypi/dm/pgsync?color=brightgreen\u0026logo=pypi\u0026logoColor=white)](https://pypi.org/project/pgsync)\n[![License](https://img.shields.io/github/license/toluaina/pgsync?color=blue)](LICENSE)\n\n[![Docker](https://img.shields.io/badge/docker-ready-2496ED?logo=docker\u0026logoColor=white)](https://hub.docker.com/r/toluaina1/pgsync)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\n[Website](https://pgsync.com) · [Documentation](https://pgsync.com) · [Examples](examples/) · [Report Bug](https://github.com/toluaina/pgsync/issues)\n\n\u003c/div\u003e\n\n---\n\n## What is PGSync?\n\nPGSync is a change data capture tool that syncs data from **PostgreSQL**, **MySQL**, or **MariaDB** to **Elasticsearch** or **OpenSearch** in real-time. Define your document structure in JSON, and PGSync handles the rest — no custom code required.\n\n```mermaid\nflowchart LR\n    subgraph Source[\"🗄️ Source Database\"]\n        DB[(PostgreSQL\u003cbr/\u003eMySQL\u003cbr/\u003eMariaDB)]\n    end\n\n    subgraph CDC[\"⚡ Change Data Capture\"]\n        P[PGSync]\n    end\n\n    subgraph Search[\"🔍 Search Engine\"]\n        ES[(Elasticsearch\u003cbr/\u003eOpenSearch)]\n    end\n\n    DB --\u003e|WAL / Binlog| P\n    P --\u003e|Bulk Index| ES\n```\n\n### Key Features\n\n| Feature | Description |\n|---------|-------------|\n| **Real-time sync** | Changes propagate instantly via logical replication |\n| **Zero code** | Define mappings in JSON — no ETL pipelines to build |\n| **Nested documents** | Automatically denormalize complex relationships |\n| **Fault tolerant** | Resumes from checkpoints after crashes |\n| **Transactionally consistent** | Documents appear in commit order |\n| **Minimal overhead** | Lightweight CDC with negligible database impact |\n\n---\n\n## Quick Start\n\n### Using Docker (Fastest)\n\n```bash\ndocker run --rm -it \\\n  -e PG_URL=postgres://user:pass@host/db \\\n  -e ELASTICSEARCH_URL=http://localhost:9200 \\\n  -e REDIS_HOST=localhost \\\n  -v \"$(pwd)/schema.json:/app/schema.json\" \\\n  toluaina1/pgsync:latest -c schema.json -d -b\n```\n\n### Using pip\n\n```bash\npip install pgsync\n```\n\n```bash\n# Bootstrap (one-time setup)\nbootstrap --config schema.json\n\n# Run sync\npgsync --config schema.json -d\n```\n\n### Using Docker Compose\n\n```bash\ngit clone https://github.com/toluaina/pgsync\ncd pgsync\ndocker-compose up\n```\n\n---\n\n## How It Works\n\n**1. Define your schema** — Map tables to document structure:\n\n```json\n{\n  \"table\": \"book\",\n  \"columns\": [\"isbn\", \"title\", \"description\"],\n  \"children\": [{\n    \"table\": \"author\",\n    \"columns\": [\"name\"]\n  }]\n}\n```\n\n**2. PGSync generates optimized queries** — Complex JOINs handled automatically:\n\n```sql\nSELECT JSON_BUILD_OBJECT(\n  'isbn', book.isbn,\n  'title', book.title,\n  'authors', (SELECT JSON_AGG(author.name) FROM author ...)\n) FROM book\n```\n\n**3. Get denormalized documents** — Ready for search:\n\n```json\n{\n  \"isbn\": \"9785811243570\",\n  \"title\": \"Charlie and the Chocolate Factory\",\n  \"authors\": [\"Roald Dahl\"]\n}\n```\n\nChanges to any related table automatically update the document in Elasticsearch/OpenSearch.\n\n---\n\n## Requirements\n\n| Component | Version |\n|-----------|---------|\n| ![Python](https://img.shields.io/badge/Python-3.9+-3776AB?logo=python\u0026logoColor=white) | 3.9+ |\n| ![PostgreSQL](https://img.shields.io/badge/PostgreSQL-9.6+-4169E1?logo=postgresql\u0026logoColor=white) | 9.6+ (or MySQL 5.7.22+ / MariaDB 10.5+) |\n| ![Elasticsearch](https://img.shields.io/badge/Elasticsearch-6.3+-005571?logo=elasticsearch\u0026logoColor=white) | 6.3.1+ (or OpenSearch 1.3.7+) |\n| ![Redis](https://img.shields.io/badge/Redis-3.1+-DC382D?logo=redis\u0026logoColor=white) | 3.1+ (or Valkey 7.2+) — optional in WAL mode |\n\n---\n\n## Database Setup\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003ePostgreSQL\u003c/b\u003e\u003c/summary\u003e\n\nEnable logical decoding in `postgresql.conf`:\n\n```ini\nwal_level = logical\nmax_replication_slots = 1\n```\n\nOptionally limit WAL size:\n\n```ini\nmax_slot_wal_keep_size = 100GB\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eMySQL / MariaDB\u003c/b\u003e\u003c/summary\u003e\n\nEnable binary logging in `my.cnf`:\n\n```ini\nserver-id = 1\nlog_bin = mysql-bin\nbinlog_row_image = FULL\nbinlog_expire_logs_seconds = 604800\n```\n\nCreate replication user:\n\n```sql\nCREATE USER 'replicator'@'%' IDENTIFIED WITH mysql_native_password BY 'password';\nGRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'replicator'@'%';\nFLUSH PRIVILEGES;\n```\n\n\u003c/details\u003e\n\n---\n\n## Example\n\nConsider a book library with related authors:\n\n| **Book** | | | |\n|----------|--|--|--|\n| isbn *(PK)* | title | description |\n| 9785811243570 | Charlie and the Chocolate Factory | Willy Wonka's famous... |\n| 9781471331435 | 1984 | George Orwell's chilling... |\n\n| **Author** | |\n|------------|--|\n| id *(PK)* | name |\n| 1 | Roald Dahl |\n| 4 | George Orwell |\n\nPGSync transforms this into search-ready documents:\n\n```json\n[\n  {\n    \"isbn\": \"9785811243570\",\n    \"title\": \"Charlie and the Chocolate Factory\",\n    \"authors\": [\"Roald Dahl\"]\n  },\n  {\n    \"isbn\": \"9781471331435\",\n    \"title\": \"1984\",\n    \"authors\": [\"George Orwell\"]\n  }\n]\n```\n\n**Any change** — updating an author's name, adding a new book, deleting a relationship — is automatically synced.\n\n---\n\n## Why PGSync?\n\n| Challenge | PGSync Solution |\n|-----------|-----------------|\n| Dual writes are error-prone | Captures changes from WAL — single source of truth |\n| Complex JOIN queries | Auto-generates optimized SQL from your schema |\n| Nested document updates | Detects changes in any related table |\n| Data consistency | Transactionally consistent, ordered delivery |\n| Crash recovery | Checkpoint-based resumption |\n\n---\n\n## Environment Variables\n\nFull list at [pgsync.com/env-vars](https://pgsync.com/env-vars)\n\n| Variable | Description |\n|----------|-------------|\n| `PG_URL` | PostgreSQL connection string |\n| `ELASTICSEARCH_URL` | Elasticsearch/OpenSearch URL |\n| `REDIS_HOST` | Redis/Valkey host |\n| `REDIS_CHECKPOINT` | Use Redis for checkpoints (recommended for production) |\n\n---\n\n## One-Click Deploy\n\n[![Deploy to DigitalOcean](https://www.deploytodo.com/do-btn-blue.svg)](https://cloud.digitalocean.com/apps/new?repo=https://github.com/toluaina/pgsync/tree/main)\n\n---\n\n## Sponsors\n\n\u003ca href=\"https://www.digitalocean.com/?utm_medium=opensource\u0026utm_source=pgsync\"\u003e\n  \u003cimg src=\"https://opensource.nyc3.cdn.digitaloceanspaces.com/attribution/assets/SVG/DO_Logo_horizontal_blue.svg\" alt=\"DigitalOcean\" width=\"200\"\u003e\n\u003c/a\u003e\n\n---\n\n## Contributing\n\nContributions welcome! See [CONTRIBUTING.rst](CONTRIBUTING.rst) for guidelines.\n\n## License\n\n[MIT](LICENSE) — use it freely in your projects.\n","funding_links":["https://github.com/sponsors/toluaina","https://patreon.com/toluaina","https://opencollective.com/tolu-aina1","https://ko-fi.com/toluaina","https://liberapay.com/taina","https://www.paypal.me/toluaina"],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoluaina%2Fpgsync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoluaina%2Fpgsync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoluaina%2Fpgsync/lists"}