mirror of
https://github.com/wassname/docker-postgresql.git
synced 2026-06-30 22:19:08 +08:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ca479d90cf | |||
| 8aa5c9b64f | |||
| 728f606b4d | |||
| b5dd975ad1 | |||
| 693995dd2b | |||
| 7601996544 |
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
FROM quay.io/sameersbn/ubuntu:14.04.20151023
|
FROM sameersbn/ubuntu:14.04.20151117
|
||||||
MAINTAINER sameer@damagehead.com
|
MAINTAINER sameer@damagehead.com
|
||||||
|
|
||||||
ENV PG_VERSION=9.4 \
|
ENV PG_VERSION=9.4 \
|
||||||
@@ -7,8 +7,8 @@ ENV PG_VERSION=9.4 \
|
|||||||
PG_RUNDIR=/run/postgresql \
|
PG_RUNDIR=/run/postgresql \
|
||||||
PG_LOGDIR=/var/log/postgresql
|
PG_LOGDIR=/var/log/postgresql
|
||||||
|
|
||||||
ENV PG_CONFDIR="/etc/postgresql/${PG_VERSION}/main" \
|
ENV PG_BINDIR="/usr/lib/postgresql/${PG_VERSION}/bin" \
|
||||||
PG_BINDIR="/usr/lib/postgresql/${PG_VERSION}/bin" \
|
PG_CONFDIR="${PG_HOME}/${PG_VERSION}/main" \
|
||||||
PG_DATADIR="${PG_HOME}/${PG_VERSION}/main"
|
PG_DATADIR="${PG_HOME}/${PG_VERSION}/main"
|
||||||
|
|
||||||
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
|
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
all: build
|
all: build
|
||||||
|
|
||||||
build:
|
build:
|
||||||
@docker build --tag=quay.io/sameersbn/postgresql .
|
@docker build --tag=sameersbn/postgresql .
|
||||||
|
|
||||||
release: build
|
release: build
|
||||||
@docker build --tag=quay.io/sameersbn/postgresql:$(shell cat VERSION) .
|
@docker build --tag=sameersbn/postgresql:$(shell cat VERSION) .
|
||||||
|
|||||||
@@ -57,10 +57,12 @@ In your issue report please make sure you provide the following information:
|
|||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
|
|
||||||
Automated builds of the image are available on [Quay.io](https://quay.io/repository/sameersbn/postgresql) and is the recommended method of installation.
|
Automated builds of the image are available on [Dockerhub](https://hub.docker.com/r/sameersbn/postgresql) and is the recommended method of installation.
|
||||||
|
|
||||||
|
> **Note**: Builds are also available on [Quay.io](https://quay.io/repository/sameersbn/postgresql)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker pull quay.io/sameersbn/postgresql:9.4-7
|
docker pull sameersbn/postgresql:9.4-8
|
||||||
```
|
```
|
||||||
|
|
||||||
Alternately you can build the image yourself.
|
Alternately you can build the image yourself.
|
||||||
@@ -76,7 +78,7 @@ docker build -t="$USER/postgresql" .
|
|||||||
Run the postgresql image
|
Run the postgresql image
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run --name postgresql -d quay.io/sameersbn/postgresql:9.4-7
|
docker run --name postgresql -d sameersbn/postgresql:9.4-8
|
||||||
```
|
```
|
||||||
|
|
||||||
The simplest way to login to the postgresql container as the administrative `postgres` user is to use the `docker exec` command to attach a new process to the running container and connect to the postgresql server over the unix socket.
|
The simplest way to login to the postgresql container as the administrative `postgres` user is to use the `docker exec` command to attach a new process to the running container and connect to the postgresql server over the unix socket.
|
||||||
@@ -100,7 +102,7 @@ The updated run command looks like this.
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run --name postgresql -d \
|
docker run --name postgresql -d \
|
||||||
-v /opt/postgresql/data:/var/lib/postgresql quay.io/sameersbn/postgresql:9.4-7
|
-v /opt/postgresql/data:/var/lib/postgresql sameersbn/postgresql:9.4-8
|
||||||
```
|
```
|
||||||
|
|
||||||
This will make sure that the data stored in the database is not lost when the image is stopped and started again.
|
This will make sure that the data stored in the database is not lost when the image is stopped and started again.
|
||||||
@@ -114,7 +116,7 @@ To create a new user you should specify the `DB_USER` and `DB_PASS` variables. T
|
|||||||
```bash
|
```bash
|
||||||
docker run --name postgresql -d \
|
docker run --name postgresql -d \
|
||||||
-e 'DB_USER=dbuser' -e 'DB_PASS=dbpass' \
|
-e 'DB_USER=dbuser' -e 'DB_PASS=dbpass' \
|
||||||
quay.io/sameersbn/postgresql:9.4-7
|
sameersbn/postgresql:9.4-8
|
||||||
```
|
```
|
||||||
|
|
||||||
**NOTE**
|
**NOTE**
|
||||||
@@ -125,7 +127,7 @@ Similarly, you can also create a new database by specifying the database name in
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run --name postgresql -d \
|
docker run --name postgresql -d \
|
||||||
-e 'DB_NAME=dbname' quay.io/sameersbn/postgresql:9.4-7
|
-e 'DB_NAME=dbname' sameersbn/postgresql:9.4-8
|
||||||
```
|
```
|
||||||
|
|
||||||
You may also specify a comma separated list of database names in the `DB_NAME` variable. The following command creates two new databases named *dbname1* and *dbname2* (p.s. this feature is only available in releases greater than 9.1-1).
|
You may also specify a comma separated list of database names in the `DB_NAME` variable. The following command creates two new databases named *dbname1* and *dbname2* (p.s. this feature is only available in releases greater than 9.1-1).
|
||||||
@@ -133,7 +135,7 @@ You may also specify a comma separated list of database names in the `DB_NAME` v
|
|||||||
```bash
|
```bash
|
||||||
docker run --name postgresql -d \
|
docker run --name postgresql -d \
|
||||||
-e 'DB_NAME=dbname1,dbname2' \
|
-e 'DB_NAME=dbname1,dbname2' \
|
||||||
quay.io/sameersbn/postgresql:9.4-7
|
sameersbn/postgresql:9.4-8
|
||||||
```
|
```
|
||||||
|
|
||||||
If the `DB_USER` and `DB_PASS` variables are also specified while creating the database, then the user is granted access to the database(s).
|
If the `DB_USER` and `DB_PASS` variables are also specified while creating the database, then the user is granted access to the database(s).
|
||||||
@@ -143,7 +145,7 @@ For example,
|
|||||||
```bash
|
```bash
|
||||||
docker run --name postgresql -d \
|
docker run --name postgresql -d \
|
||||||
-e 'DB_USER=dbuser' -e 'DB_PASS=dbpass' -e 'DB_NAME=dbname' \
|
-e 'DB_USER=dbuser' -e 'DB_PASS=dbpass' -e 'DB_NAME=dbname' \
|
||||||
quay.io/sameersbn/postgresql:9.4-7
|
sameersbn/postgresql:9.4-8
|
||||||
```
|
```
|
||||||
|
|
||||||
will create a user *dbuser* with the password *dbpass*. It will also create a database named *dbname* and the *dbuser* user will have full access to the *dbname* database.
|
will create a user *dbuser* with the password *dbpass*. It will also create a database named *dbname* and the *dbuser* user will have full access to the *dbname* database.
|
||||||
@@ -157,7 +159,7 @@ For example,
|
|||||||
```bash
|
```bash
|
||||||
docker run --name postgresql -d \
|
docker run --name postgresql -d \
|
||||||
-e 'PSQL_TRUST_LOCALNET=true' \
|
-e 'PSQL_TRUST_LOCALNET=true' \
|
||||||
quay.io/sameersbn/postgresql:9.4-7
|
sameersbn/postgresql:9.4-8
|
||||||
```
|
```
|
||||||
|
|
||||||
This has the effect of adding the following to the `pg_hba.conf` file:
|
This has the effect of adding the following to the `pg_hba.conf` file:
|
||||||
@@ -179,7 +181,7 @@ docker run --name='psql-master' -it --rm \
|
|||||||
-e 'PSQL_MODE=master' -e 'PSQL_TRUST_LOCALNET=true' \
|
-e 'PSQL_MODE=master' -e 'PSQL_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' \
|
||||||
quay.io/sameersbn/postgresql:9.4-7
|
sameersbn/postgresql:9.4-8
|
||||||
```
|
```
|
||||||
|
|
||||||
Create a streaming replication instance
|
Create a streaming replication instance
|
||||||
@@ -190,7 +192,7 @@ docker run --name='psql-slave' -it --rm \
|
|||||||
-e 'PSQL_MODE=slave' -e 'PSQL_TRUST_LOCALNET=true' \
|
-e 'PSQL_MODE=slave' -e 'PSQL_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' \
|
||||||
quay.io/sameersbn/postgresql:9.4-7
|
sameersbn/postgresql:9.4-8
|
||||||
```
|
```
|
||||||
|
|
||||||
# Enable Unaccent (Search plain text with accent)
|
# Enable Unaccent (Search plain text with accent)
|
||||||
@@ -202,7 +204,7 @@ By default unaccent is configure to `false`
|
|||||||
```bash
|
```bash
|
||||||
docker run --name postgresql -d \
|
docker run --name postgresql -d \
|
||||||
-e 'DB_UNACCENT=true' \
|
-e 'DB_UNACCENT=true' \
|
||||||
quay.io/sameersbn/postgresql:9.4-7
|
sameersbn/postgresql:9.4-8
|
||||||
```
|
```
|
||||||
|
|
||||||
# Host UID / GID Mapping
|
# Host UID / GID Mapping
|
||||||
@@ -214,7 +216,7 @@ Also the container processes seem to be executed as the host's user/group `[what
|
|||||||
```bash
|
```bash
|
||||||
docker run --name=postgresql -it --rm [options] \
|
docker run --name=postgresql -it --rm [options] \
|
||||||
--env="USERMAP_UID=$(id -u postgres)" --env="USERMAP_GID=$(id -g postgres)" \
|
--env="USERMAP_UID=$(id -u postgres)" --env="USERMAP_GID=$(id -g postgres)" \
|
||||||
quay.io/sameersbn/postgresql:9.4-7
|
sameersbn/postgresql:9.4-8
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -231,13 +233,13 @@ docker stop postgresql
|
|||||||
- **Step 2**: Update the docker image.
|
- **Step 2**: Update the docker image.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker pull quay.io/sameersbn/postgresql:9.4-7
|
docker pull sameersbn/postgresql:9.4-8
|
||||||
```
|
```
|
||||||
|
|
||||||
- **Step 3**: Start the image
|
- **Step 3**: Start the image
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run --name postgresql -d [OPTIONS] quay.io/sameersbn/postgresql:9.4-7
|
docker run --name postgresql -d [OPTIONS] sameersbn/postgresql:9.4-8
|
||||||
```
|
```
|
||||||
|
|
||||||
# Shell Access
|
# Shell Access
|
||||||
|
|||||||
+78
-81
@@ -61,8 +61,72 @@ create_data_dir
|
|||||||
create_log_dir
|
create_log_dir
|
||||||
create_run_dir
|
create_run_dir
|
||||||
|
|
||||||
# fix ownership of ${PG_CONFDIR} (may be necessary if USERMAP_* was set)
|
cd ${PG_HOME}
|
||||||
chown -R ${PG_USER}:${PG_USER} ${PG_CONFDIR}
|
|
||||||
|
# initialize PostgreSQL data directory
|
||||||
|
if [[ ! -d ${PG_DATADIR} ]]; then
|
||||||
|
if [[ ${PSQL_MODE} == slave || ${PSQL_MODE} == snapshot ]]; then
|
||||||
|
echo "Replicating database..."
|
||||||
|
if [[ ${PSQL_MODE} == snapshot ]]; then
|
||||||
|
sudo -Hu ${PG_USER} \
|
||||||
|
PGPASSWORD=$REPLICATION_PASS ${PG_BINDIR}/pg_basebackup -D ${PG_DATADIR} \
|
||||||
|
-h ${REPLICATION_HOST} -p ${REPLICATION_PORT} -U ${REPLICATION_USER} -w -x -v -P
|
||||||
|
elif [[ ${PSQL_MODE} == slave ]]; then
|
||||||
|
# Setup streaming replication.
|
||||||
|
sudo -Hu ${PG_USER} \
|
||||||
|
PGPASSWORD=$REPLICATION_PASS ${PG_BINDIR}/pg_basebackup -D ${PG_DATADIR} \
|
||||||
|
-h ${REPLICATION_HOST} -p ${REPLICATION_PORT} -U ${REPLICATION_USER} -X stream -w -v -P
|
||||||
|
echo "Setting up hot standby configuration..."
|
||||||
|
cat >> ${PG_CONFDIR}/postgresql.conf <<EOF
|
||||||
|
hot_standby = on
|
||||||
|
EOF
|
||||||
|
sudo -Hu ${PG_USER} touch ${PG_DATADIR}/recovery.conf
|
||||||
|
cat >> ${PG_DATADIR}/recovery.conf <<EOF
|
||||||
|
standby_mode = 'on'
|
||||||
|
primary_conninfo = 'host=${REPLICATION_HOST} port=${REPLICATION_PORT} user=${REPLICATION_USER} password=${REPLICATION_PASS} sslmode=${PSQL_SSLMODE}'
|
||||||
|
trigger_file = '/tmp/postgresql.trigger'
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
else
|
||||||
|
# check if we need to perform data migration
|
||||||
|
PG_OLD_VERSION=$(find ${PG_HOME}/[0-9].[0-9]/main -maxdepth 1 -name PG_VERSION 2>/dev/null | sort -r | head -n1 | cut -d'/' -f5)
|
||||||
|
|
||||||
|
if [[ $DB_LOCALE != C ]]; then
|
||||||
|
echo "Generating required locale \"${DB_LOCALE}\"..."
|
||||||
|
locale-gen ${DB_LOCALE} >/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Initializing database..."
|
||||||
|
sudo -Hu ${PG_USER} ${PG_BINDIR}/initdb --pgdata=${PG_DATADIR} \
|
||||||
|
--username=${PG_USER} --encoding=unicode --locale=${DB_LOCALE} --auth=trust >/dev/null
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n ${PG_OLD_VERSION} ]]; then
|
||||||
|
echo "Migrating postgresql ${PG_OLD_VERSION} data..."
|
||||||
|
PG_OLD_CONFDIR="${PG_HOME}/${PG_OLD_VERSION}/main"
|
||||||
|
PG_OLD_BINDIR="/usr/lib/postgresql/${PG_OLD_VERSION}/bin"
|
||||||
|
PG_OLD_DATADIR="${PG_HOME}/${PG_OLD_VERSION}/main"
|
||||||
|
|
||||||
|
# backup ${PG_OLD_DATADIR} to avoid data loss
|
||||||
|
PG_BKP_SUFFIX=$(date +%Y%m%d%H%M%S)
|
||||||
|
echo "Backing up ${PG_OLD_DATADIR} to ${PG_OLD_DATADIR}.${PG_BKP_SUFFIX}..."
|
||||||
|
cp -a ${PG_OLD_DATADIR} ${PG_OLD_DATADIR}.${PG_BKP_SUFFIX}
|
||||||
|
|
||||||
|
echo "Installing postgresql-${PG_OLD_VERSION}..."
|
||||||
|
apt-get update
|
||||||
|
DEBIAN_FRONTEND=noninteractive apt-get install postgresql-${PG_OLD_VERSION} postgresql-client-${PG_OLD_VERSION}
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# migrate ${PG_OLD_VERSION} data
|
||||||
|
echo "Migration in progress. This could take a while, please be patient..."
|
||||||
|
sudo -Hu ${PG_USER} ${PG_BINDIR}/pg_upgrade \
|
||||||
|
-b ${PG_OLD_BINDIR} -B ${PG_BINDIR} \
|
||||||
|
-d ${PG_OLD_DATADIR} -D ${PG_DATADIR} \
|
||||||
|
-o "-c config_file=${PG_OLD_CONFDIR}/postgresql.conf --hba_file=${PG_OLD_CONFDIR}/pg_hba.conf --ident_file=${PG_OLD_CONFDIR}/pg_ident.conf" \
|
||||||
|
-O "-c config_file=${PG_CONFDIR}/postgresql.conf --hba_file=${PG_CONFDIR}/pg_hba.conf --ident_file=${PG_CONFDIR}/pg_ident.conf" >/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ ${PSQL_SSLMODE} == disable ]]; then
|
if [[ ${PSQL_SSLMODE} == disable ]]; then
|
||||||
sed 's/ssl = true/#ssl = true/' -i ${PG_CONFDIR}/postgresql.conf
|
sed 's/ssl = true/#ssl = true/' -i ${PG_CONFDIR}/postgresql.conf
|
||||||
@@ -116,73 +180,6 @@ EOF
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd ${PG_HOME}
|
|
||||||
|
|
||||||
# initialize PostgreSQL data directory
|
|
||||||
if [[ ! -d ${PG_DATADIR} ]]; then
|
|
||||||
if [[ ${PSQL_MODE} == slave || ${PSQL_MODE} == snapshot ]]; then
|
|
||||||
echo "Replicating database..."
|
|
||||||
if [[ ${PSQL_MODE} == snapshot ]]; then
|
|
||||||
sudo -Hu ${PG_USER} \
|
|
||||||
PGPASSWORD=$REPLICATION_PASS ${PG_BINDIR}/pg_basebackup -D ${PG_DATADIR} \
|
|
||||||
-h ${REPLICATION_HOST} -p ${REPLICATION_PORT} -U ${REPLICATION_USER} -w -x -v -P
|
|
||||||
elif [[ ${PSQL_MODE} == slave ]]; then
|
|
||||||
# Setup streaming replication.
|
|
||||||
sudo -Hu ${PG_USER} \
|
|
||||||
PGPASSWORD=$REPLICATION_PASS ${PG_BINDIR}/pg_basebackup -D ${PG_DATADIR} \
|
|
||||||
-h ${REPLICATION_HOST} -p ${REPLICATION_PORT} -U ${REPLICATION_USER} -w -v -P
|
|
||||||
echo "Setting up hot standby configuration..."
|
|
||||||
cat >> ${PG_CONFDIR}/postgresql.conf <<EOF
|
|
||||||
hot_standby = on
|
|
||||||
EOF
|
|
||||||
sudo -Hu ${PG_USER} touch ${PG_DATADIR}/recovery.conf
|
|
||||||
cat >> ${PG_DATADIR}/recovery.conf <<EOF
|
|
||||||
standby_mode = 'on'
|
|
||||||
primary_conninfo = 'host=${REPLICATION_HOST} port=${REPLICATION_PORT} user=${REPLICATION_USER} password=${REPLICATION_PASS} sslmode=${PSQL_SSLMODE}'
|
|
||||||
trigger_file = '/tmp/postgresql.trigger'
|
|
||||||
EOF
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
# check if we need to perform data migration
|
|
||||||
PG_OLD_VERSION=$(find ${PG_HOME}/[0-9].[0-9]/main -maxdepth 1 -name PG_VERSION 2>/dev/null | sort -r | head -n1 | cut -d'/' -f5)
|
|
||||||
|
|
||||||
if [[ $DB_LOCALE != C ]]; then
|
|
||||||
echo "Generating required locale \"${DB_LOCALE}\"..."
|
|
||||||
locale-gen ${DB_LOCALE} >/dev/null
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Initializing database..."
|
|
||||||
sudo -Hu ${PG_USER} ${PG_BINDIR}/initdb --pgdata=${PG_DATADIR} \
|
|
||||||
--username=${PG_USER} --encoding=unicode --locale=${DB_LOCALE} --auth=trust >/dev/null
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n ${PG_OLD_VERSION} ]]; then
|
|
||||||
echo "Migrating postgresql ${PG_OLD_VERSION} data..."
|
|
||||||
PG_OLD_CONFDIR="/etc/postgresql/${PG_OLD_VERSION}/main"
|
|
||||||
PG_OLD_BINDIR="/usr/lib/postgresql/${PG_OLD_VERSION}/bin"
|
|
||||||
PG_OLD_DATADIR="${PG_HOME}/${PG_OLD_VERSION}/main"
|
|
||||||
|
|
||||||
# backup ${PG_OLD_DATADIR} to avoid data loss
|
|
||||||
PG_BKP_SUFFIX=$(date +%Y%m%d%H%M%S)
|
|
||||||
echo "Backing up ${PG_OLD_DATADIR} to ${PG_OLD_DATADIR}.${PG_BKP_SUFFIX}..."
|
|
||||||
cp -a ${PG_OLD_DATADIR} ${PG_OLD_DATADIR}.${PG_BKP_SUFFIX}
|
|
||||||
|
|
||||||
echo "Installing postgresql-${PG_OLD_VERSION}..."
|
|
||||||
apt-get update
|
|
||||||
DEBIAN_FRONTEND=noninteractive apt-get install postgresql-${PG_OLD_VERSION} postgresql-client-${PG_OLD_VERSION}
|
|
||||||
rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# migrate ${PG_OLD_VERSION} data
|
|
||||||
echo "Migration in progress. This could take a while, please be patient..."
|
|
||||||
sudo -Hu ${PG_USER} ${PG_BINDIR}/pg_upgrade \
|
|
||||||
-b ${PG_OLD_BINDIR} -B ${PG_BINDIR} \
|
|
||||||
-d ${PG_OLD_DATADIR} -D ${PG_DATADIR} \
|
|
||||||
-o "-c config_file=${PG_OLD_CONFDIR}/postgresql.conf" \
|
|
||||||
-O "-c config_file=${PG_CONFDIR}/postgresql.conf" >/dev/null
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Hot standby (slave and snapshot) servers can ignore the following code.
|
# Hot standby (slave and snapshot) servers can ignore the following code.
|
||||||
if [[ ${PSQL_MODE} == standalone || ${PSQL_MODE} == master ]]; then
|
if [[ ${PSQL_MODE} == standalone || ${PSQL_MODE} == master ]]; then
|
||||||
if [[ -n ${REPLICATION_USER} ]]; then
|
if [[ -n ${REPLICATION_USER} ]]; then
|
||||||
@@ -195,8 +192,8 @@ if [[ ${PSQL_MODE} == standalone || ${PSQL_MODE} == master ]]; then
|
|||||||
else
|
else
|
||||||
echo "Creating user \"${REPLICATION_USER}\"..."
|
echo "Creating user \"${REPLICATION_USER}\"..."
|
||||||
echo "CREATE ROLE \"${REPLICATION_USER}\" WITH REPLICATION LOGIN ENCRYPTED PASSWORD '${REPLICATION_PASS}';" |
|
echo "CREATE ROLE \"${REPLICATION_USER}\" WITH REPLICATION LOGIN ENCRYPTED PASSWORD '${REPLICATION_PASS}';" |
|
||||||
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single \
|
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single -D ${PG_DATADIR} \
|
||||||
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null
|
-c config_file=${PG_CONFDIR}/postgresql.conf --hba_file=${PG_CONFDIR}/pg_hba.conf --ident_file=${PG_CONFDIR}/pg_ident.conf >/dev/null
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -210,8 +207,8 @@ if [[ ${PSQL_MODE} == standalone || ${PSQL_MODE} == master ]]; then
|
|||||||
else
|
else
|
||||||
echo "Creating user \"${DB_USER}\"..."
|
echo "Creating user \"${DB_USER}\"..."
|
||||||
echo "CREATE ROLE \"${DB_USER}\" with LOGIN CREATEDB PASSWORD '${DB_PASS}';" |
|
echo "CREATE ROLE \"${DB_USER}\" with LOGIN CREATEDB PASSWORD '${DB_PASS}';" |
|
||||||
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single \
|
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single -D ${PG_DATADIR} \
|
||||||
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null
|
-c config_file=${PG_CONFDIR}/postgresql.conf --hba_file=${PG_CONFDIR}/pg_hba.conf --ident_file=${PG_CONFDIR}/pg_ident.conf >/dev/null
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -219,26 +216,26 @@ if [[ ${PSQL_MODE} == standalone || ${PSQL_MODE} == master ]]; then
|
|||||||
for db in $(awk -F',' '{for (i = 1 ; i <= NF ; i++) print $i}' <<< "${DB_NAME}"); do
|
for db in $(awk -F',' '{for (i = 1 ; i <= NF ; i++) print $i}' <<< "${DB_NAME}"); do
|
||||||
echo "Creating database \"${db}\"..."
|
echo "Creating database \"${db}\"..."
|
||||||
echo "CREATE DATABASE \"${db}\";" | \
|
echo "CREATE DATABASE \"${db}\";" | \
|
||||||
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single \
|
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single -D ${PG_DATADIR} \
|
||||||
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null
|
-c config_file=${PG_CONFDIR}/postgresql.conf --hba_file=${PG_CONFDIR}/pg_hba.conf --ident_file=${PG_CONFDIR}/pg_ident.conf >/dev/null
|
||||||
|
|
||||||
if [[ ${DB_UNACCENT} == true ]]; then
|
if [[ ${DB_UNACCENT} == true ]]; then
|
||||||
echo "Installing unaccent extension..."
|
echo "Installing unaccent extension..."
|
||||||
echo "CREATE EXTENSION IF NOT EXISTS unaccent;" | \
|
echo "CREATE EXTENSION IF NOT EXISTS unaccent;" | \
|
||||||
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single ${db} \
|
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single ${db} -D ${PG_DATADIR} \
|
||||||
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null
|
-c config_file=${PG_CONFDIR}/postgresql.conf --hba_file=${PG_CONFDIR}/pg_hba.conf --ident_file=${PG_CONFDIR}/pg_ident.conf >/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n ${DB_USER} ]]; then
|
if [[ -n ${DB_USER} ]]; then
|
||||||
echo "Granting access to database \"${db}\" for user \"${DB_USER}\"..."
|
echo "Granting access to database \"${db}\" for user \"${DB_USER}\"..."
|
||||||
echo "GRANT ALL PRIVILEGES ON DATABASE \"${db}\" to \"${DB_USER}\";" |
|
echo "GRANT ALL PRIVILEGES ON DATABASE \"${db}\" to \"${DB_USER}\";" |
|
||||||
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single \
|
sudo -Hu ${PG_USER} ${PG_BINDIR}/postgres --single -D ${PG_DATADIR} \
|
||||||
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf >/dev/null
|
-c config_file=${PG_CONFDIR}/postgresql.conf --hba_file=${PG_CONFDIR}/pg_hba.conf --ident_file=${PG_CONFDIR}/pg_ident.conf >/dev/null
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Starting PostgreSQL server..."
|
echo "Starting PostgreSQL server..."
|
||||||
exec start-stop-daemon --start --chuid ${PG_USER}:${PG_USER} --exec ${PG_BINDIR}/postgres -- \
|
exec start-stop-daemon --start --chuid ${PG_USER}:${PG_USER} --exec ${PG_BINDIR}/postgres -- -D ${PG_DATADIR} \
|
||||||
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf
|
-c config_file=${PG_CONFDIR}/postgresql.conf --hba_file=${PG_CONFDIR}/pg_hba.conf --ident_file=${PG_CONFDIR}/pg_ident.conf
|
||||||
|
|||||||
Reference in New Issue
Block a user