1.使用root用户执行如下编译
meson setup build \
-Dssl=openssl \
-Dlibxml=enabled \
-Dlibxslt=enabled \
-Dzlib=enabled \
--prefix=`pwd`/debug
执行生成:
meson compile -C build
编译完成后安装:
meson install -C build
- 执行如下命令拷贝二进制到/tmp
/tmp/debug/bin/pg_ctl -D /tmp/debug/bin/pub_data/ stop
/tmp/debug/bin/pg_ctl -D /tmp/debug/bin/scrib_data/ stop
rm -rf /tmp/debug
cp -r debug /tmp/
chown dys /tmp/debug -R
后续操作都需要切换到dys用户执行。
- 初始化发布端和订阅端数据库
cd /tmp/debug/bin/
/tmp/debug/bin/initdb -D pub_data -A trust
/tmp/debug/bin/initdb -D scrib_data -A trust
4.修改数据库端口和wal_level
echo "port=12345" >> /tmp/debug/bin/pub_data/postgresql.conf
echo "wal_level='logical'" >> /tmp/debug/bin/pub_data/postgresql.conf
echo "port=12346" >> /tmp/debug/bin/scrib_data/postgresql.conf
echo "wal_level='logical'" >> /tmp/debug/bin/scrib_data/postgresql.conf
- 启动数据库
/tmp/debug/bin/pg_ctl -D /tmp/debug/bin/pub_data/ -l logfile start
/tmp/debug/bin/pg_ctl -D /tmp/debug/bin/scrib_data/ -l logfile1 start
- 分别连接发布端和订阅端创建users表
/tmp/debug/bin/psql -d postgres -p 12345
create table users (
id SERIAL PRIMARY KEY,
name VARCHAR(100) not NULL,
email VARCHAR(255) UNIQUE
);
/tmp/debug/bin/psql -d postgres -p 12346
create table users (
id SERIAL PRIMARY KEY,
name VARCHAR(100) not NULL,
email VARCHAR(255) UNIQUE
);
- 创建发布者
/tmp/debug/bin/psql -d postgres -p 12345
create publication ddl_test_pub for table users with (ddl ='table,index');
- 创建订阅
/tmp/debug/bin/psql -d postgres -p 12346
create subscription ddl_test_sub
connection 'host=localhost port=12345 dbname=postgres user=dys'
publication ddl_test_pub
with (
copy_data = true,
enabled = true,
ddl = 'table,index',
streaming = on,
binary = false
);
9.在发布端插入数据
/tmp/debug/bin/psql -d postgres -p 12345
insert into users(name,email) values
('tom','tom@qq.com');
- 在发布端更新表结构
/tmp/debug/bin/psql -d postgres -p 12345
alter table users add column phone VARCHAR(20);
- 在发布端插入数据
/tmp/debug/bin/psql -d postgres -p 12345
insert into users(name,email,phone) values
('alice','test@qq.com','123-456-789'),
('bob','bob@qq.com','123-456-788');
- 观察订阅端数据是否同步,包括列是否增加,插入数据是否一致。