Starting & Stopping Replication

2.2. Starting & Stopping Replication

The slon program is a daemon process that replicates data from one machine to another. The slon process is responsible for the following tasks

  • Generating 'SYNC' events on the local database

  • Processing events from remote nodes.

  • Applying the updates pulled from a remote database to user tables to the local database.

  • Performing cleanup tasks

2.2.1. Deploying Slon Processes

Each database in your cluster needs a slon process which it will act as the "node controller" for. The slon instance will consider itself "local" to that database and establish "remote" connections to any other databases for which a SLONIK STORE PATH has been defined.

The slon process for a particular database does not need to run on the same server as the database. It is recommended (for performance reasons) that the network connection between slon process and "local" database fairly fast but this is not required. One common way of deploying Slony-I is to have the slon process running on the same node as the database it is servicing. Another common deployment is to centralize the slon processes for all of the databases in a particular data-center on a single administrative server.

It is important that the network connection between the slon processes and the database servers it talks to be reliable. If the network connection goes away at the wrong time it can leave the database connection in a "zombied". Restarting the slon process will repair this situation.

2.2.2. Starting Slon On Unix Systems

The slon process gets installed in your PostgreSQL bin directory, this is the same directory that psql and the postgres binary get installed into. On a Unix system (including Linux variants) slon can be started either:

  • Manually through the command line by invoking "slon" directly.

  • By using the rc.d style script found in the tools directory of the Slony-I source distribution. Invoking slon Directly

To invoke slon directly you would execute the command

slon slony_example 'host=localhost dbname=pgbench user=pgbench'

See slon for information on command line options.

To start slon via the script you will first need to create a slon.conf file with the configuration options for slon. This is an example of a simple slon.conf file

conn_info=host=localhost dbname=pgbench user=pgbench

You would then set the SLON_CONF environment variable to point at this file and start the slon.

export SLON_BIN=/usr/local/pgsql8.3/bin/slon
export SLON_CONF=/etc/slon/slon.conf
export SLON_LOG=/var/log/slon.log
/usr/local/pgsql8.3/bin/ start

2.2.3. Stopping Slon On a Unix System

On a Unix system the slon process (called the watchdog) slon will fork creating a child slon process (called the worker) that does all the work. The watchdog monitors the worker and restarts the worker when required. To terminate slon you would send the watchdog slon (the slon process that you started) a SIGTERM. If you started slon through the script then you can stop the slon via the "stop" command.

export SLON_BIN=/usr/local/pgsql8.3/bin/slon
export SLON_CONF=/etc/slon/slon.conf
export SLON_LOG=/var/log/slon.log
/usr/local/pgsql8.3/bin/ stop

2.2.4. Starting Slon On a MS-Windows System

On a MS-Windows system slon needs to be started as a service with a configuration file containing the settings for slon. An example of a configuration file is below.

conn_info=host=localhost dbname=pgbench user=pgbench

You then need to add the slon service

pgsql\lib>regsvr32 slevent.dll

-- running slon
pgsql\bin>slon -regservice Slony-I
pgsql\bin>slon -addengine Slony-I slon.conf
pgsql\bin>slon -listengines Slony-I

2.2.5. Stopping slon On MS-Windows

On MS-Windows the service manager starts slon as a service. This slon processs acts as the slon worker. The service manager will start a new slon whenever the slon worker exists. To stop slon you need to disable the service. This can be done through the service manager GUI or with the following commands

pgsql\bin>slon -delengine Slony-I slon.conf