Christopher B. Browne's Home Page

4.3. Monitoring

As a prelude to the discussion, it is worth pointing out that since the bulk of Slony-I functionality is implemented via running database functions and SQL queries against tables within a Slony-I schema, most of the things that one might want to monitor about replication may be found by querying tables in the schema created for the cluster in each database in the cluster.

Here are some of the tables that contain information likely to be particularly interesting from a monitoring and diagnostic perspective.


This view is the first, most obviously useful thing to look at from a monitoring perspective. It looks at the local node's events, and checks to see how quickly they are being confirmed on other nodes.

The view is primarily useful to run against an origin ("master") node, as it is only there where the events generated are generally expected to require interesting work to be done. The events generated on non-origin nodes tend to be SYNC events that require no replication work be done, and that are nearly no-ops, as a result.


Contains confirmations of replication events; this may be used to infer which events have, and have not been processed.


Contains information about the replication events processed on the local node.

sl_log_1 and sl_log_2

These tables contain replicable data. On an origin node, this is the "queue" of data that has not necessarily been replicated everywhere. By examining the table, you may examine the details of what data is replicable.


The list of nodes in the cluster.


This table holds connection information indicating how slon(1) processes are to connect to remote nodes, whether to access events, or to request replication data.


This configuration table indicates how nodes listen for events coming from other nodes. Usually this is automatically populated; generally you can detect configuration problems by this table being "underpopulated."


A configuration table that may be used to store miscellaneous runtime data. Presently used only to manage switching between the two log tables.


Contains the "last value" of replicated sequences.


Contains definition information for replication sets, which is the mechanism used to group together related replicable tables and sequences.


Contains information about the state of synchronization of each replication set, including transaction snapshot data.


Indicates what subscriptions are in effect for each replication set.


Contains the list of tables being replicated.

4.3.1. test_slony_state

This invaluable script does various sorts of analysis of the state of a Slony-I cluster. Some administrators recommend running these scripts frequently (hourly seems suitable) to find problems as early as possible.

You specify arguments including database, host, user, cluster, password, and port to connect to any of the nodes on a cluster. You also specify a mailprog command (which should be a program equivalent to Unix mailx) and a recipient of email.

You may alternatively specify database connection parameters via the environment variables used by libpq, e.g. - using PGPORT, PGDATABASE, PGUSER, PGSERVICE, and such.

The script then rummages through sl_path to find all of the nodes in the cluster, and the DSNs to allow it to, in turn, connect to each of them.

For each node, the script examines the state of things, including such things as:

The script does some diagnosis work based on parameters in the script; if you don't like the values, pick your favorites!


Note that there are two versions, one using the "classic" Perl module for accessing PostgreSQL databases, and one, with dbi in its name, that uses the newer Perl DBI interface. It is likely going to be easier to find packaging for DBI.

4.3.2. Nagios Replication Checks

The script in the tools directory called represents some of the best answers arrived at in attempts to build replication tests to plug into the Nagios system monitoring tool.

A former script,, took a "clever" approach where a "test script" is periodically run, which rummages through the Slony-I configuration to find origin and subscribers, injects a change, and watches for its propagation through the system. It had two problems:

The new script,, takes the minimalist approach of assuming that the system is an online system that sees regular "traffic," so that you can define a view specifically for the replication test called replication_status which is expected to see regular updates. The view simply looks for the youngest "transaction" on the node, and lists its timestamp, age, and some bit of application information that might seem useful to see.

An instance of the script will need to be run for each node that is to be monitored; that is the way Nagios works.

4.3.3. Monitoring Slony-I using MRTG

One user reported on the Slony-I mailing list how to configure mrtg - Multi Router Traffic Grapher to monitor Slony-I replication.

... Since I use mrtg to graph data from multiple servers I use snmp (net-snmp to be exact). On database server, I added the following line to snmpd configuration:

    exec replicationLagTime  /cvs/scripts/ 2
    where  /cvs/scripts/ looks like this:
    /home/pgdba/work/bin/psql -U pgdba -h -p 5800 -d _DBNAME_ -qAt -c
    "select cast(extract(epoch from st_lag_time) as int8) FROM _irr.sl_status
    WHERE st_received = $1"

