- 論壇徽章:
- 0
|
主數(shù)據(jù)庫(kù): 172.16.254.21 端口:5432
從數(shù)據(jù)庫(kù): 172.16.254.22 端口:5432
步驟1:主從均安裝slon
apt-get install slon-bin
步驟2:主從數(shù)據(jù)庫(kù)配置權(quán)限,創(chuàng)建語(yǔ)言。
在主數(shù)據(jù)庫(kù)中 vi /etc/postgresql/8.3/node/pg_hba.conf
添加一條記錄 host all repl 172.16.254.22/32 md5
在主從數(shù)據(jù)庫(kù)均執(zhí)行以下操作:
shell>psql
node=#create role repl password '123456' login superuser
#創(chuàng)建用戶repl,賦予超級(jí)用戶權(quán)限
node=# use node;
node=# create language plpgsql;
#創(chuàng)建語(yǔ)言plpgsql
步驟3:備份主數(shù)據(jù)庫(kù)至從數(shù)據(jù)庫(kù)并恢復(fù)
#在主數(shù)據(jù)庫(kù)備份要復(fù)制的數(shù)據(jù)庫(kù)
pg_dump node > node_20100220.dmp
#在從庫(kù)恢復(fù)數(shù)據(jù)庫(kù)node
postgres=#create database node;
postgres=#\q
shell>psql node > /export/scripts/master.log &
$SLON $CLUSTER_NAME "$SLAVE" >> /export/scripts/slave.log &
}
stop()
{
# killall slon
kill -9 `ps axu|grep 'dbname=node' |grep -v grep|awk '{print $2}'`
}
case $1 in
'install')
install
;;
'uninstall')
uninstall
;;
'start')
start
;;
'stop')
stop
;;
*)
echo "usage: $0 {install|uninstall|start|stop} "
;;
esac
步驟5:?jiǎn)?dòng)
./replication start
步驟6:測(cè)試
1.在主數(shù)據(jù)庫(kù)的空表public.hxf中添加一條記錄
insert into hxf(uid,uname) select 1,'huangxifeng';
2.在主數(shù)據(jù)庫(kù)中看到有一條記錄
node=# select * from hxf;
uid | uname
-----+-------------
1 | huangxifeng
(1 row)
3.在從數(shù)據(jù)庫(kù)中看到有一條記錄
node=# select * from hxf;
uid | uname
-----+-------------
1 | huangxifeng
(1 row)
本文來(lái)自ChinaUnix博客,如果查看原文請(qǐng)點(diǎn):http://blog.chinaunix.net/u2/66215/showart_2182947.html |
|