Slony-1 Documentation

[http://slony.info/ Slony-I Docs]

A Bit about Slony-1

Slony-1 is a database replication engine used for Postgres databases. The JSOC will be running Slony-1 to handle remote DRMS, and possibly for its web-based data querying.

There are two different ways to implement Slony-1: "Classic" and "Log-shipping" (note these are not technical terms and are used for purposes of this explanation).

Slony-1 "classic" is the traditional method, and uses all the features that Slony-1 is known for. "Classic" is the original intended use of the product. In a "classic" environment, each Postgres instance to be replicated has Slony-1 fully installed and is designated with a node number. Each node communicates with the other nodes as an equal, via a software process called "slon". Origins and subscribers are defined. Slony-1 can be used in a master-slave configuration, but that is not the model up on which it was designed. The Slony-1 philosophy is that any node can be an origin for some data and a subscriber to other data. Likewise, any node can be all origin or all subscriber. Each slon process must be run as a database superuser, or a user with effectively superuser privileges. Otherwise, the slon process cannot execute the updates, inserts and deletes to keep the subscribers in sync. If all nodes are in-house, powerful access rights across Postgres instances is less of a concern. For the JSOC, with nodes distributed worldwide, "classic" represents a security risk for all distributed nodes. Running in "classic" mode is more complex and requires a tight connection between nodes.

"Log shipping" is the second implementation. It is a sort of an end-around the original software design. Effectively, the slon program "archives" anything done on the node into SQL files ("logs"). These logs are not the same as the Postgres Write-Ahead-Logs (WALs). These logs are text-based SQL commands, and only handle inserts, updates and deletes. Slony-1 logs don't handle, for example, database structural changes, user password changes, create table/drop table commands, new namespaces (schemas), et cetera. Those structural changes must be applied specially using the slonik and SQL languages. To create a log-shipping Postgres instance, one must have at least two nodes running Slony-1 in a "classic" architecture. The output from that will be the logs to be shipped.

One of the benefits of log shipping is that it requires no external systems to have database superuser privileges. It also allows the destination database to pick up logs as desired, instead of constantly receiving updates. The administrator of the slons can decide how frequently logs are created, as well. Network connections between remote sites are no longer time-critical.

JSOC has decided to use Slony-1 in "log shipping" mode. We will have to set up one classic mode cluster to create the logs, but it will contain two nodes only.

To become a recipient of our log-shipping Slony-1 is far less work than creating your own logs to ship to the JSOC. If you wish to regularly ship your data to the JSOC, you will have to set up Slony-1 classic on two instances of Postgres, define a cluster, define sets, and generally have an understanding of how Slony-1 works. To use logs that you have received, one need only apply them to your Postgres instance using "psql -f" in sequence (more on that below).

To use the log-shipping method, first decide if you wish to be a passive receiver or a log shipper. JSOC will be a log-shipper. To generate logs, you must have already installed Slony-1 fully, and designate one node a master node. Then you must create a slave node to receive the master's replications, as a regular Slony-1 node (above). The words master and slave are used here only to give an idea of which node is changing data. In Slony-1 parlance, all nodes are equal, but JSOC will designate a master and a slave.

If a remote system (a "replica" or "remote DRMS") desires only to read (not write) these logs, they have only to run two basic scripts.

The first script, slony1_dump.sh, is run on the JSOC database "slave" node based on the data clusters requested by the remote DRMS site. slony1_dump.sh installs two very basic tables and three functions per cluster (each cluster creates a new namespace):

{{{_jsoc_example.sl_archive_tracking


+


+


_jsoc_example.sl_sequence_offline


+


+



+


+


+


After the tables and functions are created, slony1_dump.sh's output loads the full data available for the cluster. It updates the sl_archive_tracking table to reflect the number of the last log at the time of the data output, and waits for the user to begin loading logs. The Slony-1 log files must be scp'd over from JSOC's file server (method still TBD), and a short looping script employed to apply them. The looping script would be a variant of:

{{{#!/bin/sh -f #Change this to reflect your cluster name, log file location, host, port number, and your user and db name!!! SLONYCLUSTER=jsoc_example ARCHIVEDIR=/surge/slony/jsoc_slave_logs REPLICATIONUSER=postgres PGDATABASE=jsoc PGPORT=5444 PGHOST=myhost.stanford.edu #End your changes FILEPREFIX=slony1_log_2_ NEXTQUERY="select at_counter+1 from \"_${SLONYCLUSTER}\".sl_archive_tracking;" nextseq=psql -d ${PGDATABASE} -p ${PGPORT} -U ${REPLICATIONUSER} -h ${PGHOST} -A -t -c "${NEXTQUERY}" #last_counter=400000 while true; do #while [ $nextseq -lt $last_counter ]; do #Could do fewer selects/psqls I suppose, but better safe than sorry for the time being

done}}}

If a remote replica/DRMS wishes to ship new changes back to the JSOC, they would have to install a traditional Slony-1 setup with a master and log-shipping slave node, and then only ship new data back to the JSOC (e.g. not something the JSOC is already sending as a log to the remote DRMS site). There can only be one origin node for any specific namespace and table (series).

In a traditional Slony-1 setup, changes are replicated across nodes very quickly, at least once per minute. In log-shipping, a new log file can be generated once per minute, or more or less often. As we define the clusters of the JSOC, we will define the frequency of replication log output as well. The size of the log file for a small database with no new activity is ~800 bytes. A log file directing the insertion of 100,000 records into a table with five columns was 9 Mb. The speed of log shipping replication is determined by how often remote users download their logs, the amount of activity in the data tables in the cluster, and network traffic.

A sample of the log file listings for a quiescent sample database: {{{-bash-3.00$ /bin/ls -l | head -10 total 275812 -rw-rw-r-- 1 postgres postgres 698 Jul 24 17:40 slony1_log_2_00000000000000000001.sql -rw-rw-r-- 1 postgres postgres 698 Jul 24 17:40 slony1_log_2_00000000000000000002.sql -rw-rw-r-- 1 postgres postgres 698 Jul 24 17:40 slony1_log_2_00000000000000000003.sql -rw-rw-r-- 1 postgres postgres 698 Jul 24 17:40 slony1_log_2_00000000000000000004.sql -rw-rw-r-- 1 postgres postgres 698 Jul 24 17:41 slony1_log_2_00000000000000000005.sql -rw-rw-r-- 1 postgres postgres 698 Jul 24 17:41 slony1_log_2_00000000000000000006.sql -rw-rw-r-- 1 postgres postgres 698 Jul 24 17:41 slony1_log_2_00000000000000000007.sql -rw-rw-r-- 1 postgres postgres 698 Jul 24 17:41 slony1_log_2_00000000000000000008.sql -rw-rw-r-- 1 postgres postgres 698 Jul 24 17:41 slony1_log_2_00000000000000000009.sql}}}

The following figure is a sketch of our present implementation plan for Slony-1 (as of September 2008). attachment:slony_map1.jpg

Difference Between a Slony-1 Replica and a Warm Standby Server

1. Scope: per-table vs whole database

2. Availability: available vs standby

Replication Lag Requirement

From Phil's notes:

1. Access to quicklook data:

2. Clone for web access:

3. Remote replicas:

Locations of Remote Replicas

0. LM

1. MSSL

2. Germany

3. SAO

4. India

Test Tasks

1. Log shipping

2. What happens when DB server goes down and when DB server reboots

3. How to add tables to replication set while slon daemon is running?

4. Replica DB maintenance? e.g., rebuild index, vacuum, etc.

5. How to copy table schema and role information

6. Is there a way to subscribe to part of a series?

Procedure to Become a Replica

1. Decide whether you wish to simply receive logs, or whether you wish to receive logs and send logs back to the JSOC or another replica. The former is easier for you, but could be limiting. If you want to decide later, and just start with receiving logs, that's fine. You will not lock yourself out of log-shipping later.

2. You will need to understand basic SQL, basic shell scripting, and you will need to have Postgres v8.3 or higher installed. It is recommended that you have some basic understanding of how Postgres works, how to log into it, and how to check its health.

3. Figure out what data sets you would like to receive and whether you have the space to do so. Make a list of those data sets, by namespace.series_name. Soon, the JSOC team will be able to respond to your request and make a slon demon for your job. If you are already a replica site receiving Slony-1 logs from JSOC, then you need to check with the person who is managing that process first.

4. More To Be Determined as we at JSOC progress with implementing Slony-1 log shipping.