mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-23 15:16:29 +00:00
Compare commits
21 Commits
v2.0.2
...
REL2_0_STA
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48099e9c5f | ||
|
|
e7ca8c369f | ||
|
|
782fae6239 | ||
|
|
a492745db1 | ||
|
|
9ac066db51 | ||
|
|
20db2f52b1 | ||
|
|
341831ad69 | ||
|
|
e8bc5521a5 | ||
|
|
1d9aacfed9 | ||
|
|
e39ec70ef0 | ||
|
|
196585c78a | ||
|
|
79728ba6dd | ||
|
|
c4a47c467f | ||
|
|
36e5944b2c | ||
|
|
097bbdebfd | ||
|
|
4fa75afa26 | ||
|
|
0aae96008f | ||
|
|
2349e182d2 | ||
|
|
03a8f2eaba | ||
|
|
b6a263a40e | ||
|
|
81050899e8 |
5
HISTORY
5
HISTORY
@@ -1,3 +1,8 @@
|
|||||||
|
2.0.3 2015-04-16
|
||||||
|
Add -S/--superuser option for witness database creation (Ian)
|
||||||
|
Add -c/--fast-checkpoint option for cloning (Christoph)
|
||||||
|
Add option "--initdb-no-pwprompt" (Ian)
|
||||||
|
|
||||||
2.0.2 2015-02-17
|
2.0.2 2015-02-17
|
||||||
Add "--checksum" in rsync when using "--force" (Jaime)
|
Add "--checksum" in rsync when using "--force" (Jaime)
|
||||||
Use createdb/createuser instead of psql (Jaime)
|
Use createdb/createuser instead of psql (Jaime)
|
||||||
|
|||||||
188
QUICKSTART.md
188
QUICKSTART.md
@@ -1,7 +1,7 @@
|
|||||||
repmgr: Quickstart guide
|
repmgr: Quickstart guide
|
||||||
========================
|
========================
|
||||||
|
|
||||||
repmgr is an open-source tool suite for mananaging replication and failover
|
`repmgr` is an open-source tool suite for mananaging replication and failover
|
||||||
among multiple PostgreSQL server nodes. It enhances PostgreSQL's built-in
|
among multiple PostgreSQL server nodes. It enhances PostgreSQL's built-in
|
||||||
hot-standby capabilities with a set of administration tools for monitoring
|
hot-standby capabilities with a set of administration tools for monitoring
|
||||||
replication, setting up standby servers and performing failover/switchover
|
replication, setting up standby servers and performing failover/switchover
|
||||||
@@ -14,14 +14,14 @@ covering setup on a variety of different systems, see the README.rst file.
|
|||||||
Conceptual Overview
|
Conceptual Overview
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
repmgr provides two binaries:
|
`repmgr` provides two binaries:
|
||||||
|
|
||||||
- `repmgr`: a command-line client to manage replication and repmgr configuration
|
- `repmgr`: a command-line client to manage replication and `repmgr` configuration
|
||||||
- `repmgrd`: an optional daemon process which runs on standby nodes to monitor
|
- `repmgrd`: an optional daemon process which runs on standby nodes to monitor
|
||||||
replication and node status
|
replication and node status
|
||||||
|
|
||||||
Each PostgreSQL node requires a repmgr configuration file; additionally
|
Each PostgreSQL node requires a `repmgr.conf` configuration file; additionally
|
||||||
it must be "registered" using the repmgr command-line client. repmgr stores
|
it must be "registered" using the `repmgr` command-line client. `repmgr` stores
|
||||||
information about managed nodes in a custom schema on the node's current master
|
information about managed nodes in a custom schema on the node's current master
|
||||||
database.
|
database.
|
||||||
|
|
||||||
@@ -29,33 +29,33 @@ database.
|
|||||||
Requirements
|
Requirements
|
||||||
------------
|
------------
|
||||||
|
|
||||||
repmgr works with PostgreSQL 9.0 and later. All server nodes must be running the
|
`repmgr` works with PostgreSQL 9.0 and later. All server nodes must be running the
|
||||||
same PostgreSQL major version, and preferably should be running the same minor
|
same PostgreSQL major version, and preferably should be running the same minor
|
||||||
version.
|
version.
|
||||||
|
|
||||||
repmgr will work on any Linux or UNIX-like environment capable of running
|
`repmgr` will work on any Linux or UNIX-like environment capable of running
|
||||||
PostgreSQL. rsync must also be installed.
|
PostgreSQL. `rsync` must also be installed.
|
||||||
|
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
------------
|
------------
|
||||||
|
|
||||||
repmgr must be installed on each PostgreSQL server node.
|
`repmgr` must be installed on each PostgreSQL server node.
|
||||||
|
|
||||||
* Packages
|
* Packages
|
||||||
- RPM packages for RedHat-based distributions are available from PGDG
|
- RPM packages for RedHat-based distributions are available from PGDG
|
||||||
- Debian/Ubuntu provide .deb packages.
|
- Debian/Ubuntu provide .deb packages.
|
||||||
|
|
||||||
It is also possible to build .deb packages directly from the repmgr source;
|
It is also possible to build .deb packages directly from the `repmgr` source;
|
||||||
see README.rst for further details.
|
see README.rst for further details.
|
||||||
|
|
||||||
* Source installation
|
* Source installation
|
||||||
- repmgr source code is hosted at github (https://github.com/2ndQuadrant/repmgr);
|
- `repmgr` source code is hosted at github (https://github.com/2ndQuadrant/repmgr);
|
||||||
tar.gz files can be downloaded from https://github.com/2ndQuadrant/repmgr/releases .
|
tar.gz files can be downloaded from https://github.com/2ndQuadrant/repmgr/releases .
|
||||||
|
|
||||||
repmgr can be built easily using PGXS:
|
`repmgr` can be built easily using PGXS:
|
||||||
|
|
||||||
sudo make USE_PGXS=1 install
|
sudo make USE_PGXS=1 install
|
||||||
|
|
||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
@@ -64,42 +64,42 @@ Configuration
|
|||||||
### Server configuration
|
### Server configuration
|
||||||
|
|
||||||
Password-less SSH logins must be enabled for the database system user (typically `postgres`)
|
Password-less SSH logins must be enabled for the database system user (typically `postgres`)
|
||||||
between all server nodes to enable repmgr to copy required files.
|
between all server nodes to enable `repmgr` to copy required files.
|
||||||
|
|
||||||
### PostgreSQL configuration
|
### PostgreSQL configuration
|
||||||
|
|
||||||
The master PostgreSQL node needs to be configured for replication with the
|
The master PostgreSQL node needs to be configured for replication with the
|
||||||
following settings:
|
following settings:
|
||||||
|
|
||||||
wal_level = 'hot_standby' # minimal, archive, hot_standby, or logical
|
wal_level = 'hot_standby' # minimal, archive, hot_standby, or logical
|
||||||
archive_mode = on # allows archiving to be done
|
archive_mode = on # allows archiving to be done
|
||||||
archive_command = 'cd .' # command to use to archive a logfile segment
|
archive_command = 'cd .' # command to use to archive a logfile segment
|
||||||
max_wal_senders = 10 # max number of walsender processes
|
max_wal_senders = 10 # max number of walsender processes
|
||||||
wal_keep_segments = 5000 # in logfile segments, 16MB each; 0 disables
|
wal_keep_segments = 5000 # in logfile segments, 16MB each; 0 disables
|
||||||
hot_standby = on # "on" allows queries during recovery
|
hot_standby = on # "on" allows queries during recovery
|
||||||
|
|
||||||
Note that repmgr expects a default of 5000 wal_keep_segments, although this
|
Note that `repmgr` expects a default of 5000 wal_keep_segments, although this
|
||||||
value can be overridden when executing the `repmgr` client.
|
value can be overridden when executing the `repmgr` client.
|
||||||
|
|
||||||
Additionally, repmgr requires a dedicated PostgreSQL superuser account
|
Additionally, `repmgr` requires a dedicated PostgreSQL superuser account
|
||||||
and a database in which to store monitoring and replication data. The repmgr
|
and a database in which to store monitoring and replication data. The `repmgr`
|
||||||
user account will also be used for replication connections from the standby,
|
user account will also be used for replication connections from the standby,
|
||||||
so a seperate replication user with the `REPLICATION` privilege is not required.
|
so a seperate replication user with the `REPLICATION` privilege is not required.
|
||||||
The database can in principle be any database, including the default `postgres`
|
The database can in principle be any database, including the default `postgres`
|
||||||
one, however it's probably advisable to create a dedicated database for repmgr
|
one, however it's probably advisable to create a dedicated database for `repmgr`
|
||||||
usage.
|
usage.
|
||||||
|
|
||||||
|
|
||||||
### repmgr configuration
|
### repmgr configuration
|
||||||
|
|
||||||
Each PostgreSQL node requires a repmgr configuration file containing
|
Each PostgreSQL node requires a `repmgr.conf` configuration file containing
|
||||||
identification and database connection information:
|
identification and database connection information:
|
||||||
|
|
||||||
cluster=test
|
cluster=test
|
||||||
node=1
|
node=1
|
||||||
node_name=node1
|
node_name=node1
|
||||||
conninfo='host=repmgr_node1 user=repmgr_usr dbname=repmgr_db'
|
conninfo='host=repmgr_node1 user=repmgr_usr dbname=repmgr_db'
|
||||||
pg_bindir=/path/to/postgres/bin
|
pg_bindir=/path/to/postgres/bin
|
||||||
|
|
||||||
* `cluster`: common name for the replication cluster; this must be the same on all nodes
|
* `cluster`: common name for the replication cluster; this must be the same on all nodes
|
||||||
* `node`: a unique, abitrary integer identifier
|
* `node`: a unique, abitrary integer identifier
|
||||||
@@ -110,12 +110,15 @@ identification and database connection information:
|
|||||||
resolvable by all nodes on the cluster.
|
resolvable by all nodes on the cluster.
|
||||||
* `pg_bindir`: (optional) location of PostgreSQL binaries, if not in the default $PATH
|
* `pg_bindir`: (optional) location of PostgreSQL binaries, if not in the default $PATH
|
||||||
|
|
||||||
Note that the configuration file should not be stored inside the PostgreSQL
|
Note that the configuration file should *not* be stored inside the PostgreSQL
|
||||||
data directory.
|
data directory. The configuration file can be specified with the
|
||||||
|
`-f, --config-file=PATH` option and can have any arbitrary name. If no
|
||||||
|
configuration file is specified, `repmgr` will search for `repmgr.conf`
|
||||||
|
in the current working directory.
|
||||||
|
|
||||||
Each node configuration needs to be registered with repmgr, either using the
|
Each node configuration needs to be registered with `repmgr`, either using the
|
||||||
repmgr command line tool, or the repmgrd daemon; for details see below. Details
|
`repmgr` command line tool, or the `repmgrd` daemon; for details see below. Details
|
||||||
about each node are inserted into the repmgr database (for details see below).
|
about each node are inserted into the `repmgr` database (for details see below).
|
||||||
|
|
||||||
|
|
||||||
Replication setup and monitoring
|
Replication setup and monitoring
|
||||||
@@ -141,9 +144,9 @@ Master setup
|
|||||||
CREATE DATABASE repmgr_db OWNER repmgr_usr;
|
CREATE DATABASE repmgr_db OWNER repmgr_usr;
|
||||||
```
|
```
|
||||||
|
|
||||||
- configure postgresql.conf for replication (see above)
|
- configure `postgresql.conf` for replication (see above)
|
||||||
|
|
||||||
- update pg_hba.conf, e.g.:
|
- update `pg_hba.conf`, e.g.:
|
||||||
|
|
||||||
```
|
```
|
||||||
host repmgr_db repmgr_usr 192.168.1.0/24 trust
|
host repmgr_db repmgr_usr 192.168.1.0/24 trust
|
||||||
@@ -151,45 +154,47 @@ Master setup
|
|||||||
```
|
```
|
||||||
|
|
||||||
Restart the PostgreSQL server after making these changes.
|
Restart the PostgreSQL server after making these changes.
|
||||||
|
2. Create the `repmgr` configuration file:
|
||||||
|
|
||||||
2. Create the repmgr configuration file:
|
$ cat $HOME/repmgr/repmgr.conf
|
||||||
|
cluster=test
|
||||||
|
node=1
|
||||||
|
node_name=node1
|
||||||
|
conninfo='host=repmgr_node1 user=repmgr_usr dbname=repmgr_db'
|
||||||
|
pg_bindir=/path/to/postgres/bin
|
||||||
|
|
||||||
$ cat $HOME/repmgr/repmgr.conf
|
(For an annotated `repmgr.conf` file, see `repmgr.conf.sample` in the
|
||||||
cluster=test
|
repository's root directory).
|
||||||
node=1
|
|
||||||
node_name=node1
|
|
||||||
conninfo='host=repmgr_node1 user=repmgr_usr dbname=repmgr_db'
|
|
||||||
pg_bindir=/path/to/postgres/bin
|
|
||||||
|
|
||||||
3. Register the master node with repmgr:
|
3. Register the master node with `repmgr`:
|
||||||
|
|
||||||
$ repmgr -f $HOME/repmgr/repmgr.conf --verbose master register
|
$ repmgr -f $HOME/repmgr/repmgr.conf --verbose master register
|
||||||
[2014-07-04 10:43:42] [INFO] repmgr mgr connecting to master database
|
[2014-07-04 10:43:42] [INFO] repmgr mgr connecting to master database
|
||||||
[2014-07-04 10:43:42] [INFO] repmgr connected to master, checking its state
|
[2014-07-04 10:43:42] [INFO] repmgr connected to master, checking its state
|
||||||
[2014-07-04 10:43:42] [INFO] master register: creating database objects inside the repmgr_test schema
|
[2014-07-04 10:43:42] [INFO] master register: creating database objects inside the repmgr_test schema
|
||||||
[2014-07-04 10:43:43] [NOTICE] Master node correctly registered for cluster test with id 1 (conninfo: host=localhost user=repmgr_usr dbname=repmgr_db)
|
[2014-07-04 10:43:43] [NOTICE] Master node correctly registered for cluster test with id 1 (conninfo: host=localhost user=repmgr_usr dbname=repmgr_db)
|
||||||
|
|
||||||
|
|
||||||
Slave/standby setup
|
Slave/standby setup
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
1. Use repmgr to clone the master:
|
1. Use `repmgr` to clone the master:
|
||||||
|
|
||||||
$ repmgr -f $HOME/repmgr/repmgr.conf -D $PGDATA -d repmgr_db -U repmgr_usr -R postgres --verbose standby clone 192.168.1.2
|
$ repmgr -D $PGDATA -d repmgr_db -U repmgr_usr -R postgres --verbose standby clone 192.168.1.2
|
||||||
Opening configuration file: ./repmgr.conf
|
Opening configuration file: ./repmgr.conf
|
||||||
[2014-07-04 10:49:00] [ERROR] Did not find the configuration file './repmgr.conf', continuing
|
[2014-07-04 10:49:00] [ERROR] Did not find the configuration file './repmgr.conf', continuing
|
||||||
[2014-07-04 10:49:00] [INFO] repmgr connecting to master database
|
[2014-07-04 10:49:00] [INFO] repmgr connecting to master database
|
||||||
[2014-07-04 10:49:00] [INFO] repmgr connected to master, checking its state
|
[2014-07-04 10:49:00] [INFO] repmgr connected to master, checking its state
|
||||||
[2014-07-04 10:49:00] [INFO] Successfully connected to primary. Current installation size is 1807 MB
|
[2014-07-04 10:49:00] [INFO] Successfully connected to primary. Current installation size is 1807 MB
|
||||||
[2014-07-04 10:49:00] [NOTICE] Starting backup...
|
[2014-07-04 10:49:00] [NOTICE] Starting backup...
|
||||||
[2014-07-04 10:49:00] [INFO] creating directory "/path/to/data/"...
|
[2014-07-04 10:49:00] [INFO] creating directory "/path/to/data/"...
|
||||||
(...)
|
(...)
|
||||||
[2014-07-04 10:53:19] [NOTICE] Finishing backup...
|
[2014-07-04 10:53:19] [NOTICE] Finishing backup...
|
||||||
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
|
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
|
||||||
[2014-07-04 10:53:21] [INFO] repmgr requires primary to keep WAL files 0000000100000000000000AD until at least 0000000100000000000000AD
|
[2014-07-04 10:53:21] [INFO] repmgr requires primary to keep WAL files 0000000100000000000000AD until at least 0000000100000000000000AD
|
||||||
[2014-07-04 10:53:21] [NOTICE] repmgr standby clone complete
|
[2014-07-04 10:53:21] [NOTICE] repmgr standby clone complete
|
||||||
[2014-07-04 10:53:21] [NOTICE] HINT: You can now start your postgresql server
|
[2014-07-04 10:53:21] [NOTICE] HINT: You can now start your postgresql server
|
||||||
[2014-07-04 10:53:21] [NOTICE] for example : /etc/init.d/postgresql start
|
[2014-07-04 10:53:21] [NOTICE] for example : /etc/init.d/postgresql start
|
||||||
|
|
||||||
-R is the database system user on the master node. At this point it does not matter
|
-R is the database system user on the master node. At this point it does not matter
|
||||||
if the `repmgr.conf` file is not found.
|
if the `repmgr.conf` file is not found.
|
||||||
@@ -201,28 +206,28 @@ Slave/standby setup
|
|||||||
|
|
||||||
2. Start the PostgreSQL server
|
2. Start the PostgreSQL server
|
||||||
|
|
||||||
3. Create the repmgr configuration file:
|
3. Create the `repmgr` configuration file:
|
||||||
|
|
||||||
$ cat $HOME/repmgr/repmgr.conf
|
$ cat $HOME/repmgr/repmgr.conf
|
||||||
cluster=test
|
cluster=test
|
||||||
node=2
|
node=2
|
||||||
node_name=node2
|
node_name=node2
|
||||||
conninfo='host=repmgr_node2 user=repmgr_usr dbname=repmgr_db'
|
conninfo='host=repmgr_node2 user=repmgr_usr dbname=repmgr_db'
|
||||||
pg_bindir=/path/to/postgres/bin
|
pg_bindir=/path/to/postgres/bin
|
||||||
|
|
||||||
4. Register the master node with repmgr:
|
4. Register the master node with `repmgr`:
|
||||||
|
|
||||||
$ repmgr -f $HOME/repmgr/repmgr.conf --verbose standby register
|
$ repmgr -f $HOME/repmgr/repmgr.conf --verbose standby register
|
||||||
Opening configuration file: /path/to/repmgr/repmgr.conf
|
Opening configuration file: /path/to/repmgr/repmgr.conf
|
||||||
[2014-07-04 11:48:13] [INFO] repmgr connecting to standby database
|
[2014-07-04 11:48:13] [INFO] repmgr connecting to standby database
|
||||||
[2014-07-04 11:48:13] [INFO] repmgr connected to standby, checking its state
|
[2014-07-04 11:48:13] [INFO] repmgr connected to standby, checking its state
|
||||||
[2014-07-04 11:48:13] [INFO] repmgr connecting to master database
|
[2014-07-04 11:48:13] [INFO] repmgr connecting to master database
|
||||||
[2014-07-04 11:48:13] [INFO] finding node list for cluster 'test'
|
[2014-07-04 11:48:13] [INFO] finding node list for cluster 'test'
|
||||||
[2014-07-04 11:48:13] [INFO] checking role of cluster node 'host=repmgr_node1 user=repmgr_usr dbname=repmgr_db'
|
[2014-07-04 11:48:13] [INFO] checking role of cluster node 'host=repmgr_node1 user=repmgr_usr dbname=repmgr_db'
|
||||||
[2014-07-04 11:48:13] [INFO] repmgr connected to master, checking its state
|
[2014-07-04 11:48:13] [INFO] repmgr connected to master, checking its state
|
||||||
[2014-07-04 11:48:13] [INFO] repmgr registering the standby
|
[2014-07-04 11:48:13] [INFO] repmgr registering the standby
|
||||||
[2014-07-04 11:48:13] [INFO] repmgr registering the standby complete
|
[2014-07-04 11:48:13] [INFO] repmgr registering the standby complete
|
||||||
[2014-07-04 11:48:13] [NOTICE] Standby node correctly registered for cluster test with id 2 (conninfo: host=localhost user=repmgr_usr dbname=repmgr_db)
|
[2014-07-04 11:48:13] [NOTICE] Standby node correctly registered for cluster test with id 2 (conninfo: host=localhost user=repmgr_usr dbname=repmgr_db)
|
||||||
|
|
||||||
Monitoring
|
Monitoring
|
||||||
----------
|
----------
|
||||||
@@ -259,8 +264,8 @@ To promote a standby to master, on the standby execute e.g.:
|
|||||||
|
|
||||||
repmgr -f $HOME/repmgr/repmgr.conf --verbose standby promote
|
repmgr -f $HOME/repmgr/repmgr.conf --verbose standby promote
|
||||||
|
|
||||||
repmgr will attempt to connect to the current master to verify that it
|
`repmgr` will attempt to connect to the current master to verify that it
|
||||||
is not available (if it is, repmgr will not promote the standby).
|
is not available (if it is, `repmgr` will not promote the standby).
|
||||||
|
|
||||||
Other standby servers need to be told to follow the new master with:
|
Other standby servers need to be told to follow the new master with:
|
||||||
|
|
||||||
@@ -273,7 +278,7 @@ automated failover.
|
|||||||
repmgr database schema
|
repmgr database schema
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
repmgr creates a small schema for its own use in the database specified in
|
`repmgr` creates a small schema for its own use in the database specified in
|
||||||
each node's conninfo configuration parameter. This database can in principle
|
each node's conninfo configuration parameter. This database can in principle
|
||||||
be any database. The schema name is the global `cluster` name prefixed
|
be any database. The schema name is the global `cluster` name prefixed
|
||||||
with `repmgr_`, so for the example setup above the schema name is
|
with `repmgr_`, so for the example setup above the schema name is
|
||||||
@@ -290,3 +295,10 @@ and one view, `repl_status`, which summarizes the latest monitoring information
|
|||||||
for each node.
|
for each node.
|
||||||
|
|
||||||
|
|
||||||
|
Further reading
|
||||||
|
---------------
|
||||||
|
|
||||||
|
* http://blog.2ndquadrant.com/announcing-repmgr-2-0/
|
||||||
|
* http://blog.2ndquadrant.com/managing-useful-clusters-repmgr/
|
||||||
|
* http://blog.2ndquadrant.com/easier_postgresql_90_clusters/
|
||||||
|
|
||||||
|
|||||||
@@ -427,7 +427,7 @@ system you already have superuser access to.
|
|||||||
Clearing the PostgreSQL installation on the Standby
|
Clearing the PostgreSQL installation on the Standby
|
||||||
---------------------------------------------------
|
---------------------------------------------------
|
||||||
|
|
||||||
To setup a new streaming replica, startin by removing any PostgreSQL
|
To setup a new streaming replica, start by removing any PostgreSQL
|
||||||
installation on the existing standby nodes.
|
installation on the existing standby nodes.
|
||||||
|
|
||||||
* Stop any server on "node2" and "node3". You can confirm the database
|
* Stop any server on "node2" and "node3". You can confirm the database
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ Version: 2.0
|
|||||||
Release: 2
|
Release: 2
|
||||||
License: GPLv3
|
License: GPLv3
|
||||||
Group: System Environment/Daemons
|
Group: System Environment/Daemons
|
||||||
URL: http://repmgr.org
|
URL: http://repmgr.org
|
||||||
Packager: Nathan Van Overloop <nathan.van.overloop@nexperteam.be>
|
Packager: Nathan Van Overloop <nathan.van.overloop@nexperteam.be>
|
||||||
Vendor: 2ndQuadrant Limited
|
Vendor: 2ndQuadrant Limited
|
||||||
Distribution: centos
|
Distribution: centos
|
||||||
@@ -32,7 +32,7 @@ export PATH=$PATH:/usr/pgsql-9.3/bin/
|
|||||||
|
|
||||||
%clean
|
%clean
|
||||||
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}
|
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}
|
||||||
|
|
||||||
|
|
||||||
%files
|
%files
|
||||||
%defattr(-,root,root)
|
%defattr(-,root,root)
|
||||||
@@ -45,7 +45,7 @@ export PATH=$PATH:/usr/pgsql-9.3/bin/
|
|||||||
/usr/pgsql-9.3/share/contrib/repmgr_funcs.sql
|
/usr/pgsql-9.3/share/contrib/repmgr_funcs.sql
|
||||||
/usr/pgsql-9.3/share/contrib/uninstall_repmgr.sql
|
/usr/pgsql-9.3/share/contrib/uninstall_repmgr.sql
|
||||||
/usr/pgsql-9.3/share/contrib/uninstall_repmgr_funcs.sql
|
/usr/pgsql-9.3/share/contrib/uninstall_repmgr_funcs.sql
|
||||||
%attr(0755,root,root)/etc/init.d/repmgrd
|
%attr(0755,root,root)/etc/init.d/repmgrd
|
||||||
%attr(0644,root,root)/etc/sysconfig/repmgrd
|
%attr(0644,root,root)/etc/sysconfig/repmgrd
|
||||||
%attr(0644,root,root)/etc/repmgr/repmgr.conf.sample
|
%attr(0644,root,root)/etc/repmgr/repmgr.conf.sample
|
||||||
|
|
||||||
@@ -54,4 +54,3 @@ export PATH=$PATH:/usr/pgsql-9.3/bin/
|
|||||||
- fix witness creation to create db and user if needed
|
- fix witness creation to create db and user if needed
|
||||||
* Fri Apr 04 2014 Nathan Van Overloop <nathan.van.overloop@nexperteam.be> 2.0.1
|
* Fri Apr 04 2014 Nathan Van Overloop <nathan.van.overloop@nexperteam.be> 2.0.1
|
||||||
- initial build for RHEL6
|
- initial build for RHEL6
|
||||||
|
|
||||||
|
|||||||
@@ -1,89 +1,114 @@
|
|||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# repmgrd Start up the repmgrd daemon
|
# chkconfig: - 75 16
|
||||||
# repmrgd (replication manager daemon)
|
# description: Enable repmgrd replication management and monitoring daemon for PostgreSQL
|
||||||
#
|
# processname: repmgrd
|
||||||
# chkconfig: - 75 16
|
# pidfile="/var/run/${NAME}.pid"
|
||||||
# description: repmgrd is the repliation manager daemon \
|
|
||||||
# The repmgrd replication management and monitoring daemon for PostgreSQL.
|
|
||||||
|
|
||||||
### BEGIN INIT INFO
|
|
||||||
# Provides: repmgrd
|
|
||||||
# Required-Start: $local_fs $remote_fs $network $syslog postgresql
|
|
||||||
# Required-Stop: $local_fs $remote_fs $network $syslog postgresql
|
|
||||||
# Should-Start: $syslog postgresql-9.3
|
|
||||||
# Should-Stop: $syslog postgresql-9.3
|
|
||||||
# Short-Description: start and stop repmrgd
|
|
||||||
# Description: Enable repmgrd replication management and monitoring daemon for PostgreSQL
|
|
||||||
# this is used to monitor a postgresql cluster.
|
|
||||||
### END INIT INFO
|
|
||||||
|
|
||||||
# Source function library.
|
# Source function library.
|
||||||
. /etc/init.d/functions
|
INITD=/etc/rc.d/init.d
|
||||||
|
. $INITD/functions
|
||||||
|
|
||||||
# Source networking configuration.
|
# Get function listing for cross-distribution logic.
|
||||||
|
TYPESET=`typeset -f|grep "declare"`
|
||||||
|
|
||||||
|
# Get network config.
|
||||||
. /etc/sysconfig/network
|
. /etc/sysconfig/network
|
||||||
|
|
||||||
prog=repmgrd
|
DESC="PostgreSQL replication management and monitoring daemon"
|
||||||
REPMGRD_ENABLED=yes
|
NAME=repmgrd
|
||||||
|
|
||||||
|
REPMGRD_ENABLED=no
|
||||||
REPMGRD_OPTS=
|
REPMGRD_OPTS=
|
||||||
REPMGRD_USER=postgres
|
REPMGRD_USER=postgres
|
||||||
DAEMONIZE="-d"
|
REPMGRD_BIN=/usr/pgsql-9.3/bin/repmgrd
|
||||||
|
REPMGRD_PIDFILE=/var/run/repmgrd.pid
|
||||||
|
REPMGRD_LOCK=/var/lock/subsys/${NAME}
|
||||||
|
REPMGRD_LOG=/var/lib/pgsql/9.3/data/pg_log/repmgrd.log
|
||||||
|
|
||||||
# pull in sysconfig settings
|
# Read configuration variable file if it is present
|
||||||
[ -f /etc/sysconfig/repmgrd ] && . /etc/sysconfig/repmgrd
|
[ -r /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
|
||||||
|
|
||||||
LOCKFILE=/var/lock/subsys/$prog
|
# For SELinux we need to use 'runuser' not 'su'
|
||||||
RETVAL=0
|
if [ -x /sbin/runuser ]
|
||||||
|
then
|
||||||
|
SU=runuser
|
||||||
|
else
|
||||||
|
SU=su
|
||||||
|
fi
|
||||||
|
|
||||||
|
test -x $REPMGRD_BIN || exit 0
|
||||||
|
|
||||||
case "$REPMGRD_ENABLED" in
|
case "$REPMGRD_ENABLED" in
|
||||||
[Yy]*)
|
[Yy]*)
|
||||||
#nothing to do here
|
break
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
exit 2
|
exit 0
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
||||||
if [ -z "$REPMGRD_OPTS" ]
|
if [ -z "${REPMGRD_OPTS}" ]
|
||||||
then
|
then
|
||||||
echo "Not starting $prog, REPMGRD_OPTS not set in /etc/sysconfig/$prog"
|
echo "Not starting ${NAME}, REPMGRD_OPTS not set in /etc/sysconfig/${NAME}"
|
||||||
exit 2
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
start() {
|
start()
|
||||||
[ "$EUID" != "0" ] && exit 4
|
{
|
||||||
[ "$NETWORKING" = "no" ] && exit 1
|
REPMGRD_START=$"Starting ${NAME} service: "
|
||||||
|
|
||||||
# Start daemons.
|
# Make sure startup-time log file is valid
|
||||||
echo -n $"Starting $prog: "
|
if [ ! -e "${REPMGRD_LOG}" -a ! -h "${REPMGRD_LOG}" ]
|
||||||
daemon --user $REPMGRD_USER $prog $DAEMONIZE $REPMGRD_OPTS
|
then
|
||||||
RETVAL=$?
|
touch "${REPMGRD_LOG}" || exit 1
|
||||||
|
chown ${REPMGRD_USER}:postgres "${REPMGRD_LOG}"
|
||||||
|
chmod go-rwx "${REPMGRD_LOG}"
|
||||||
|
[ -x /sbin/restorecon ] && /sbin/restorecon "${REPMGRD_LOG}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -n "${REPMGRD_START}"
|
||||||
|
$SU -l $REPMGRD_USER -c "${REPMGRD_BIN} ${REPMGRD_OPTS} -p ${REPMGRD_PIDFILE} &" >> "${REPMGRD_LOG}" 2>&1 < /dev/null
|
||||||
|
sleep 2
|
||||||
|
pid=`head -n 1 "${REPMGRD_PIDFILE}" 2>/dev/null`
|
||||||
|
if [ "x${pid}" != "x" ]
|
||||||
|
then
|
||||||
|
success "${REPMGRD_START}"
|
||||||
|
touch "${REPMGRD_LOCK}"
|
||||||
|
echo $pid > "${REPMGRD_PIDFILE}"
|
||||||
echo
|
echo
|
||||||
[ $RETVAL -eq 0 ] && touch $LOCKFILE
|
else
|
||||||
return $RETVAL
|
failure "${REPMGRD_START}"
|
||||||
|
echo
|
||||||
|
script_result=1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop()
|
||||||
[ "$EUID" != "0" ] && exit 4
|
{
|
||||||
echo -n $"Shutting down $prog: "
|
echo -n $"Stopping ${NAME} service: "
|
||||||
killproc $prog
|
if [ -e "${REPMGRD_LOCK}" ]
|
||||||
RETVAL=$?
|
then
|
||||||
echo
|
killproc ${NAME}
|
||||||
[ $RETVAL -eq 0 ] && rm -f $LOCKFILE
|
ret=$?
|
||||||
return $RETVAL
|
if [ $ret -eq 0 ]
|
||||||
}
|
then
|
||||||
status() {
|
echo_success
|
||||||
if [ -f "$LOCKFILE" ]; then
|
rm -f "${REPMGRD_PIDFILE}"
|
||||||
echo "$prog is running"
|
rm -f "${REPMGRD_LOCK}"
|
||||||
else
|
else
|
||||||
RETVAL=3
|
echo_failure
|
||||||
echo "$prog is stopped"
|
script_result=1
|
||||||
fi
|
fi
|
||||||
return $RETVAL
|
else
|
||||||
|
# not running; per LSB standards this is "ok"
|
||||||
|
echo_success
|
||||||
|
fi
|
||||||
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# See how we were called.
|
# See how we were called.
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start)
|
start)
|
||||||
@@ -93,22 +118,16 @@ case "$1" in
|
|||||||
stop
|
stop
|
||||||
;;
|
;;
|
||||||
status)
|
status)
|
||||||
status $prog
|
status -p $REPMGRD_PIDFILE $NAME
|
||||||
|
script_result=$?
|
||||||
;;
|
;;
|
||||||
restart|force-reload)
|
restart)
|
||||||
stop
|
stop
|
||||||
start
|
start
|
||||||
;;
|
|
||||||
try-restart|condrestart)
|
|
||||||
if status $prog > /dev/null; then
|
|
||||||
stop
|
|
||||||
start
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
reload)
|
|
||||||
exit 3
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}"
|
echo $"Usage: $0 {start|stop|status|restart}"
|
||||||
exit 2
|
exit 2
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
exit $script_result
|
||||||
|
|||||||
@@ -1,4 +1,21 @@
|
|||||||
#default sysconfig file for repmrgd
|
# default settings for repmgrd. This file is source by /bin/sh from
|
||||||
#custom overrides can be placed here
|
# /etc/init.d/repmgrd
|
||||||
|
|
||||||
REPMGRD_OPTS="-f /etc/repmgr/repmgr.conf"
|
# disable repmgrd by default so it won't get started upon installation
|
||||||
|
# valid values: yes/no
|
||||||
|
REPMGRD_ENABLED=no
|
||||||
|
|
||||||
|
# Options for repmgrd (required)
|
||||||
|
#REPMGRD_OPTS="--verbose -d -f /var/lib/pgsql/repmgr/repmgr.conf"
|
||||||
|
|
||||||
|
# User to run repmgrd as
|
||||||
|
#REPMGRD_USER=postgres
|
||||||
|
|
||||||
|
# repmgrd binary
|
||||||
|
#REPMGRD_BIN=/usr/bin/repmgr
|
||||||
|
|
||||||
|
# pid file
|
||||||
|
#REPMGRD_PIDFILE=/var/lib/pgsql/repmgr/repmgrd.pid
|
||||||
|
|
||||||
|
# log file
|
||||||
|
#REPMGRD_LOG=/var/lib/pgsql/repmgr/repmgrd.log
|
||||||
|
|||||||
@@ -25,7 +25,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* NB: postgres_fe must be included BEFORE check_dir */
|
/* NB: postgres_fe must be included BEFORE check_dir */
|
||||||
#include "postgres_fe.h"
|
#include <libpq-fe.h>
|
||||||
|
#include <postgres_fe.h>
|
||||||
#include "check_dir.h"
|
#include "check_dir.h"
|
||||||
|
|
||||||
#include "strutil.h"
|
#include "strutil.h"
|
||||||
|
|||||||
4
config.c
4
config.c
@@ -185,6 +185,10 @@ trim(char *s)
|
|||||||
char *s1 = s,
|
char *s1 = s,
|
||||||
*s2 = &s[strlen(s) - 1];
|
*s2 = &s[strlen(s) - 1];
|
||||||
|
|
||||||
|
/* If string is empty, no action needed */
|
||||||
|
if(s2 < s1)
|
||||||
|
return s;
|
||||||
|
|
||||||
/* Trim and delimit right side */
|
/* Trim and delimit right side */
|
||||||
while ((isspace(*s2)) && (s2 >= s1))
|
while ((isspace(*s2)) && (s2 >= s1))
|
||||||
--s2;
|
--s2;
|
||||||
|
|||||||
2
debian/DEBIAN/control
vendored
2
debian/DEBIAN/control
vendored
@@ -3,7 +3,7 @@ Version: 2.0beta2
|
|||||||
Section: database
|
Section: database
|
||||||
Priority: optional
|
Priority: optional
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Depends: rsync, postgresql-9.0 | postgresql-9.1 | postgresql-9.2 | postgresql-9.3
|
Depends: rsync, postgresql-9.0 | postgresql-9.1 | postgresql-9.2 | postgresql-9.3 | postgresql-9.4
|
||||||
Maintainer: Jaime Casanova <jaime@2ndQuadrant.com>
|
Maintainer: Jaime Casanova <jaime@2ndQuadrant.com>
|
||||||
Description: PostgreSQL replication setup, magament and monitoring
|
Description: PostgreSQL replication setup, magament and monitoring
|
||||||
has two main executables
|
has two main executables
|
||||||
|
|||||||
6
log.h
6
log.h
@@ -25,9 +25,15 @@
|
|||||||
#define REPMGR_SYSLOG 1
|
#define REPMGR_SYSLOG 1
|
||||||
#define REPMGR_STDERR 2
|
#define REPMGR_STDERR 2
|
||||||
|
|
||||||
|
#if (PG_VERSION_NUM >= 90100)
|
||||||
void
|
void
|
||||||
stderr_log_with_level(const char *level_name, int level, const char *fmt,...)
|
stderr_log_with_level(const char *level_name, int level, const char *fmt,...)
|
||||||
__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
|
__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
|
||||||
|
#else
|
||||||
|
void
|
||||||
|
stderr_log_with_level(const char *level_name, int level, const char *fmt,...)
|
||||||
|
__attribute__((format(printf, 3, 4)));
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Standard error logging */
|
/* Standard error logging */
|
||||||
#define stderr_log_debug(...) stderr_log_with_level("DEBUG", LOG_DEBUG, __VA_ARGS__)
|
#define stderr_log_debug(...) stderr_log_with_level("DEBUG", LOG_DEBUG, __VA_ARGS__)
|
||||||
|
|||||||
80
repmgr.c
80
repmgr.c
@@ -100,6 +100,7 @@ main(int argc, char **argv)
|
|||||||
{"host", required_argument, NULL, 'h'},
|
{"host", required_argument, NULL, 'h'},
|
||||||
{"port", required_argument, NULL, 'p'},
|
{"port", required_argument, NULL, 'p'},
|
||||||
{"username", required_argument, NULL, 'U'},
|
{"username", required_argument, NULL, 'U'},
|
||||||
|
{"superuser", required_argument, NULL, 'S'},
|
||||||
{"dest-dir", required_argument, NULL, 'D'},
|
{"dest-dir", required_argument, NULL, 'D'},
|
||||||
{"local-port", required_argument, NULL, 'l'},
|
{"local-port", required_argument, NULL, 'l'},
|
||||||
{"config-file", required_argument, NULL, 'f'},
|
{"config-file", required_argument, NULL, 'f'},
|
||||||
@@ -110,6 +111,8 @@ main(int argc, char **argv)
|
|||||||
{"wait", no_argument, NULL, 'W'},
|
{"wait", no_argument, NULL, 'W'},
|
||||||
{"ignore-rsync-warning", no_argument, NULL, 'I'},
|
{"ignore-rsync-warning", no_argument, NULL, 'I'},
|
||||||
{"verbose", no_argument, NULL, 'v'},
|
{"verbose", no_argument, NULL, 'v'},
|
||||||
|
{"fast-checkpoint", no_argument, NULL, 'c'},
|
||||||
|
{"initdb-no-pwprompt", no_argument, NULL, 1},
|
||||||
{NULL, 0, NULL, 0}
|
{NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -134,7 +137,7 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "d:h:p:U:D:l:f:R:w:k:FWIv", long_options,
|
while ((c = getopt_long(argc, argv, "d:h:p:U:S:D:l:f:R:w:k:FWIvc", long_options,
|
||||||
&optindex)) != -1)
|
&optindex)) != -1)
|
||||||
{
|
{
|
||||||
switch (c)
|
switch (c)
|
||||||
@@ -152,6 +155,9 @@ main(int argc, char **argv)
|
|||||||
case 'U':
|
case 'U':
|
||||||
strncpy(runtime_options.username, optarg, MAXLEN);
|
strncpy(runtime_options.username, optarg, MAXLEN);
|
||||||
break;
|
break;
|
||||||
|
case 'S':
|
||||||
|
strncpy(runtime_options.superuser, optarg, MAXLEN);
|
||||||
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
strncpy(runtime_options.dest_dir, optarg, MAXFILENAME);
|
strncpy(runtime_options.dest_dir, optarg, MAXFILENAME);
|
||||||
break;
|
break;
|
||||||
@@ -187,6 +193,12 @@ main(int argc, char **argv)
|
|||||||
case 'v':
|
case 'v':
|
||||||
runtime_options.verbose = true;
|
runtime_options.verbose = true;
|
||||||
break;
|
break;
|
||||||
|
case 'c':
|
||||||
|
runtime_options.fast_checkpoint = true;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
runtime_options.initdb_no_pwprompt = true;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
exit(ERR_BAD_CONFIG);
|
exit(ERR_BAD_CONFIG);
|
||||||
@@ -812,7 +824,7 @@ do_standby_clone(void)
|
|||||||
|
|
||||||
int r = 0,
|
int r = 0,
|
||||||
retval = SUCCESS;
|
retval = SUCCESS;
|
||||||
int i,
|
int i,j,
|
||||||
is_standby_retval;
|
is_standby_retval;
|
||||||
bool flag_success = false;
|
bool flag_success = false;
|
||||||
bool test_mode = false;
|
bool test_mode = false;
|
||||||
@@ -890,11 +902,30 @@ do_standby_clone(void)
|
|||||||
i = guc_set(conn, "wal_level", "=", "hot_standby");
|
i = guc_set(conn, "wal_level", "=", "hot_standby");
|
||||||
if (i == 0 || i == -1)
|
if (i == 0 || i == -1)
|
||||||
{
|
{
|
||||||
PQfinish(conn);
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
log_err(_("%s needs parameter 'wal_level' to be set to 'hot_standby'\n"),
|
{
|
||||||
progname);
|
/* We could be using PG 9.4 with log_level logical, which is good enough for
|
||||||
exit(ERR_BAD_CONFIG);
|
hot standby replication.
|
||||||
|
We should check if the wal_level is set to that value, in which case we are
|
||||||
|
good to proceed.
|
||||||
|
No need to check if we are in 9.4 first, as the query used in guc_set will just
|
||||||
|
return zero rows if on < 9.4, and so will work anyway.
|
||||||
|
*/
|
||||||
|
j = guc_set(conn, "wal_level", "=", "logical");
|
||||||
|
if (j == 0 || j == -1)
|
||||||
|
{
|
||||||
|
PQfinish(conn);
|
||||||
|
if (j == 0)
|
||||||
|
log_err(_("%s needs parameter 'wal_level' to be set to at least 'hot_standby'\n"),
|
||||||
|
progname);
|
||||||
|
exit(ERR_BAD_CONFIG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (i == -1)
|
||||||
|
{
|
||||||
|
PQfinish(conn);
|
||||||
|
exit(ERR_BAD_CONFIG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i = guc_set_typed(conn, "wal_keep_segments", ">=",
|
i = guc_set_typed(conn, "wal_keep_segments", ">=",
|
||||||
@@ -1087,8 +1118,9 @@ do_standby_clone(void)
|
|||||||
*/
|
*/
|
||||||
sqlquery_snprintf(
|
sqlquery_snprintf(
|
||||||
sqlquery,
|
sqlquery,
|
||||||
"SELECT pg_xlogfile_name(pg_start_backup('repmgr_standby_clone_%ld'))",
|
"SELECT pg_xlogfile_name(pg_start_backup('repmgr_standby_clone_%ld', %s))",
|
||||||
time(NULL));
|
time(NULL),
|
||||||
|
runtime_options.fast_checkpoint ? "TRUE" : "FALSE");
|
||||||
log_debug(_("standby clone: %s\n"), sqlquery);
|
log_debug(_("standby clone: %s\n"), sqlquery);
|
||||||
res = PQexec(conn, sqlquery);
|
res = PQexec(conn, sqlquery);
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
@@ -1688,8 +1720,13 @@ do_witness_create(void)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Create the cluster for witness */
|
/* Create the cluster for witness */
|
||||||
sprintf(script, "%s/pg_ctl %s -D %s init -o \"-W\"", options.pg_bindir,
|
if (!runtime_options.superuser[0])
|
||||||
options.pgctl_options, runtime_options.dest_dir);
|
strncpy(runtime_options.superuser, "postgres", MAXLEN);
|
||||||
|
|
||||||
|
sprintf(script, "%s/pg_ctl %s -D %s init -o \"%s-U %s\"", options.pg_bindir,
|
||||||
|
options.pgctl_options, runtime_options.dest_dir,
|
||||||
|
runtime_options.initdb_no_pwprompt ? "" : "-W ",
|
||||||
|
runtime_options.superuser);
|
||||||
log_info("Initialize cluster for witness: %s.\n", script);
|
log_info("Initialize cluster for witness: %s.\n", script);
|
||||||
|
|
||||||
r = system(script);
|
r = system(script);
|
||||||
@@ -1742,13 +1779,13 @@ do_witness_create(void)
|
|||||||
PQfinish(masterconn);
|
PQfinish(masterconn);
|
||||||
exit(ERR_BAD_CONFIG);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if we need to create a user */
|
/* check if we need to create a user */
|
||||||
if (runtime_options.username[0] && runtime_options.localport[0] && strcmp(runtime_options.username,"postgres")!=0 )
|
if (runtime_options.username[0] && runtime_options.localport[0] && strcmp(runtime_options.username,"postgres")!=0 )
|
||||||
{
|
{
|
||||||
/* create required user needs to be superuser to create untrusted language function in c */
|
/* create required user needs to be superuser to create untrusted language function in c */
|
||||||
sprintf(script, "%s/createuser -p %s --superuser --login -U postgres %s", options.pg_bindir,
|
sprintf(script, "%s/createuser -p %s --superuser --login -U %s %s", options.pg_bindir,
|
||||||
runtime_options.localport,runtime_options.username);
|
runtime_options.localport, runtime_options.superuser, runtime_options.username);
|
||||||
log_info("Create user for witness db: %s.\n", script);
|
log_info("Create user for witness db: %s.\n", script);
|
||||||
|
|
||||||
r = system(script);
|
r = system(script);
|
||||||
@@ -1759,13 +1796,13 @@ do_witness_create(void)
|
|||||||
exit(ERR_BAD_CONFIG);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if we need to create a database */
|
/* check if we need to create a database */
|
||||||
if(runtime_options.dbname[0] && strcmp(runtime_options.dbname,"postgres")!=0 && runtime_options.localport[0])
|
if(runtime_options.dbname[0] && strcmp(runtime_options.dbname,"postgres")!=0 && runtime_options.localport[0])
|
||||||
{
|
{
|
||||||
/* create required db */
|
/* create required db */
|
||||||
sprintf(script, "%s/createdb -p %s -U postgres --owner=%s %s",
|
sprintf(script, "%s/createdb -p %s -U %s --owner=%s %s",
|
||||||
options.pg_bindir, runtime_options.localport,runtime_options.username, runtime_options.dbname);
|
options.pg_bindir, runtime_options.localport, runtime_options.superuser, runtime_options.username, runtime_options.dbname);
|
||||||
log_info("Create database for witness db: %s.\n", script);
|
log_info("Create database for witness db: %s.\n", script);
|
||||||
|
|
||||||
r = system(script);
|
r = system(script);
|
||||||
@@ -1809,7 +1846,7 @@ do_witness_create(void)
|
|||||||
PQfinish(masterconn);
|
PQfinish(masterconn);
|
||||||
exit(ERR_BAD_CONFIG);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* reload to adapt for changed pg_hba.conf */
|
/* reload to adapt for changed pg_hba.conf */
|
||||||
sprintf(script, "%s/pg_ctl %s -w -D %s reload", options.pg_bindir,
|
sprintf(script, "%s/pg_ctl %s -w -D %s reload", options.pg_bindir,
|
||||||
options.pgctl_options, runtime_options.dest_dir);
|
options.pgctl_options, runtime_options.dest_dir);
|
||||||
@@ -1821,8 +1858,8 @@ do_witness_create(void)
|
|||||||
PQfinish(masterconn);
|
PQfinish(masterconn);
|
||||||
exit(ERR_BAD_CONFIG);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* register ourselves in the master */
|
/* register ourselves in the master */
|
||||||
sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_nodes(id, cluster, name, conninfo, priority, witness) "
|
sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_nodes(id, cluster, name, conninfo, priority, witness) "
|
||||||
"VALUES (%d, '%s', '%s', '%s', %d, true)",
|
"VALUES (%d, '%s', '%s', '%s', %d, true)",
|
||||||
@@ -1917,6 +1954,8 @@ help(const char *progname)
|
|||||||
printf(_(" -l, --local-port=PORT standby or witness server local port\n"));
|
printf(_(" -l, --local-port=PORT standby or witness server local port\n"));
|
||||||
printf(_(" -f, --config-file=PATH path to the configuration file\n"));
|
printf(_(" -f, --config-file=PATH path to the configuration file\n"));
|
||||||
printf(_(" -R, --remote-user=USERNAME database server username for rsync\n"));
|
printf(_(" -R, --remote-user=USERNAME database server username for rsync\n"));
|
||||||
|
printf(_(" -S, --superuser=USERNAME superuser username for witness database\n" \
|
||||||
|
" (default: postgres)\n"));
|
||||||
printf(_(" -w, --wal-keep-segments=VALUE minimum value for the GUC\n" \
|
printf(_(" -w, --wal-keep-segments=VALUE minimum value for the GUC\n" \
|
||||||
" wal_keep_segments (default: 5000)\n"));
|
" wal_keep_segments (default: 5000)\n"));
|
||||||
printf(_(" -I, --ignore-rsync-warning ignore rsync partial transfer warning\n"));
|
printf(_(" -I, --ignore-rsync-warning ignore rsync partial transfer warning\n"));
|
||||||
@@ -1925,7 +1964,8 @@ help(const char *progname)
|
|||||||
printf(_(" -F, --force force potentially dangerous operations\n" \
|
printf(_(" -F, --force force potentially dangerous operations\n" \
|
||||||
" to happen\n"));
|
" to happen\n"));
|
||||||
printf(_(" -W, --wait wait for a master to appear\n"));
|
printf(_(" -W, --wait wait for a master to appear\n"));
|
||||||
|
printf(_(" -c, --fast-checkpoint force fast checkpoint when cloning a standby\n"));
|
||||||
|
printf(_(" --initdb-no-pwprompt don't require superuser password when running initdb\n"));
|
||||||
printf(_("\n%s performs some tasks like clone a node, promote it or making follow\n"), progname);
|
printf(_("\n%s performs some tasks like clone a node, promote it or making follow\n"), progname);
|
||||||
printf(_("another node and then exits.\n\n"));
|
printf(_("another node and then exits.\n\n"));
|
||||||
printf(_("COMMANDS:\n"));
|
printf(_("COMMANDS:\n"));
|
||||||
|
|||||||
11
repmgr.h
11
repmgr.h
@@ -20,9 +20,9 @@
|
|||||||
#ifndef _REPMGR_H_
|
#ifndef _REPMGR_H_
|
||||||
#define _REPMGR_H_
|
#define _REPMGR_H_
|
||||||
|
|
||||||
#include "postgres_fe.h"
|
#include <libpq-fe.h>
|
||||||
#include "getopt_long.h"
|
#include <postgres_fe.h>
|
||||||
#include "libpq-fe.h"
|
#include <getopt_long.h>
|
||||||
|
|
||||||
#include "strutil.h"
|
#include "strutil.h"
|
||||||
#include "dbutils.h"
|
#include "dbutils.h"
|
||||||
@@ -56,11 +56,14 @@ typedef struct
|
|||||||
char dest_dir[MAXFILENAME];
|
char dest_dir[MAXFILENAME];
|
||||||
char config_file[MAXFILENAME];
|
char config_file[MAXFILENAME];
|
||||||
char remote_user[MAXLEN];
|
char remote_user[MAXLEN];
|
||||||
|
char superuser[MAXLEN];
|
||||||
char wal_keep_segments[MAXLEN];
|
char wal_keep_segments[MAXLEN];
|
||||||
bool verbose;
|
bool verbose;
|
||||||
bool force;
|
bool force;
|
||||||
bool wait_for_master;
|
bool wait_for_master;
|
||||||
bool ignore_rsync_warn;
|
bool ignore_rsync_warn;
|
||||||
|
bool initdb_no_pwprompt;
|
||||||
|
bool fast_checkpoint;
|
||||||
|
|
||||||
char masterport[MAXLEN];
|
char masterport[MAXLEN];
|
||||||
char localport[MAXLEN];
|
char localport[MAXLEN];
|
||||||
@@ -69,6 +72,6 @@ typedef struct
|
|||||||
int keep_history;
|
int keep_history;
|
||||||
} t_runtime_options;
|
} t_runtime_options;
|
||||||
|
|
||||||
#define T_RUNTIME_OPTIONS_INITIALIZER { "", "", "", "", "", "", DEFAULT_WAL_KEEP_SEGMENTS, false, false, false, false, "", "", 0 }
|
#define T_RUNTIME_OPTIONS_INITIALIZER { "", "", "", "", "", "", "", DEFAULT_WAL_KEEP_SEGMENTS, false, false, false, false, false, false, "", "", 0}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
22
repmgrd.c
22
repmgrd.c
@@ -218,6 +218,17 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Read the configuration file: repmgr.conf
|
||||||
|
*/
|
||||||
|
parse_config(config_file, &local_options);
|
||||||
|
if (local_options.node == -1)
|
||||||
|
{
|
||||||
|
log_err(_("Node information is missing. "
|
||||||
|
"Check the configuration file, or provide one if you have not done so.\n"));
|
||||||
|
terminate(ERR_BAD_CONFIG);
|
||||||
|
}
|
||||||
|
|
||||||
if (daemonize)
|
if (daemonize)
|
||||||
{
|
{
|
||||||
do_daemonize();
|
do_daemonize();
|
||||||
@@ -232,17 +243,6 @@ main(int argc, char **argv)
|
|||||||
setup_event_handlers();
|
setup_event_handlers();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
* Read the configuration file: repmgr.conf
|
|
||||||
*/
|
|
||||||
parse_config(config_file, &local_options);
|
|
||||||
if (local_options.node == -1)
|
|
||||||
{
|
|
||||||
log_err(_("Node information is missing. "
|
|
||||||
"Check the configuration file, or provide one if you have not done so.\n"));
|
|
||||||
terminate(ERR_BAD_CONFIG);
|
|
||||||
}
|
|
||||||
|
|
||||||
fd = freopen("/dev/null", "r", stdin);
|
fd = freopen("/dev/null", "r", stdin);
|
||||||
if (fd == NULL)
|
if (fd == NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,9 +25,15 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "strutil.h"
|
#include "strutil.h"
|
||||||
|
|
||||||
|
#if (PG_VERSION_NUM >= 90100)
|
||||||
static int
|
static int
|
||||||
xvsnprintf(char *str, size_t size, const char *format, va_list ap)
|
xvsnprintf(char *str, size_t size, const char *format, va_list ap)
|
||||||
__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 0)));
|
__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 0)));
|
||||||
|
#else
|
||||||
|
static int
|
||||||
|
xvsnprintf(char *str, size_t size, const char *format, va_list ap)
|
||||||
|
__attribute__((format(printf, 3, 0)));
|
||||||
|
#endif
|
||||||
|
|
||||||
static int
|
static int
|
||||||
xvsnprintf(char *str, size_t size, const char *format, va_list ap)
|
xvsnprintf(char *str, size_t size, const char *format, va_list ap)
|
||||||
|
|||||||
14
strutil.h
14
strutil.h
@@ -31,6 +31,7 @@
|
|||||||
#define MAXCONNINFO 1024
|
#define MAXCONNINFO 1024
|
||||||
|
|
||||||
|
|
||||||
|
#if (PG_VERSION_NUM >= 90100)
|
||||||
extern int
|
extern int
|
||||||
xsnprintf(char *str, size_t size, const char *format,...)
|
xsnprintf(char *str, size_t size, const char *format,...)
|
||||||
__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
|
__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
|
||||||
@@ -42,5 +43,18 @@ __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
|
|||||||
extern int
|
extern int
|
||||||
maxlen_snprintf(char *str, const char *format,...)
|
maxlen_snprintf(char *str, const char *format,...)
|
||||||
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
|
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
|
||||||
|
#else
|
||||||
|
extern int
|
||||||
|
xsnprintf(char *str, size_t size, const char *format,...)
|
||||||
|
__attribute__((format(printf, 3, 4)));
|
||||||
|
|
||||||
|
extern int
|
||||||
|
sqlquery_snprintf(char *str, const char *format,...)
|
||||||
|
__attribute__((format(printf, 2, 3)));
|
||||||
|
|
||||||
|
extern int
|
||||||
|
maxlen_snprintf(char *str, const char *format,...)
|
||||||
|
__attribute__((format(printf, 2, 3)));
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _STRUTIL_H_ */
|
#endif /* _STRUTIL_H_ */
|
||||||
|
|||||||
Reference in New Issue
Block a user