HiveBrain v1.2.0
Get Started
← Back to all entries
debugsqlModerate

PostgreSQL: Unable to run repmgr cloned database

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqlunabledatabaseclonedrepmgrrun

Problem

I'm running tests with PostgreSQL hot standby with 1 master, and exactly 1 slave.

I am using the instructions on this guide: http://www.howtoforge.com/how-to-set-up-a-postgresql-9.0-hot-standby-streaming-replication-server-with-repmgr-on-opensuse-11.4

I'm using PostgreSQL version 9.1, repmgr 1.1.0 and Ubuntu 10.04 LTS.

I followed steps upto step-6 in the guide where I ran

repmgr -D /var/lib/postgresql/9.1/main -d pgbench -p 5432 -R postgres --verbose standby clone pgmaster


on pgslave.

Then I did a

/etc/init.d/postgresql start


on it and it the script (seemingly) finished successfully.

However, executing psql throws error:


psql: FATAL: the database system is starting up

Any help on proceeding further is welcome.

Solution

I searched around and realized that the problem was due to not enabling hot_standby on the standby server. I wrote a corrected, updated and simplified version of the above article as an odt for future personal reference. Here is the text in its entirety (converted to html from odt using openoffice.org) for those who are interested in setting up a single read-only clone of a database using repmgr:

Single Slave Streaming Replication with
PostgreSQL

Introduction
This guide aims to quickly help you configure a PostgreSQL 9.1
server with a database, and have it replicated to a slave that can be
used for read-only queries. There is no concept of failover involved
here, and the slave will only have a read-only copy of the master's
data.

  1. Tools Needed



A stable GNU/Linux Distribution (Recommended OS: CentOS 6.2 x86-64)
PostgreSQL 9.1 – you may install from here: http://yum.postgresql.org/ (also make sure that the following packages or their equivalnets are installed)

postgresql
postgresql-client
postgresql-contrib
postgresql-server
postgresql-server-dev
2 workstations – a master that runs the primary database
and a slave that runs the replicated read-only database (for the
purpose of this document, their respective IP addresses have been
replaced with pgmaster and pgslave so
make those changes in /etc/hosts of both machines if you want to
follow the following instructions word for word)

  1. Installation Check and Password Creation



Run /etc/init.d/postgresql start on both systems to check if PostgreSQL is functional or not.
Run /etc/init.d/postgresql stop on both systems to stop PostgreSQL. We will not be using PostgreSQL till we finish some configuration related tasks.
Set a password for user postgres on both the systems. This user by default has no password, but we need a password to help create an SSH tunnel between pgmaster and pgslave.
Run sudo passwd postgres on both systems and type a new Unix password for both.

  1. SSH Tunnel Creation



On the pgmaster do the following:
su postgres
ssh-keygen -t rsa (press enter at every prompt)
ssh-copy-id -i ~/ssh/id_rsa.pub pgslave (you need to enter pgslave's postgres password)
ssh pgslave and see if you are able to login without password
Repeat the above steps on pgslave
su postgres
sh-keygen -t rsa
ssh-copy-id -i ~/ssh/id_rsa.pubaster
ssh pgmaster and see if you are able to login without password
Make sure you log out from the remote machine after you finish checking connectivity

  1. Editing postgresql.conf on pgmaster


You need to make the following changes in the file
postgresql.conf that resides in the configuration
directory inside /etc/postgresql/
on your machine pgmaster:

listen_addresses = '*'
wal_level = hot_standby
checkpoint_segments=30
archive_mode=on
archive_command='cd .'
max_wal_senders=2
wal_keep_segments=5000

  1. Editing postgresql.conf on pgslave


You need to make the following change in the file postgresql.conf
that resides in the configuration directory inside /etc/postgresql/
on machine pgslave:

hot_standby=on

  1. Editing pg_hba.conf on pgmastger


You need to make the following changes in the file pg_hba.conf
that resides in the configuration directory inside /etc/postgresql/
on machine pgmaster:

host all all 192.168.5.0/24 trust
host replication all 192.168.5.0/24 trust

  1. Adding PostgreSQL bin folder to PATH


There are a bunch of nifty postgresql utilities we will be using
here, so lets set the PATH variable so that it knows where to find
them

Execute locate pgbench
The output will be something like /usr/lib/postgresql/9.1/bin/pgbench
Excluding final word pgbench, copy the above path and add it to your path variable.
Execute nano ~/.bashrc
add line export PATH+=:/usr/lib/postgresql/9.1/bin/ (or whatever location the locate command revealed)
Close the file and save changes
You may need to log out and login (or open a new shell) for changes to take effect.

  1. Loading pgmaster's PostgreSQL server with


dummy data

On pgmaster start the PostgreSQL server first: /etc/init.d/postgresql start
We create a test database and load it with some dummy data with the following commands:

su postgres
createdb pgbench
pgbench -i -s 10 pgbench

Alternatively open the database pgbench yourself, create a sample table and insert sample data into it.

  1. Erasing pgslave's data and checking pgmaster


connectivity

We are going to erase data directory of pgslave, so execute following on that machine:
First stop PostgreSQL server /etc/init.d/postgresql stop
Move into the PostgreSQL default data directory folder: cd /var/lib/pgsql/data (or to the data directory that is default for your installation)
Empty the directory completely with rm -rf *
Now execute psql -h pgmaster -d pgbench and see if you are

Context

StackExchange Database Administrators Q#15055, answer score: 12

Revisions (0)

No revisions yet.