译者简介
晏杰宏,任职于上海新炬网络信息技术股份有限公司,Oracle DBA。负责数据库、中间件、大数据等基础软件建设、优化和业务保障工作。具有10年以上电信与银行企业一线/二线数据库运维管理经验。目前专注研究云计算、开源软件和国产化数据库等领域技术研究。
校对者简介
崔鹏,任职于海能达通信股份有限公司,数据库开发高级工程师,致力于postgresql数据库在专网通信领域、公共安全领域的应用与推广。
背景
正在进行的事务的逻辑复制
如何解码正在进行的事务
logical_decoding_work_mem=”64kB”;postgres[89179]=# CREATE TABLE stream_test(data text);CREATE TABLEpostgres[89179]=# BEGIN;BEGINpostgres[89179]=#* INSERT INTO stream_test SELECT repeat('a', 2000) || g.i FROM generate_series(1, 35) g(i);INSERT 0 35postgres[89179]=#* SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL,NULL, 'stream-changes', '1');data--------------------------------------------------BEGIN 553COMMIT 553opening a streamed block for transaction TXN 554streaming change for TXN 554streaming change for TXN 554streaming change for TXN 554streaming change for TXN 554streaming change for TXN 554streaming change for TXN 554…..closing a streamed block for transaction TXN 554(35 rows)
CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr application_name=$appname' PUBLICATION tap_pub WITH (streaming = on)
性能测试
[publisher configurations]:wal_level = logicalsynchronous_standby_names = '*' [this is set so that commit will wait for response from downstream]logical_decoding_work_mem=10MB[publisher setup]:CREATE TABLE publish_table(a int ,b text);CREATE TABLE non_publish_table(a int ,b text);CREATE PUBLICATION test_pub FOR TABLE publish_table;[subscription setup]CREATE TABLE publish_table(a int ,b text);CREATE SUBSCRIPTION test_sub CONNECTION 'host=127.0.0.1 port=5432 dbname=postgres' PUBLICATION test_pub;[performance test]:Execute a large transaction on the publisher and measure the total commit time (local commit + subscriber apply + ack from the subscriber)The transaction operates on published as well as non-published tablesBEGIN;INSERT INTO non_publish_table SELECT i, REPEAT('x', 10) FROM generate_series(1,5000000) AS i;INSERT INTO publish_table SELECT i, REPEAT('x', 10) FROM generate_series(1,1000000) AS i;COMMIT;Time taken for COMMIT: 5,7087.004 msEnable the streaming and recheck the performance.ALTER SUBSCRIPTION test_sub SET(STREAMING = ON)Time taken for COMMIT: 2,3967.789 ms
进一步的改进范围
PostgreSQL提交

文章转载自PostgreSQL中文社区,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




