BDR 0.9.0版本测试

一、安装

参考bdr官方文档Chapter 3. Installation

二、配置

先initdb,然后修改配置postgresql.conf:

#必须的配置:
shared_preload_libraries = 'bdr'
track_commit_timestamp = on
wal_level = 'logical'
max_replication_slots = 30
max_wal_senders = 10
#可选的:
#bdr.synchronous_commit = on
#bdr.log_conflicts_to_table = on
#bdr.max_workers = 512MB
#max_worker_processes = 50

配置pg_hba.conf,然后启动实例:

local   replication     postgres                                trust
host    all             all             xxx.xxx.xxx.xxx/32       md5
host    replication     postgres        xxx.xxx.xxx.xxx/32       md5

配置.pgpass

xxx.xxx.xxx.xxx:5432:*:postgres:xxxxxxxxxxxxxxxxxxxxxxxx


三、初始化第一个节点

进入PostgreSQL后执行:

bdr=# create extension btree_gist;
bdr=# create extension bdr;
bdr=# select bdr.bdr_group_create(
	local_node_name := 'node1',
	node_external_dsn := 'host=node1_ip dbname=bdr port=5432'
);

然后你能看见第一个节点已经准备好了:

bdr=# select * from bdr.bdr_nodes ;
node_sysid      | node_timeline | node_dboid | node_status | node_name |              node_local_dsn              | node_init_from_dsn
---------------------+---------------+------------+-------------+-----------+------------------------------------------+--------------------
 6139739409922254460 |             1 |      16384 | r           | node1     | host=node1_ip dbname=bdr port=5432  |
(1 row)


四、新节点的创建

1. 逻辑克隆:initdb + pg_dumpall

(1)初始化实例:执行第一步和第二步

(2)使用pg_dumpall从第一个节点复制数据,这个过程需要集群只读,否则数据就不一致了

(3)在pg里面执行:

bdr=# create extension btree_gist;
bdr=# create extension bdr;
bdr=#  select bdr.bdr_group_join(
	local_node_name := 'node2',
	node_external_dsn := 'dbname=bdr host=node2_ip user=postgres port=5432',
	join_using_dsn := 'dbname=bdr host=node1_ip user=postgres port=5432'
);

查看是否加入成功:

bdr=# select * from bdr.bdr_nodes ;
     node_sysid      | node_timeline | node_dboid | node_status | node_name |                     node_local_dsn                     |                   node_init_from_dsn                   
---------------------+---------------+------------+-------------+-----------+--------------------------------------------------------+--------------------------------------------------------
 6139739409922254460 |             1 |      16384 | r           | node1     | host=node1_ip dbname=bdr port=5432                     |
 6139757325958541519 |             1 |      16384 | r           | node2     | dbname=bdr host=node2_ip user=postgres port=5432       | dbname=bdr host=node1_ip user=postgres port=5432
(2 rows)

bdr=# select * from pg_replication_slots ;
                slot_name                | plugin | slot_type | datoid | database | active | xmin | catalog_xmin | restart_lsn 
-----------------------------------------+--------+-----------+--------+----------+--------+------+--------------+-------------
 bdr_16384_6139739409922254460_1_16384__ | bdr    | logical   |  16384 | bdr      | t      |      |         1839 | 0/18E24A0
(1 row)

bdr=# select * from pg_stat_replication ;
  pid  | usesysid | usename  |              application_name              |  client_addr   | client_hostname | client_port |         backend_start         | backend_xmin |   state   | sent_location | write_location | flush_location | replay_location | sync_priority | sync_state
-------+----------+----------+--------------------------------------------+----------------+-----------------+-------------+-------------------------------+--------------+-----------+---------------+----------------+----------------+-----------------+---------------+------------
 25028 |       10 | postgres | bdr (6139739409922254460,1,16384,):receive | node1_ip       |                 |       52095 | 2015-04-20 09:56:34.211347+00 |              | streaming | 0/18E24D8     | 0/18E24D8      |             0/18E24D8      | 0/18E24D8       |            0  | async
(1 row)

2. 物理克隆:pg_basebackup + bdr_init_copy

获取基础备份:

$ /opt/pg94-bdr/bin/pg_basebackup -h node1_ip -p 5432  -X stream -D PG_DATA

bdr_init_copy:

$ /opt/pg94-bdr/bin/bdr_init_copy -d "host=node1_ip dbname=bdr port=5432" --local-dbname="host=node2_ip dbname=bdr port=5432" -n node2 -D PG_DATA


你可能感兴趣的:(PostgreSQL,BDR)