Wednesday, June 06, 2007

Slony install on Debian Etch

installing the base packages.

apt-get install postgresql-8.1 postgresql-doc-8.1 postgresql-contrib-8.1 build-essential postgresql-server-dev-8.1

download the latest version of slony1 into /usr/local/src

cd /usr/local/src
cd slony1-1.2.9

./configure --prefix=/usr/local/slony1-1.2.9 --with-perltools
make
make install

cd /usr/local/
rm slony1
ln -s slony1-1.2.9/ slony1

edit the postgres settings

vi /etc/postgresql/8.1/main/postgresql.conf

add the following line to the above config file
listen_addresses = '*'

vi /etc/postgresql/8.1/main/pg_hba.conf
add the following lines for user authentication.

#################### Custom User settings ##################################
#
# TYPE DATABASE USER CIDR-ADDRESS METHOD
#
local all postgres trust
host all postgres 192.168.255.0/24 trust
host all all 192.168.1.0/24 password

restart postgresql server

On the master Postgres database do the following

su - postgres
createdb slonytest
createlang plpgsql slonytest

psql slonytest
create sequence contact_seq start with 1;
create table contact (
cid int4 primary key,
name varchar(50),
address varchar(255),
phonenumber varchar(15)
);
insert into contact (cid, name, address,phonenumber) values ((select nextval('contact_seq')), 'Joe', '1 Foo Street', '(592) 471-8271');
insert into contact (cid, name, address,phonenumber) values ((select nextval('contact_seq')),'Robert', '4 Bar Roard', '(515) 821-3831');
insert into contact (cid, name, address,phonenumber) values ((select nextval('contact_seq')), 'Sushil', '510 Lordship lane', '(590) 441-8771');

On the Slave issue the following commands

su - postgres
createdb slonytest
pg_dump -s -h pdb0x slonytest | psql -h pdb1x slonytest

the last command will dump the schema and import it into the replication slave.

on both machines..
mkdir /etc/slony1
create slon_tools.conf files in etc/slony1
mkdir /etc/slony1/slonytest
the slonytest directory will contain the slon.conf file used for startint the slony daemon.

On MASTER

slonik_init_cluster --config /etc/slony1/slon_tools.conf-slonytest | slonik
slonik_create_set --config /etc/slony1/slon_tools.conf-slonytest set1 | slonik

start the slony daemon

ON SLAVE

start the slony daemon

slonik_subscribe_set --config /etc/slony1/slon_tools.conf-slonytest set1 node2 | slonik



______________________________________________________________

As per request i am pasting a sample slony_tools.conf file I used.

This configuration file was used to cluster sample posgress database called dellstore.
I can't remember from where i downloaded the database.

_____________________slony_tool.conf___________________

# $Id: slon_tools.conf-sample,v 1.7 2005/11/15 18:09:59 cbbrowne Exp $
# Author: Christopher Browne
# Copyright 2004 Afilias Canada
# Revised extensively by Steve Simms

# Keeping the following three lines for backwards compatibility in
# case this gets incorporated into a 1.0.6 release.
#
# TODO: The scripts should check for an environment variable
# containing the location of a configuration file. That would
# simplify this configuration file and allow Slony-I tools to still work
# in situations where it doesn't exist.
#
if ($ENV{"SLONYNODES"}) {
require $ENV{"SLONYNODES"};
} else {

# The name of the replication cluster. This will be used to
# create a schema named _$CLUSTER_NAME in the database which will
# contain Slony-related data.
$CLUSTER_NAME = 'replicdell';

# The directory where Slony should record log messages. This
# directory will need to be writable by the user that invokes
# Slony.
$LOGDIR = '/var/log/slony1';

# SYNC check interval (slon -s option)
# $SYNC_CHECK_INTERVAL = 1000;

# Which node is the default master for all sets?
$MASTERNODE = 1;

# Include add_node lines for each node in the cluster. Be sure to
# use host names that will resolve properly on all nodes
# (i.e. only use 'localhost' if all nodes are on the same host).
# Also, note that the user must be a superuser account.

add_node(node => 1,
host => 'pdb0',
dbname => 'dellstore2',
port => 5432,
user => 'postgres',
password => '');

add_node(node => 2,
host => 'pdb1',
dbname => 'dellstore2',
port => 5432,
user => 'postgres',
password => '');

}

# The $SLONY_SETS variable contains information about all of the sets
# in your cluster.

$SLONY_SETS = {

# A unique name for the set
"set1" => {

# The set_id, also unique
"set_id" => 1,

# Uncomment the following line to change the origin
# (a.k.a. master) for the set. The default is $MASTERNODE.
#
"origin" => 1,

# If this is set to 1, table and sequence names will be folded to lower-case
# to match the way that PostgreSQL handles unquoted names.
# For example, CREATE TABLE ACCOUNT(...) actually turns into CREATE TABLE account(...);
# unless you put quotes around the table name
# Slony always quotes object names, so you may get a mis-match between the table-name
# as PostgreSQL understands it, and as Slony represents it.
# default value is 0
#
# foldCase => 0,

# The first ID to use for tables and sequences that are added
# to the replication cluster. This must be unique across the
# cluster.
#
# TODO: This should be determined automatically, which can be
# done fairly easily in most cases using psql. create_set
# should derive it, and give an option to override it with a
# specific value.
"table_id" => 1,
"sequence_id" => 1,

# This array contains a list of tables that already have
# primary keys.
"pkeyedtables" => [
'categories',
'customers',
'inventory',
'orders',
'products',
],

# For tables that have unique not null keys, but no primary
# key, enter their names and indexes here.
# "keyedtables" => {
# 'table3' => 'index_on_table3',
# 'table4' => 'index_on_table4',
# },

# If a table does not have a suitable key or set of keys that
# can act as a primary key, Slony can add one.
#
# Note: The Slony development team does not recomment this
# approach -- you should create your own primary keys instead.
"serialtables" => ["reorder",
"cust_hist",
"orderlines",
],

# Sequences that need to be replicated should be entered here.
"sequences" => ['categories_category_seq',
'customers_customerid_seq',
'orders_orderid_seq',
'products_prod_id_seq',
],
},

};

# Keeping the following three lines for backwards compatibility in
# case this gets incorporated into a 1.0.6 release.
#
# TODO: The scripts should check for an environment variable
# containing the location of a configuration file. That would
# simplify this configuration file and allow Slony tools to still work
# in situations where it doesn't exist.
#
if ($ENV{"SLONYSET"}) {
require $ENV{"SLONYSET"};
}

# Please do not add or change anything below this point.
1;

___________________________________________________

2 comments:

  1. timballDec 10, 2008 02:47 PM
    what does slon_tools.conf or any of the slony config files look like?

    --timball
    ReplyDelete
  2. SushilDec 11, 2008 12:25 AM
    Hi,
    Let me see if i can dig out some of my old slony configuration file..

    I should have them somewhere.. stashed away.. If i can i will post them here in a day or two.

    On a side note, PgCluster has been developed quite a bit. When i first tried slony, pgcluster was far from being usable, but it is worth a try now.
    ReplyDelete