# PostgreSQL to Elasticsearch/OpenSearch sync
- [PGSync](https://pgsync.com) is a middleware for syncing data from [Postgres](https://www.postgresql.org) to [Elasticsearch](https://www.elastic.co/products/elastic-stack)/[OpenSearch](https://opensearch.org/) or [OpenSearch](https://opensearch.org/).
- It allows you to keep [Postgres](https://www.postgresql.org) as your source of truth data source and
expose structured denormalized documents in [Elasticsearch](https://www.elastic.co/products/elastic-stack)/[OpenSearch](https://opensearch.org/).
### Requirements
- [Python](https://www.python.org) 3.7+
- [Postgres](https://www.postgresql.org) 9.6+
- [Redis](https://redis.io) 3.1.0
- [Elasticsearch](https://www.elastic.co/products/elastic-stack) 6.3.1+ or [OpenSearch](https://opensearch.org/) 1.3.7+
- [SQlAlchemy](https://www.sqlalchemy.org) 1.3.4+
### Postgres setup
Enable [logical decoding](https://www.postgresql.org/docs/current/logicaldecoding.html) 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](https://pypi.org):
$ pip install pgsync
### Config
Create a schema for the application named e.g **schema.json**
[Example schema](https://github.com/toluaina/pgsync/blob/main/examples/airbnb/schema.json)
Example spec
.. code-block::
[
{
"database": "[database name]",
"index": "[Elasticsearch or OpenSearch 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"
},
...
},
{
... 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
Raw data
{
"_id": null,
"home_page": "https://github.com/toluaina/pgsync",
"name": "retake-pgsync",
"maintainer": "Tolu Aina",
"docs_url": null,
"requires_python": ">=3.7.0",
"maintainer_email": "tolu@pgsync.com",
"keywords": "pgsync,elasticsearch,opensearch,postgres,change data capture",
"author": "Tolu Aina",
"author_email": "tolu@pgsync.com",
"download_url": "https://files.pythonhosted.org/packages/0f/af/f1cde56a454d8f00f1dc741d1c43c7810909e546c8e4bf76c9260424a3f3/retake-pgsync-2.5.4.tar.gz",
"platform": null,
"description": "# PostgreSQL to Elasticsearch/OpenSearch sync\n\n\n- [PGSync](https://pgsync.com) is a middleware for syncing data from [Postgres](https://www.postgresql.org) to [Elasticsearch](https://www.elastic.co/products/elastic-stack)/[OpenSearch](https://opensearch.org/) or [OpenSearch](https://opensearch.org/).\n- It allows you to keep [Postgres](https://www.postgresql.org) as your source of truth data source and\nexpose structured denormalized documents in [Elasticsearch](https://www.elastic.co/products/elastic-stack)/[OpenSearch](https://opensearch.org/).\n\n\n### Requirements\n\n- [Python](https://www.python.org) 3.7+\n- [Postgres](https://www.postgresql.org) 9.6+\n- [Redis](https://redis.io) 3.1.0\n- [Elasticsearch](https://www.elastic.co/products/elastic-stack) 6.3.1+ or [OpenSearch](https://opensearch.org/) 1.3.7+\n- [SQlAlchemy](https://www.sqlalchemy.org) 1.3.4+\n\n### Postgres setup\n \n Enable [logical decoding](https://www.postgresql.org/docs/current/logicaldecoding.html) in your \n Postgres setting.\n\n - You also need to set up two parameters in your Postgres config postgresql.conf\n\n ```wal_level = logical```\n\n ```max_replication_slots = 1```\n\n### Installation\n\nYou can install PGSync from [PyPI](https://pypi.org):\n\n $ pip install pgsync\n\n### Config\n\nCreate a schema for the application named e.g **schema.json**\n\n[Example schema](https://github.com/toluaina/pgsync/blob/main/examples/airbnb/schema.json)\n\nExample spec\n\n.. code-block::\n\n [\n {\n \"database\": \"[database name]\",\n \"index\": \"[Elasticsearch or OpenSearch index]\",\n \"nodes\": {\n \"table\": \"[table A]\",\n \"schema\": \"[table A schema]\",\n \"columns\": [\n \"column 1 from table A\",\n \"column 2 from table A\",\n ... additional columns\n ],\n \"children\": [\n {\n \"table\": \"[table B with relationship to table A]\",\n \"schema\": \"[table B schema]\",\n \"columns\": [\n \"column 1 from table B\",\n \"column 2 from table B\",\n ... additional columns\n ],\n \"relationship\": {\n \"variant\": \"object\",\n \"type\": \"one_to_many\"\n },\n ...\n },\n {\n ... additional children\n }\n ]\n }\n }\n ]\n\n### Environment variables \n\nSetup environment variables required for the application\n\n SCHEMA='/path/to/schema.json'\n\n ELASTICSEARCH_HOST=localhost\n ELASTICSEARCH_PORT=9200\n\n PG_HOST=localhost\n PG_USER=i-am-root # this must be a postgres superuser or replication user\n PG_PORT=5432\n PG_PASSWORD=*****\n\n REDIS_HOST=redis\n REDIS_PORT=6379\n REDIS_DB=0\n REDIS_AUTH=*****\n\n\n### Running\n\nBootstrap the database (one time only)\n - $ bootstrap --config schema.json\n\nRun pgsync as a daemon\n - $ pgsync --config schema.json --daemon\n",
"bugtrack_url": null,
"license": "LGPLv3",
"summary": "Postgres to Elasticsearch/OpenSearch sync",
"version": "2.5.4",
"project_urls": {
"Bug Reports": "https://github.com/toluaina/pgsync/issues",
"Documentation": "https://pgsync.com",
"Funding": "https://github.com/sponsors/toluaina",
"Homepage": "https://github.com/toluaina/pgsync",
"Source": "https://github.com/toluaina/pgsync",
"Web": "https://pgsync.com"
},
"split_keywords": [
"pgsync",
"elasticsearch",
"opensearch",
"postgres",
"change data capture"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "83188c5768a5d47cc96fd2a77fce02492c80e35800af07eaf7107bae18e61376",
"md5": "2de5cde9ad4787a2bf9e4d758f72d301",
"sha256": "c1c8a93387ef8bb6949d2f7bd60861d2e7d6dbe39ba8e0f0f256bf136cef50d0"
},
"downloads": -1,
"filename": "retake_pgsync-2.5.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2de5cde9ad4787a2bf9e4d758f72d301",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7.0",
"size": 57982,
"upload_time": "2023-08-14T16:25:59",
"upload_time_iso_8601": "2023-08-14T16:25:59.431280Z",
"url": "https://files.pythonhosted.org/packages/83/18/8c5768a5d47cc96fd2a77fce02492c80e35800af07eaf7107bae18e61376/retake_pgsync-2.5.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0faff1cde56a454d8f00f1dc741d1c43c7810909e546c8e4bf76c9260424a3f3",
"md5": "ff56970f314f1e96f9fa2c94f9e72d15",
"sha256": "99b40018c6d2c8db78f2f741e266bce61c890754b7c62aad8dc3c634262cf213"
},
"downloads": -1,
"filename": "retake-pgsync-2.5.4.tar.gz",
"has_sig": false,
"md5_digest": "ff56970f314f1e96f9fa2c94f9e72d15",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7.0",
"size": 110219,
"upload_time": "2023-08-14T16:26:01",
"upload_time_iso_8601": "2023-08-14T16:26:01.444161Z",
"url": "https://files.pythonhosted.org/packages/0f/af/f1cde56a454d8f00f1dc741d1c43c7810909e546c8e4bf76c9260424a3f3/retake-pgsync-2.5.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-14 16:26:01",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "toluaina",
"github_project": "pgsync",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"lcname": "retake-pgsync"
}