通过逻辑复制槽将postresql复制到elasticsearch
pg-replicate-elastic的Python项目详细描述
通过逻辑复制槽将postresql复制到elasticsearch
安装
$ pip install pg-replicate-elastic
wal2json
$ pip install pg-replicate-elastic
注意:使用我的叉子,因为我们测试了它,以确保它100%与它一起工作,并且不会发生破坏性的变化,wal2json。
$ git clone https://github.com/hmilkovi/wal2json.git
$ PATH=/path/to/bin/pg_config:$PATH
$ USE_PGXS=1 make
$ USE_PGXS=1 make install
您需要在postgresql.conf上设置至少两个参数:
wal_level = logical
max_replication_slots = 1
更改这些参数后,需要重新启动。
使用量
pg_replicate_elastic --config=<absolute path to json config>
以json格式构造配置文件,其中:
- replication_slot复制slot name和if是临时的json对象
- tables是要复制的表数组
- es_连接到elasticsearch的连接字符串
- postgrespostresql连接的json对象
- inital_sync需要第一次完成的初始同步的布尔值 复制旧数据
示例配置
{
"replication_slot": {
"name": "elasticsearch_slot",
"is_temp": true
},
"tables": [{
"name": "poc",
"primary_key": "a"
"exclude_columns": "c,z"
}],
"es_connection": "http://127.0.0.1:9200/",
"postgres": {
"port": 5432,
"host": "127.0.0.1",
"database": "poc",
"username": "test",
"password": "test"
},
"inital_sync": false
}
注
wal2json不是我的软件,所以用于许可证检查their licence