使用pgoutput的方式
设置postgresql
修改postgresql.conf添加或者修改以下字段
wal_level = logical
max_wal_senders = 1
max_replication_slots = 1
修改pg_hba.conf
local replication <youruser> trust
host replication <youruser> 127.0.0.1/32 trust
host replication <youruser> ::1/128 trust
需要权限
表Select权限 GRANT SELECT on public.[table] to [user];
Publication 权限 ALTER USER test_dbz REPLICATION;
表的PUBLICATION 权限 CREATE PUBLICATION [publication_name] FOR TABLE [table1,table2](需要表的owner或者管理员)
配置kafka connect
1.将kafka connect的jar报放在plugn 目录(config/connect-distributed.properties的plugin.path)目录下
2.重启kafka connect
3.编写connect json
{
"name": "postgres-connect",
"config": {
"connector.class": "io.debezium.connector.postgresql.PostgresConnector",
"database.hostname": "ip",
"database.port": "5432",
"database.user": "user",
"database.password": "pass",
"database.dbname" : "test_owner",
"database.server.name": "postgres-test-owner",
"table.include.list": "public.test1,public.test2,public.test3",
"publication.autocreate.mode":"filtered",
"plugin.name":"pgoutput",
}
}
4.post 提交json 到http://ip:8083/connectors
5.查看kafka topic postgres-test-owner.public.test1

该博客详细介绍了如何通过pgoutput插件设置PostgreSQL的逻辑复制,以及利用Kafka Connect和Debezium连接器将数据流式传输到Kafka。首先,修改postgresql.conf和pg_hba.conf文件以启用逻辑复制和设置权限。然后,为用户和表分配必要的权限。接着,配置Kafka Connect,包括放置jar包、重启服务和编写连接器配置JSON。最后,通过HTTP提交JSON并验证Kafka主题。这个过程对于实时数据管道和数据库变更捕获至关重要。

被折叠的 条评论
为什么被折叠?



