Postgres to Elasticsearch sync
Project description
PostgreSQL to Elasticsearch sync
- PGSync is a middleware for syncing data from Postgres to Elasticsearch.
- It allows you to keep Postgres as your source of truth data source and expose structured denormalized documents in Elasticsearch.
Requirements
- Python 3.7+
- Postgres 9.6+
- Redis 3.1.0
- Elasticsearch 6.3.1+
- SQlAlchemy 1.3.4+
Postgres setup
Enable logical decoding in your Postgres setting.
-
You also need to set up two parameters in your Postgres config postgresql.conf
wal_level = logical
max_replication_slots = 1
Installation
You can install PGSync from PyPI:
$ pip install pgsync
Config
Create a schema for the application named e.g schema.json
Example spec
.. code-block::
[
{
"database": "[database name]",
"index": "[elasticsearch index]",
"nodes": {
"table": "[table A]",
"schema": "[table A schema]",
"columns": [
"column 1 from table A",
"column 2 from table A",
... additional columns
],
"children": [
{
"table": "[table B with relationship to table A]",
"schema": "[table B schema]",
"columns": [
"column 1 from table B",
"column 2 from table B",
... additional columns
],
"relationship": {
"variant": "object",
"type": "one_to_many"
},
...
},
{
... any other additional children
}
]
}
}
]
Environment variables
Setup environment variables required for the application
SCHEMA='/path/to/schema.json'
ELASTICSEARCH_HOST=localhost
ELASTICSEARCH_PORT=9200
PG_HOST=localhost
PG_USER=i-am-root # this must be a postgres superuser or replication user
PG_PORT=5432
PG_PASSWORD=*****
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_DB=0
REDIS_AUTH=*****
Running
Bootstrap the database (one time only)
- $ bootstrap --config schema.json
Run pgsync as a daemon
- $ pgsync --config schema.json --daemon
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pgsync-2.2.0.tar.gz
(90.8 kB
view details)
Built Distribution
File details
Details for the file pgsync-2.2.0.tar.gz
.
File metadata
- Download URL: pgsync-2.2.0.tar.gz
- Upload date:
- Size: 90.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 864d62b26ab3f71d7cfb30bb842aa035622dcb2557d87782319c6b1c1e6ac581 |
|
MD5 | fb4ab4d2a7dee852d413fc909d02b3cd |
|
BLAKE2b-256 | 6350a19a7baeabfcf11c0e7976b73a88086290b12d69d9efbb8252e7868d4e26 |
File details
Details for the file pgsync-2.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: pgsync-2.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 50.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8917d7ba0133645427039ba2d80b6e0414a66bd6bd85093985100423309d7d6e |
|
MD5 | 36e4275827aa40bcc762d1284e8c7321 |
|
BLAKE2b-256 | 0347470cb8739abeecc0ab7e7401fac3d77e2b0ddf9fe4bb40cb4c82b51d995c |