Then, in mrtg configuration, add this target:

    Target[db_replication_lagtime]:extOutput.3&extOutput.3:public at db::30:::
    MaxBytes[db_replication_lagtime]: 400000000
    Title[db_replication_lagtime]: db: replication lag time
    PageTop[db_replication_lagtime]: <H1>db: replication lag time</H1>
    Options[db_replication_lagtime]: gauge,nopercent,growright

Alternatively, Ismail Yenigul points out how he managed to monitor slony using MRTG without installing SNMPD.

Here is the mrtg configuration

    Target[db_replication_lagtime]:`/bin/ 2`
    MaxBytes[db_replication_lagtime]: 400000000
    Title[db_replication_lagtime]: db: replication lag time
    PageTop[db_replication_lagtime]: <H1>db: replication lag time</H1>
    Options[db_replication_lagtime]: gauge,nopercent,growright

and here is the modified version of the script

    # cat /bin/
    output=`/usr/bin/psql -U slony -h -d endersysecm -qAt -c
    "select cast(extract(epoch from st_lag_time) as int8) FROM _mycluster.sl_status WHERE st_received = $1"`
    echo $output
    echo $output
    # end of script#


MRTG expects four lines from the script, and since there are only two lines provided, the output must be padded to four lines.

4.3.4. Bucardo-related Monitoring

The Bucardo replication system includes script,, which can monitor a variety of things about PostgreSQL status that includes monitoring Slony-I replication status; see - slony_status


This script is constructed to search for Slony-I log files at a given path (LOGHOME), based both on the naming conventions used by the Section 7.1.4 and Section systems used for launching slon(1) processes.

Errors, if found, are listed, by log file, and emailed to the specified user (LOGRECIPIENT); if no email address is specified, output goes to standard output.

LOGTIMESTAMP allows overriding what hour to evaluate (rather than the last hour).

An administrator might run this script once an hour to monitor for replication problems.

4.3.6. Building MediaWiki Cluster Summary

The script , in tools, may be used to generate a cluster summary compatible with the popular MediaWiki software. Note that the --categories permits the user to specify a set of (comma-delimited) categories with which to associate the output. If you have a series of Slony-I clusters, passing in the option --categories=slony1 leads to the MediaWiki instance generating a category page listing all Slony-I clusters so categorized on the wiki.

The gentle user might use the script as follows:

    ~/logtail.en>         mvs login -d -u "Chris Browne" -p `cat ~/.wikipass` -w wiki/index.php                     
    Doing login with host: logtail and lang: en
    ~/logtail.en> perl $SLONYHOME/tools/ --host localhost --database slonyregress1 --cluster slony_regress1 --categories=Slony-I  >
    ~/logtail.en> mvs commit -m "More sophisticated generated Slony-I cluster docs"
    Doing commit with host: logtail and lang: en

Note that mvs is a client written in Perl; on Debian GNU/Linux, the relevant package is called libwww-mediawiki-client-perl; other systems may have a packaged version of this under some similar name.

4.3.7. Analysis of a SYNC

The following is (as of 2.0) an extract from the slon(1) log for node #2 in a run of "test1" from the regression tests.

    DEBUG2 remoteWorkerThread_1: SYNC 19 processing
    INFO   about to monitor_subscriber_query - pulling big actionid list 134885072
    INFO   remoteWorkerThread_1: syncing set 1 with 4 table(s) from provider 1
    DEBUG2  ssy_action_list length: 0
    DEBUG2 remoteWorkerThread_1: current local log_status is 0
    DEBUG2 remoteWorkerThread_1_1: current remote log_status = 0
    DEBUG1 remoteHelperThread_1_1: 0.028 seconds delay for first row
    DEBUG1 remoteHelperThread_1_1: 0.978 seconds until close cursor
    INFO   remoteHelperThread_1_1: inserts=144 updates=1084 deletes=0
    INFO   remoteWorkerThread_1: sync_helper timing:  pqexec (s/count)- provider 0.063/6 - subscriber 0.000/6
    INFO   remoteWorkerThread_1: sync_helper timing:  large tuples 0.315/288
    DEBUG2 remoteWorkerThread_1: cleanup
    INFO   remoteWorkerThread_1: SYNC 19 done in 1.272 seconds
    INFO   remoteWorkerThread_1: SYNC 19 sync_event timing:  pqexec (s/count)- provider 0.001/1 - subscriber 0.004/1 - IUD 0.972/248

Here are some notes to interpret this output:

Contact me at