Skip to main content
PyPI Version Python Versions License Downloads

PostgreSQL/MySQL/MariaDB to Elasticsearch/OpenSearch sync

PGSync is a middleware for syncing data from PostgreSQL, MySQL, or MariaDB to Elasticsearch or OpenSearch.

Keep your relational database as the source of truth and expose structured denormalized documents in your search engine.

Django integration: Use django-pgsync to integrate PGSync with Django projects.

Key Features

  • Real-time sync via logical decoding (PostgreSQL) or binary log (MySQL/MariaDB)

  • Denormalize complex relational data into nested search documents

  • JSON schema-based configuration

  • Support for one-to-one, one-to-many relationships

  • Plugin system for document transformation

  • Multiple operation modes: daemon, polling, or direct WAL streaming

Requirements

Installation

Install from PyPI:

pip install pgsync

Database Setup

PostgreSQL

Enable logical decoding in your PostgreSQL configuration (postgresql.conf):

wal_level = logical
max_replication_slots = 1

MySQL / MariaDB

Enable binary logging in your MySQL/MariaDB configuration (my.cnf):

server-id = 1
log_bin = mysql-bin
binlog_row_image = FULL
binlog_expire_logs_seconds = 604800

Create a replication user:

CREATE USER 'replicator'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'replicator'@'%';
FLUSH PRIVILEGES;

Configuration

Create a JSON schema file (e.g., schema.json) defining your sync mapping:

[
    {
        "database": "book",
        "index": "book",
        "nodes": {
            "table": "book",
            "columns": ["isbn", "title", "description"],
            "children": [
                {
                    "table": "publisher",
                    "columns": ["name"],
                    "relationship": {
                        "variant": "object",
                        "type": "one_to_one"
                    }
                },
                {
                    "table": "author",
                    "label": "authors",
                    "columns": ["name", "date_of_birth"],
                    "relationship": {
                        "variant": "object",
                        "type": "one_to_many",
                        "through_tables": ["book_author"]
                    }
                }
            ]
        }
    }
]

See the examples directory for more schema examples (airbnb, social, rental, etc.).

Environment Variables

Configure PGSync via environment variables:

# Schema
SCHEMA='/path/to/schema.json'

# PostgreSQL
PG_HOST=localhost
PG_PORT=5432
PG_USER=postgres
PG_PASSWORD=*****

# Elasticsearch / OpenSearch
ELASTICSEARCH_HOST=localhost
ELASTICSEARCH_PORT=9200

# Redis (optional in WAL mode)
REDIS_HOST=localhost
REDIS_PORT=6379

Running

Bootstrap (run once to set up triggers and replication slots):

bootstrap --config schema.json

Run as daemon:

pgsync --config schema.json --daemon

License

MIT License - see LICENSE for details.

Release files for pgsync 7.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pgsync 7.3.0
File Size Uploaded
pgsync-7.3.0.tar.gz 183.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pgsync 7.3.0
File Interpreter ABI Platform
pgsync-7.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 269.2 kB

Release files / pgsync-7.3.0.tar.gz

Download URL pgsync-7.3.0.tar.gz
Size 183.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0ea5c355e417dfd5d064593c59fdd7d2d92e978a8a1c110f25168a97ede306bc
BLAKE2b-256 checksum
How to use checksums
663a2c5dd1e691a16a7bd30f2c085c9e239e85632e371ed2c1661a7c102975f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 13, 2026.

Transparency log

Release files / pgsync-7.3.0-py3-none-any.whl

Download URL pgsync-7.3.0-py3-none-any.whl
Size 85.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f1b4f8aa4104bd1de14b4c02fdd954947c8b6144e03ae7c2268c511612ece01f
BLAKE2b-256 checksum
How to use checksums
567f972c5462f44f6cb2789674743ce9d335019fb7bd20c0bb901d454f61ee7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 13, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

7.3.0 This release

2 release files

7.2.0

2 release files

7.1.0

2 release files

7.0.5

2 release files

7.0.2

2 release files

7.0.1

2 release files

7.0.0

2 release files

6.2.0

2 release files

6.1.1

2 release files

6.1.0

2 release files

6.0.0

2 release files

5.0.0

2 release files

4.2.1

2 release files

4.2.0

2 release files

4.1.0

2 release files

4.0.0

2 release files

3.3.0

2 release files

3.2.1

2 release files

3.2.0

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.5.0

2 release files

2.4.0

2 release files

2.3.3

2 release files

2.3.2

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.11

2 release files

2.1.9

2 release files

2.1.8

2 release files

2.1.7

2 release files

2.1.6

2 release files

2.1.5

2 release files

2.1.4

2 release files

2.1.3

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.0.0

2 release files

1.1.33

2 release files

1.1.30

2 release files

1.1.29

2 release files

1.1.27

2 release files

1.1.26

2 release files

1.1.25

2 release files

1.1.23

2 release files

1.1.22

2 release files

1.1.21

2 release files

1.1.17

2 release files

1.1.16

2 release files

1.1.9

10 release files

1.1.8

10 release files

1.1.7

10 release files

1.1.6

7 release files

1.1.5

10 release files

1.1.4

10 release files

1.1.3

10 release files

1.1.2

7 release files

1.1.1

10 release files

1.1.0

3 release files

1.0.1

10 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page