Skip to main content

Postgres 到 Elasticsearch 同步

项目描述

PostgreSQL 到 Elasticsearch 同步

要求

Postgres 设置

在 Postgres 设置中启用逻辑解码。

  • 您还需要在 Postgres 配置 postgresql.conf 中设置两个参数

    wal_level = logical

    max_replication_slots = 1

安装

您可以从PyPI安装 PGSync :

$ pip install pgsync

配置

为应用程序创建一个模式,例如schema.json

示例架构

示例规范

.. 代码块::

[
    {
        "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"
                    },
                    ...
                },
                {
                    ... additional children
                }
            ]
        }
    }
]

环境变量

设置应用程序所需的环境变量

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=*****

跑步

引导数据库(仅一次)

  • $ bootstrap --config schema.json

将 pgsync 作为守护进程运行

  • $ pgsync --config schema.json --daemon

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

pgsync-2.3.2.tar.gz (104.6 kB 查看哈希

已上传 source

内置分布

pgsync-2.3.2-py2.py3-none-any.whl (54.3 kB 查看哈希

已上传 py2 py3