Thursday 25 October 2012

Data replication with Postgresql and Slony using pgAdmin

  1. Slony-I – introduction:
      Slony-I is a "master to multiple slaves" replication system for PostgreSQL supporting cascading        (e.g. - a node can feed another node which feeds another node) and failover.
     The big picture for the development of Slony-I is that it is a master-slave replication system that     includes all features and capabilities needed to replicate large databases to a reasonably limited number   of slave systems. Slony-I is a system designed for use at data centers and backup sites, where the   normal mode of operation is that all nodes are available.
  1. Tools: Postgres-9.2, PgAdmin 1.16, slon version 2.0.7 on UBUNTU 12.04
  2. Database setup
    The data will be replicated from database source ,public schema with table emp_details to to target databse,public schema and emp_details table.
    User is postgres, host=localhost both the database are on the same machine (same host and port)

  3. Replication Process with PgAdmin
    Create to database “source” and “target” .
    Create a schema-only dump of the source database, and load it into target.
    Everything has to be done into the Replication items inside the two newly created databases. The two replication objects need references to each other .















   1- Create base replication objects

For the Master :
  • Right click on source > Replication and choose "New Slony-I Cluster"
  • Join existing cluster : Do not check this !
  • Cluster name : choose a name, here it is : REP_CLUSTER
  • Local Node Left : 1
  • Local Node Right : master_node
  • Admin Node Left : 99
  • Admin Node Right : admin_node
  • Press OK.
For the Slave :
  • Right click on target > Replication and choose "New Slony-I Cluster"
  • Join existing cluster : Has to be checked
  • Server : localhost
  • Database : source
  • Cluster name : REP_CLUSTER (should be automatically recognized)
  • Local Node Left : 10
  • Local Node Right : slave_node
  • Admin Node : 99 - admin_node
  • Press OK.
2 – Create path setup
For the Master :
  • Right click on master_node Path and choose New path
  • Server : 10 - Slave Node
  • Connect Info : host=localhost port=5434 user=postgres password= “” dbname=target
  • Conn retry : 10
  • Press OK.
For the Slave :
  • Right click on slave_node > Path and choose New path on target
  • Server : 1 - master_node
  • Connect Info : host=localhost port=5434 user=postgres password=”” dbname=source
  • Conn retry : 10
  • Press OK.
Similarly create path for each node (slave on source and master on target)
3 – Define replication set on source
  • In the Db source > REP_CLUSTER create a Replication Sets and choose new Replication Set
  • ID : 1
  • Comment : Replication Set 1
Now we choose the table we want to be replicated from source to target .
  • In the Replication Set 1 choose New tables
  • Table : Any table of your choice e.g public.details (You will have to select table from the list that you want to replicate.)
  • ID : 1
  • Index : Auto filled when choosing table. That’s important to have a unique constraint on the table you want to replicate (primary key for instance).
  • Comment : a nice comment
  • Press OK.
4 – Create a new Subscription (screen caps below)
  • Source >Replication Set > Subscription and choose New subscription.
  • Origin : write “1”
  • Provider : Choose “1 - Master Node”
  • Receiver : Choose “10 - Slave Node”
  • Can forward : Keep it unchecked
  • Press OK.
Now check path and listen are same in source and target of admin node .If not add master_node (slave_node), slave_node(slave_node) in the target as well .

Start the replication

Go to slon path
/usr/lib/postgresql/9.2/bin bin (or any other location depending on your linux flavour and / or Postgresql installation path). Check that slon is there in the path. This is the slony daemon you will start twice : one for the MASTER(source), the other for the SLAVE (target).

slon syntax :

slon [Options] [ClusterName] [ConnexionInfos]

For the Master :
  • ./slon -d 1 REP_CLUSTER "dbname=source user=postgres host=localhost port=5434"
For the Slave :
  • ./slon -d 1 REP_CLUSTER "dbname=target user=postgres host=localhost port=5434"
Refer to the sample output of source and target .

Test the Replication
Add some data in the details table of source database and check whether it is replicated at the target.

Reference:

Wednesday 17 October 2012

Upgrading pgadmin3 from 1.14 to 1.16

The Ubuntu 12.04 package manager will install pgadmin3 version 1.14 which does not support PostgreSQL 9.2.

Warning:
The server you are connecting to is not a version that is supported by this release of pgAdmin III.
pgAdmin III may not function as expected.
Supported server versions are 8.2 to 9.1.


Remove the current pgAdmin version


sudo apt-get remove pgadmin3


Install pgAdmin version 1.16 using a ppa


sudo apt-add-repository ppa:voronov84/andreyv
sudo apt-get update
sudo apt-get install pgadmin3

Monday 15 October 2012

Solving the problem of browser and open office after upgrading UBUNTU 12.04 FROM 11.10


After upgrading UBUNTU 11.10 to UBUNTU 12.04

I was getting following error while opening any browser and open office


Error: in load: file "/usr/share/uim/lib/sigscheme-init.scm" not found
Error: in load: file "/usr/share/uim/lib/sigscheme-init.scm" not found

To rectify the issue I installed the following package 


sudo apt-get install --reinstall libuim-data