Package: pg_fabrep
Introductionpg_fabrep allow you to easy setup aPostgresql9.xHot Standby Streaming ReplicationServer WithRepmgr.Patches are welcome! Feel free to fork and contribute to this project on:bitbucket:bitbucket.org/DNX/pg_fabrepgithub:github.com/DNX/pg_fabrepInstallationThere are a few different ways to install pg_fabrep:Using pipIf you have pip install available on your system, just type:pip install pg_fabrepIf you’ve already got an old version of pg_fabrep, and want to upgrade, use:pip install -U pg_fabrepInstalling from a directoryIf you’ve obtained a copy of pg_fabrep using either Mercurial or a downloadable
archive, you’ll need to install the copy you have system-wide. Try running:python setup.py developIf that fails, you don’t havesetuptoolsor an equivalent installed;
either install them, or run:python setup.py installHow to use pg_fabrep?If you have already installed pg_fabrep, you must proceed with the
configuration of your cluster.ConfigurationCopy the scheleton for your cluster settings from <pg_fabrep> path:$ cp <pg_fabrep>/example_fabfile.py <your_project>/fabfile.pyHow to find your <pg_fabrep> path? Just run:$ python -c "import pg_fabrep; print(pg_fabrep.__path__)"or directly:$ cppython -c “import pg_fabrep; print(pg_fabrep.__path__[0])”/example_fabfile.py <your_project>/fabfile.pyIn order to startsetuptask you must change only two parameters,pgmaster_ipandpgslave_ipinside you cluster configuration task in earlier createdfabfile.py, all other parameters have default
values and if you need you can change them too.Here is a list with all parameters you can change and a short explanation for each:env.configured, don’t change this, used for testing purposesenv.postgres_version, postgres version, can be: “9.0” or “9.1”, default: “9.1”env.cluster_name, name of your cluster - only numbers, letters and underscores, default: mainenv.cluster_port, postgres cluster port, default: 5432env.pgmaster_ip, the IP of your master serverenv.master_ssh_port, ssh port on the master server, will be used by repmgr/rsync from the slave to sync the files from the master, default: 22env.master_node_number, master node number, default: 1env.pgmaster_user_host,user@hostused by fabric to establish a ssh tunnel between the machine from where the “setup” is launched and the master server, default: “root@<env.pgmaster_ip>”env.master_pgconf_path, master pgconf path, default: “/etc/postgresql/<env.postgres_version>/<cluster_name>/”env.master_pgdata_path, master pgdata path, default: “/var/lib/postgresql/<env.postgres_version>/<env.cluster_name>/”env.pgslave_ip, the IP of your slave serverenv.slave_node_number, slave node number, default: 2env.pgslave_user_host,user@hostused by fabric to establish a ssh tunnel between the machine from where the “setup” is launched and the slave server, default: “root@<env.pgslave_ip>”env.slave_pgconf_path, slave pgconf path, default: “<env.master_pgconf_path>”env.slave_pgdata_path, slave pgdata path, default: “<env.master_pgdata_path>”env.sync_db, sync database used by repmgr, will be created if not exists, default: “syncdb”env.sync_user, sync postgres user used by repmgr, will be created if not exists, default: “syncuser”env.sync_pass, sync postgres user password, default: “syncpass”env.repmgr_deb, repmgr_deb installer, default:”postgresql-repmgr-<env.postgres_version>_1.0.0.deb”env.ask_confirmation, always ask user for confirmation when run any tasks, default: TruePlease pay attention to not have any tasks in your fabfile.py called:setuptest_configurationorprint_configurationbecause these names are reserved by pg_fabrep.Test your configuration first!pg_fabrep come with its own automatic configuration tests. Each time you runsetuptask, configuration tests are called.
Anyway, you can manually run these tests for your project configuration:fab <cluster_task_name> test_configurationIf you runtest_configurationmanually, you’ll observe some output about all your project settings.Do you need an example?Ok, let’s assume you want to configure a cluster called “cluster5444”.
So, what we know about it?
we know:the cluster is calledcluster123the postgres version we want to be used is 9.1the ip of the master server is:11.11.11.11the ip of the slave server is:22.22.22.22the port to be used in your cluster is 5444on each server is installed ubuntu serverOk, it’s enough to setup the replication, let’s do it!
Create a folder to place you cluster settings:$ mkdir ~/clusters/
$ cd ~/clusters/copy here the example_fabfile.py from <pg_fabrep>:# we found pg_fabrep installation path first
$ python -c "import pg_fabrep; print(pg_fabrep.__path__)"
$ cp <pg_fabrep>/example_fabfile.py fabfile.pynow, in our current folder we have a file calledfabfile.pywhich is going to be edited according with our needs.Change task name:# from:
def example_cluster():
# to:
def cluster123():Change env.pgmaster_ip:# from:
env.pgmaster_ip = ""
# to:
env.pgmaster_ip = "11.11.11.11"Change env.pgslave_ip:# from:
env.pgslave_ip = ""
# to:
env.pgslave_ip = "22.22.22.22"not, let’s test our configuration:fab cluster123 test_configurationyou must see a message:Configuration tests passed!Setup your replicationAssuming you’ve set your cluster details in the fabfile.py now you are ready to launch the setup:fab cluster123 setupduring this process you can see all the output of the commands launched on
the master and slave servers. At some point you may be asked for some
information as sudo user password.
At the end of this task you must view a message saying that the setup
successful ended.
Now you can go on with the real tests of the replication.