Postgresql-slony-i Synchronous Replication Configuration steps

Source: Internet
Author: User
Tags event listener postgresql psql





Primary database: 172.16.254.21 port: 5432
From database: 172.16.254.22 port: 5432





Step 1: Master-Slave installation Slon
Apt-get Install Slon-bin
Step 2: Configure permissions for the master-slave database to create the language.
Vi / etc / postgresql / 8.3 / node / pg_hba.conf in the primary database
Add a record host all REPL 172.16.254.22/32 MD5





Perform the following operations on the master and slave databases:
Shell> psql
node = #create role repl password '123456' login Superuser
#Create user repl, give Superuser privileges
node = # use node;
node = # Create language Plpgsql;
#Create language plpgsql
Step 3: Back up the primary database and restore from the database
#Backup the database to be copied in the main database
Pg_dump Node> Node_20100220.dmp
#After restoring the database node from the library
postgres = #create database node;
Postgres = # \ q
Shell> psql node <node_20100220.dmp;
Step 4: Create a script replication from the database / export / script directory, with the following content:
#! / bin / sh





Slonik = / usr / bin / slonik
Slon = / usr / bin / slon





Cluster_name = mynode





Master = "host = 172.16.254.21 Dbname = node user = repl Password = 123456 ″
Slave = "host = 172.16.254.22 Dbname = node user = repl Password = 123456 ″
Log = / root





Uninstall ()
{
$ SLONIK << _eof_
Cluster name = $ CLUSTER _name;





Node 1 admin conninfo = '$ MASTER';
Node 2 admin conninfo = '$ SLAVE';





# drop node (id = 2);
# drop Node (id = 1);





Uninstall node (id = 2);
Uninstall node (id = 1);
_eof_
}





Install ()
{
$ SLONIK << _eof_
# define Cluster Name
Cluster name = $ CLUSTER _name;





# Two nodes defined
Node 1 admin conninfo = '$ MASTER';
Node 2 admin conninfo = '$ SLAVE';





Try
{
# Initialize the master node
Init cluster (id = 1, comment = 'Master Node');





# Create a Copy collection
Create set (id = 1, origin = 1, comment = 'all tables');
# Add a table in the copy collection that needs to be copied
Set Add table (set id = 1, origin = 1, id = 1, fully qualified name = 'PUBLIC.HXF', comment = 'table hxf');
#set add sequence (Set id = 1, origin = 1, id = 3, fully qualified name = 'public.hxf_seq');
# Create a Slave node
Store node (id = 2, comment = 'Slave node');





# define access paths between nodes
Store path (server = 1, client = 2, Conninfo = '$ MASTER');
Store path (server = 2, client = 1, Conninfo = '$ SLAVE');





# define Event Listener
Store Listen (origin = 1, Provider = 1, receiver = 2);
Store Listen (origin = 2, Provider = 2, receiver = 1);





# Subscription Replication Collection
Subscribe Set (id = 1, Provider = 1, receiver = 2, forward = no);
}
On success
{
Echo 'Install ok!';
}
On Error
{
Echo 'Install fail!';
}
_eof_
}





Start ()
{
# Start the replication daemon
$ SLON $ CLUSTER _name "$ MASTER" >> / 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 $} '
}





Case $ in
'Install')
Install
;;
'Uninstall')
Uninstall
;;
'Start')
Start
;;
'Stop')
Stop
;;
*)
echo "Usage: $ {install | uninstall | start | stop}"
;;
Esac
Step 5: Start
./replication Start
Step 6: Test
1. Add a record to the empty table PUBLIC.HXF in the primary database
Insert into HXF (uid, uname) Select 1, 'Huangxifeng';
2. See a record in the main database
node = # select * from HXF;
UID | Uname
-– + ————-
1 | Huangxifeng
(1 row)
3. See a record from the database
node = # select * from HXF;
UID | Uname
-– + ————-
1 | Huangxifeng
(1 row)





Postgresql-slony-i Synchronous Replication Configuration steps

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.