PSQL_MODE config parameter renamed to REPLICATION_MODE

This commit is contained in:
Sameer Naik
2015-11-26 21:03:51 +05:30
parent de5295ffa7
commit b6f0cba6a7
3 changed files with 12 additions and 10 deletions
+1
View File
@@ -3,6 +3,7 @@
**latest** **latest**
- complete rewrite - complete rewrite
- `PSQL_TRUST_LOCALNET` config parameter renamed to `PG_TRUST_LOCALNET` - `PSQL_TRUST_LOCALNET` config parameter renamed to `PG_TRUST_LOCALNET`
- `PSQL_MODE` config parameter renamed to `REPLICATION_MODE`
**9.4-2** **9.4-2**
- added replication options - added replication options
+4 -4
View File
@@ -168,15 +168,15 @@ host all all samenet trust
# Creating a Snapshot or Slave Database # Creating a Snapshot or Slave Database
You may use the `PSQL_MODE` variable along with `REPLICATION_HOST`, `REPLICATION_PORT`, `REPLICATION_USER` and `REPLICATION_PASS` to create a snapshot of an existing database and enable stream replication. You may use the `REPLICATION_MODE` variable along with `REPLICATION_HOST`, `REPLICATION_PORT`, `REPLICATION_USER` and `REPLICATION_PASS` to create a snapshot of an existing database and enable stream replication.
Your master database must support replication or super-user access for the credentials you specify. The `PSQL_MODE` variable should be set to `master`, for replication on your master node and `slave` or `snapshot` respectively for streaming replication or a point-in-time snapshot of a running instance. Your master database must support replication or super-user access for the credentials you specify. The `REPLICATION_MODE` variable should be set to `master`, for replication on your master node and `slave` or `snapshot` respectively for streaming replication or a point-in-time snapshot of a running instance.
Create a master instance Create a master instance
```bash ```bash
docker run --name='psql-master' -it --rm \ docker run --name='psql-master' -it --rm \
-e 'PSQL_MODE=master' -e 'PG_TRUST_LOCALNET=true' \ -e 'REPLICATION_MODE=master' -e 'PG_TRUST_LOCALNET=true' \
-e 'REPLICATION_USER=replicator' -e 'REPLICATION_PASS=replicatorpass' \ -e 'REPLICATION_USER=replicator' -e 'REPLICATION_PASS=replicatorpass' \
-e 'DB_NAME=dbname' -e 'DB_USER=dbuser' -e 'DB_PASS=dbpass' \ -e 'DB_NAME=dbname' -e 'DB_USER=dbuser' -e 'DB_PASS=dbpass' \
sameersbn/postgresql:9.4-8 sameersbn/postgresql:9.4-8
@@ -187,7 +187,7 @@ Create a streaming replication instance
```bash ```bash
docker run --name='psql-slave' -it --rm \ docker run --name='psql-slave' -it --rm \
--link psql-master:psql-master \ --link psql-master:psql-master \
-e 'PSQL_MODE=slave' -e 'PG_TRUST_LOCALNET=true' \ -e 'REPLICATION_MODE=slave' -e 'PG_TRUST_LOCALNET=true' \
-e 'REPLICATION_HOST=psql-master' -e 'REPLICATION_PORT=5432' \ -e 'REPLICATION_HOST=psql-master' -e 'REPLICATION_PORT=5432' \
-e 'REPLICATION_USER=replicator' -e 'REPLICATION_PASS=replicatorpass' \ -e 'REPLICATION_USER=replicator' -e 'REPLICATION_PASS=replicatorpass' \
sameersbn/postgresql:9.4-8 sameersbn/postgresql:9.4-8
+7 -6
View File
@@ -1,12 +1,13 @@
#!/bin/bash #!/bin/bash
set -e set -e
PSQL_MODE=${PSQL_MODE:-}
PSQL_SSLMODE=${PSQL_SSLMODE:-} PSQL_SSLMODE=${PSQL_SSLMODE:-}
PG_TRUST_LOCALNET=${PG_TRUST_LOCALNET:-$PSQL_TRUST_LOCALNET} # backward compatibility PG_TRUST_LOCALNET=${PG_TRUST_LOCALNET:-$PSQL_TRUST_LOCALNET} # backward compatibility
PG_TRUST_LOCALNET=${PG_TRUST_LOCALNET:-false} PG_TRUST_LOCALNET=${PG_TRUST_LOCALNET:-false}
REPLICATION_MODE=${REPLICATION_MODE:-$PSQL_MODE} # backward compatibility
REPLICATION_MODE=${REPLICATION_MODE:-}
REPLICATION_USER=${REPLICATION_USER:-} REPLICATION_USER=${REPLICATION_USER:-}
REPLICATION_PASS=${REPLICATION_PASS:-} REPLICATION_PASS=${REPLICATION_PASS:-}
REPLICATION_HOST=${REPLICATION_HOST:-} REPLICATION_HOST=${REPLICATION_HOST:-}
@@ -105,7 +106,7 @@ set_hba_param() {
} }
configure_hot_standby() { configure_hot_standby() {
case ${PSQL_MODE} in case ${REPLICATION_MODE} in
slave|snapshot) ;; slave|snapshot) ;;
*) *)
echo "Configuring hot standby..." echo "Configuring hot standby..."
@@ -120,7 +121,7 @@ configure_hot_standby() {
initialize_database() { initialize_database() {
if [[ ! -f ${PG_DATADIR}/PG_VERSION ]]; then if [[ ! -f ${PG_DATADIR}/PG_VERSION ]]; then
case ${PSQL_MODE} in case ${REPLICATION_MODE} in
slave|snapshot) slave|snapshot)
# default params # default params
REPLICATION_PORT=${REPLICATION_PORT:-5432} REPLICATION_PORT=${REPLICATION_PORT:-5432}
@@ -155,7 +156,7 @@ initialize_database() {
done done
echo echo
case ${PSQL_MODE} in case ${REPLICATION_MODE} in
slave) slave)
echo "Replicating initial data from $REPLICATION_HOST..." echo "Replicating initial data from $REPLICATION_HOST..."
exec_as_postgres PGPASSWORD=$REPLICATION_PASS ${PG_BINDIR}/pg_basebackup -D ${PG_DATADIR} \ exec_as_postgres PGPASSWORD=$REPLICATION_PASS ${PG_BINDIR}/pg_basebackup -D ${PG_DATADIR} \
@@ -272,7 +273,7 @@ create_database() {
} }
create_replication_user() { create_replication_user() {
case $PSQL_MODE in case $REPLICATION_MODE in
slave|snapshot) ;; # replication user can only be created on the master slave|snapshot) ;; # replication user can only be created on the master
*) *)
if [[ -n ${REPLICATION_USER} ]]; then if [[ -n ${REPLICATION_USER} ]]; then
@@ -293,7 +294,7 @@ create_replication_user() {
configure_recovery() { configure_recovery() {
if [[ ! -f ${PG_RECOVERY_CONF} ]]; then if [[ ! -f ${PG_RECOVERY_CONF} ]]; then
if [[ ${PSQL_MODE} == slave ]]; then if [[ ${REPLICATION_MODE} == slave ]]; then
# initialize recovery.conf on the firstrun (slave only) # initialize recovery.conf on the firstrun (slave only)
echo "Configuring recovery..." echo "Configuring recovery..."
exec_as_postgres touch ${PG_RECOVERY_CONF} exec_as_postgres touch ${PG_RECOVERY_CONF}