Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Replica de Base de Datos en PostgreSQL
Replica de Base de Datos en PostgreSQL
Replicacin.- Proceso por el cual se desea mantener y copiar los datos de una base
de datos de manera que estos datos son transportados y son almacenados.
Software
El software que utilizaremos en esta oportunidad es Slony-I para windows, el cual permite
la replicacin basada en triggers de forma asncrona. Utiliza un simple master para mltipes
esclavos (nodos suscriptores).
Cada tabla o secuencia en el master podra ser replicada va triggers remotos a los esclavos.
Actulizaciones son realizadas en la base de datos y luegos son replicadas mediante eventos.
Una replicacin basada en triggers usa on insert, on update, on delete en las tablas para
mantener la replicacin entre el nodo master y esclavo.
Limitaciones
Ventajas
Desventajas
Descargar slony desde: http://slony.info/ para windows, en linux tiene otro proceso que
espero tambin ponerlo en otro post.
Instalacin y configuracin
1. Instalar Slony-I en el nodo maestro y esclavo, para esto lo podemos hacer desde el Stack
Builder de PostgreSQL.
2. Configurar el fichero pg_hba.conf del nodo maestro y esclavo aadiendo la siguiente
informacin:
#maestro
host all all 192.168.1.34/32 md5
#esclavo
host all all 192.168.1.63/32 md5
#--
# admin conninfo's are used by slonik to connect to the nodes one for
each
# node on each side of the cluster, the syntax is that of PQconnectdb in
# the C-API - replace the parameters which are appropriate for your setup
#
# this section tells slonik how to connect to the various nodes when
running
# this script.
# --
#--
# init the first node. Its id MUST be 1. This creates the schema
# _$CLUSTERNAME containing all replication system specific database
# objects.
#--
init cluster ( id=1, comment = 'Nodo Maestro');
#--
# this is an example of how to work around a table that has no primary
key
# and is based on an example by Robert Treat. The history table referred
to
# is one of the tables being replicated.
#
# Because the history table does not have a primary key or other unique
# constraint that could be used to identify a row, we need to add one.
# The following command adds a bigint column named
# _Slony-I_$CLUSTERNAME_rowID to the table. It will have a default value
# of nextval('_$CLUSTERNAME.s1_rowid_seq'), and have UNIQUE and NOT NULL
# constraints applied. All existing rows will be initialized with a
# number
#--
# Traduccin: Esto solo es necesario usarlo si tienes una tabla que no
tenga una llave primaria, procura hacer un buen diseo en tu base de
datos.
#--
# Slony-I organizes tables into sets. The smallest unit a node can
# subscribe is a set. The following commands create one set containing
# all tables to be replicated. Tables not named here will not be
replicated.
# The master or origin of the set is node 1. Note that the second id must
be
# incremented for each table added.
#--
set add table (set id=1, origin=1, id=1, fully qualified name =
'public.employees',comment='mi tabla empleado');
set add table (set id=1, origin=1, id=2, fully qualified name =
'public.departments',comment='mi tabla departamento');
#--
# Create the second node (the slave) tell the 2 nodes how to connect to
# each other and how they should listen for events.
# we have to repeat the conninfo detils here, because these details are
written into
# the slony database.
#--
#########################################################################
#############
# slonik maestro.txt
Si todo sale bien no debers ningn mensaje de error en consola de windows como
resultado de ejecutar la sentencia anterior y poder ver configurado slony en el nodo
maestro.
Ahora el comando tambin debe de haber creado el cluster en el nodo esclavo, para ello
verificamos:
10. Desde el nodo subscriptor (esclavo) y en el directorio c:\Program
Files\PostgreSQL\8.3\bin ejecutar:
# slonik esclavo.txt
Pruebas
En el nodo maestro abrir la base de datos HR e ingresar un registro a la tabla employees
como sigue:
Verificamos en el esclavo: