Stacksmith merger (#24)
* switch to harpoon installer * switch to `gcr.io/stacksmith-images/ubuntu:14.04` base image * removed unused files * switch to `gcr.io/stacksmith-images/ubuntu:14.04` base image * organize dockerfile for stacksmith (#2) * verify checksum in harpoon commands * removed `BITNAMI_APP_DIR` macro * removed `BITNAMI_APP_VOL_PREFIX` macro * moved hacks to `app-entrypoint.sh` * organize dockerfile for stacksmith * tests: updated * Bump version (#3) * upgrade to `gcr.io/stacksmith-images/ubuntu:14.04-r06` * upgrade to `postgresql-9.4.5-1` * password for `postgres` user is now optional * upgrade to `postgresql-9.4.5-2` * organize dockerfile * ignore `.git/` and `tests/` directories in docker builds * ignore `pkg-cache/` in git * add `/opt/bitnami/$BITNAMI_APP_NAME/sbin` to `PATH` * upgrade to `gcr.io/stacksmith-images/ubuntu:14.04-r07` baseimage * tests: cannot login as postgres user without a password * add `POSTGRES_DB` env param to create database * add `POSTGRES_USER` env param to create custom user * add parameters to support master/slave replication * update to postgresql-9.5.3-0 * readme: updated * updated to `postgresql-9.5.3-1`
This commit is contained in:
parent
50e9f69ac9
commit
6d31d367e2
|
|
@ -0,0 +1,2 @@
|
||||||
|
.git/
|
||||||
|
tests/
|
||||||
|
|
@ -1 +1 @@
|
||||||
*.run
|
pkg-cache/
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,17 @@
|
||||||
FROM bitnami/base-ubuntu:14.04-onbuild
|
FROM gcr.io/stacksmith-images/ubuntu:14.04-r07
|
||||||
MAINTAINER Bitnami <containers@bitnami.com>
|
MAINTAINER Bitnami <containers@bitnami.com>
|
||||||
|
|
||||||
ENV BITNAMI_APP_DIR=$BITNAMI_PREFIX/postgresql \
|
ENV BITNAMI_IMAGE_VERSION=9.5.3-r0 \
|
||||||
BITNAMI_APP_NAME=postgresql \
|
BITNAMI_APP_NAME=postgresql \
|
||||||
BITNAMI_APP_DAEMON=postgres \
|
BITNAMI_APP_USER=postgres
|
||||||
BITNAMI_APP_USER=postgres \
|
|
||||||
BITNAMI_APP_VERSION=9.5.2-0
|
|
||||||
|
|
||||||
ENV BITNAMI_APP_VOL_PREFIX=/bitnami/$BITNAMI_APP_NAME \
|
RUN bitnami-pkg unpack postgresql-9.5.3-1 --checksum 458ac1d3beb5b250af17ee7b829c061867d770b6655379528c2b2339f2e426ef
|
||||||
PATH=$BITNAMI_APP_DIR/bin:$PATH
|
ENV PATH=/opt/bitnami/$BITNAMI_APP_NAME/sbin:/opt/bitnami/$BITNAMI_APP_NAME/bin:$PATH
|
||||||
|
|
||||||
RUN $BITNAMI_PREFIX/install.sh\
|
|
||||||
--postgres_password bitnami
|
|
||||||
|
|
||||||
COPY rootfs/ /
|
COPY rootfs/ /
|
||||||
|
ENTRYPOINT ["/app-entrypoint.sh"]
|
||||||
|
CMD ["harpoon", "start", "--foreground", "postgresql"]
|
||||||
|
|
||||||
|
VOLUME ["/bitnami/$BITNAMI_APP_NAME"]
|
||||||
|
|
||||||
EXPOSE 5432
|
EXPOSE 5432
|
||||||
VOLUME ["$BITNAMI_APP_VOL_PREFIX/data", "$BITNAMI_APP_VOL_PREFIX/conf", "$BITNAMI_APP_VOL_PREFIX/logs"]
|
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,14 @@
|
||||||
# TLDR
|
# TLDR
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run --name postgresql -e POSTGRES_PASSWORD=password123 bitnami/postgresql
|
docker run --name postgresql -e POSTGRES_PASSWORD=password123 bitnami/postgresql:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
## Docker Compose
|
## Docker Compose
|
||||||
|
|
||||||
```
|
```yaml
|
||||||
postgresql:
|
postgresql:
|
||||||
image: bitnami/postgresql
|
image: bitnami/postgresql:latest
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_PASSWORD=password123
|
- POSTGRES_PASSWORD=password123
|
||||||
```
|
```
|
||||||
|
|
@ -36,31 +36,30 @@ docker pull bitnami/postgresql:[TAG]
|
||||||
If you wish, you can also build the image yourself.
|
If you wish, you can also build the image yourself.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/bitnami/bitnami-docker-postgresql.git
|
docker build -t bitnami/postgresql:latest https://github.com/bitnami/bitnami-docker-postgresql.git
|
||||||
cd bitnami-docker-postgresql
|
|
||||||
docker build -t bitnami/postgresql .
|
|
||||||
```
|
```
|
||||||
|
|
||||||
# Persisting your database
|
# Persisting your database
|
||||||
|
|
||||||
If you remove the container all your data will be lost, and the next time you run the image the database will be reinitialized. To avoid this loss of data, you should mount a volume that will persist even after the container is removed.
|
If you remove the container all your data and configurations will be lost, and the next time you run the image the database will be reinitialized. To avoid this loss of data, you should mount a volume that will persist even after the container is removed.
|
||||||
|
|
||||||
**Note!**
|
**Note!**
|
||||||
If you have already started using your database, follow the steps on [backing up](#backing-up-your-container) and [restoring](#restoring-a-backup) to pull the data from your running container down to your host.
|
If you have already started using your database, follow the steps on
|
||||||
|
[backing up](#backing-up-your-container) and [restoring](#restoring-a-backup) to pull the data from your running container down to your host.
|
||||||
|
|
||||||
The PostgreSQL image exposes a volume at `/bitnami/postgresql/data`, you can mount a directory from your host to serve as the data store. If the directory you mount is empty, the database will be initialized.
|
The image exposes a volume at `/bitnami/postgresql` for the PostgreSQL data and configurations. For persistence you can mount a directory at this location from your host. If the mounted directory is empty, it will be initialized on the first run.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run -v /path/to/data:/bitnami/postgresql/data bitnami/postgresql
|
docker run -v /path/to/postgresql-persistence:/bitnami/postgresql bitnami/postgresql:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
or using Docker Compose:
|
or using Docker Compose:
|
||||||
|
|
||||||
```
|
```yaml
|
||||||
postgresql:
|
postgresql:
|
||||||
image: bitnami/postgresql
|
image: bitnami/postgresql:latest
|
||||||
volumes:
|
volumes:
|
||||||
- /path/to/data:/bitnami/postgresql/data
|
- /path/to/postgresql-persistence:/bitnami/postgresql
|
||||||
```
|
```
|
||||||
|
|
||||||
# Linking
|
# Linking
|
||||||
|
|
@ -76,7 +75,7 @@ The first step is to start our PostgreSQL server.
|
||||||
Docker's linking system uses container ids or names to reference containers. We can explicitly specify a name for our PostgreSQL server to make it easier to connect to other containers.
|
Docker's linking system uses container ids or names to reference containers. We can explicitly specify a name for our PostgreSQL server to make it easier to connect to other containers.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run --name postgresql -e POSTGRES_PASSWORD=password123 bitnami/postgresql
|
docker run --name postgresql -e POSTGRES_PASSWORD=password123 bitnami/postgresql:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
### Step 2: Run PostgreSQL image as a client and link to our server
|
### Step 2: Run PostgreSQL image as a client and link to our server
|
||||||
|
|
@ -104,9 +103,9 @@ docker exec -it postgresql psql -U postgres
|
||||||
|
|
||||||
Copy the snippet below into your `docker-compose.yml` to add PostgreSQL to your application.
|
Copy the snippet below into your `docker-compose.yml` to add PostgreSQL to your application.
|
||||||
|
|
||||||
```
|
```yaml
|
||||||
postgresql:
|
postgresql:
|
||||||
image: bitnami/postgresql
|
image: bitnami/postgresql:latest
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_PASSWORD=password123
|
- POSTGRES_PASSWORD=password123
|
||||||
```
|
```
|
||||||
|
|
@ -115,7 +114,7 @@ postgresql:
|
||||||
|
|
||||||
Update the definitions for containers you want to access your PostgreSQL server from to include a link to the `postgresql` entry you added in Step 1.
|
Update the definitions for containers you want to access your PostgreSQL server from to include a link to the `postgresql` entry you added in Step 1.
|
||||||
|
|
||||||
```
|
```yaml
|
||||||
myapp:
|
myapp:
|
||||||
image: myapp
|
image: myapp
|
||||||
links:
|
links:
|
||||||
|
|
@ -131,14 +130,14 @@ Inside `myapp`, use `postgresql` as the hostname for the PostgreSQL server.
|
||||||
In the above commands you may have noticed the use of the `POSTGRES_PASSWORD` environment variable. Passing the `POSTGRES_PASSWORD` environment variable when running the image for the first time will set the password of the `postgres` user to the value of `POSTGRES_PASSWORD`.
|
In the above commands you may have noticed the use of the `POSTGRES_PASSWORD` environment variable. Passing the `POSTGRES_PASSWORD` environment variable when running the image for the first time will set the password of the `postgres` user to the value of `POSTGRES_PASSWORD`.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run --name postgresql -e POSTGRES_PASSWORD=password123 bitnami/postgresql
|
docker run --name postgresql -e POSTGRES_PASSWORD=password123 bitnami/postgresql:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
or using Docker Compose:
|
or using Docker Compose:
|
||||||
|
|
||||||
```
|
```yaml
|
||||||
postgresql:
|
postgresql:
|
||||||
image: bitnami/postgresql
|
image: bitnami/postgresql:latest
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_PASSWORD=password123
|
- POSTGRES_PASSWORD=password123
|
||||||
```
|
```
|
||||||
|
|
@ -151,14 +150,14 @@ The `postgres` user is a superuser and has full administrative access to the Pos
|
||||||
By passing the `POSTGRES_DB` environment variable when running the image for the first time, a database will be created. This is useful if your application requires that a database already exists, saving you from having to manually create the database using the PostgreSQL client.
|
By passing the `POSTGRES_DB` environment variable when running the image for the first time, a database will be created. This is useful if your application requires that a database already exists, saving you from having to manually create the database using the PostgreSQL client.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run --name postgresql -e POSTGRES_DB=my_database bitnami/postgresql
|
docker run --name postgresql -e POSTGRES_DB=my_database bitnami/postgresql:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
or using Docker Compose:
|
or using Docker Compose:
|
||||||
|
|
||||||
```
|
```yaml
|
||||||
postgresql:
|
postgresql:
|
||||||
image: bitnami/postgresql
|
image: bitnami/postgresql:latest
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_DB=my_database
|
- POSTGRES_DB=my_database
|
||||||
```
|
```
|
||||||
|
|
@ -168,14 +167,14 @@ postgresql:
|
||||||
You can also create a restricted database user that only has permissions for the database created with the [`POSTGRES_DB`](#creating-a-database-on-first-run) environment variable. To do this, provide the `POSTGRES_USER` environment variable.
|
You can also create a restricted database user that only has permissions for the database created with the [`POSTGRES_DB`](#creating-a-database-on-first-run) environment variable. To do this, provide the `POSTGRES_USER` environment variable.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run --name postgresql -e POSTGRES_USER=my_user -e POSTGRES_PASSWORD=password123 -e POSTGRES_DB=my_database bitnami/postgresql
|
docker run --name postgresql -e POSTGRES_USER=my_user -e POSTGRES_PASSWORD=password123 -e POSTGRES_DB=my_database bitnami/postgresql:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
or using Docker Compose:
|
or using Docker Compose:
|
||||||
|
|
||||||
```
|
```yaml
|
||||||
postgresql:
|
postgresql:
|
||||||
image: bitnami/postgresql
|
image: bitnami/postgresql:latest
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_USER=my_user
|
- POSTGRES_USER=my_user
|
||||||
- POSTGRES_PASSWORD=password123
|
- POSTGRES_PASSWORD=password123
|
||||||
|
|
@ -189,15 +188,13 @@ When `POSTGRES_USER` is specified, the `postgres` user is not assigned a passwor
|
||||||
|
|
||||||
A [Streaming replication](http://www.postgresql.org/docs/9.4/static/warm-standby.html#STREAMING-REPLICATION) cluster can easily be setup with the Bitnami PostgreSQL Docker Image using the following environment variables:
|
A [Streaming replication](http://www.postgresql.org/docs/9.4/static/warm-standby.html#STREAMING-REPLICATION) cluster can easily be setup with the Bitnami PostgreSQL Docker Image using the following environment variables:
|
||||||
|
|
||||||
- `POSTGRES_MODE`: Replication mode. Possible values `master`/`slave` (default: master).
|
- `POSTGRES_MODE`: Replication mode. Possible values `master`/`slave`. No defaults.
|
||||||
- `POSTGRES_REPLICATION_USER`: Replication user. User is created on the master at first boot (default: none).
|
- `POSTGRES_REPLICATION_USER`: The replication user created on the master on first run. No defaults.
|
||||||
- `POSTGRES_REPLICATION_PASSWORD`: Replication users password. Password is set for `POSTGRES_REPLICATION_USER` on master on the first boot (default: none).
|
- `POSTGRES_REPLICATION_PASSWORD`: The replication users password. No defaults.
|
||||||
- `POSTGRES_MASTER_HOST`: Hostname/IP of replication master (parameter available only on slave).
|
- `POSTGRES_MASTER_HOST`: Hostname/IP of replication master (slave parameter). No defaults.
|
||||||
- `POSTGRES_MASTER_PORT`: Port of replication master, defaults to `5432` (parameter available only on slave).
|
- `POSTGRES_MASTER_PORT`: Server port of the replication master (slave parameter). Defaults to `5432`.
|
||||||
|
|
||||||
In a replication cluster you can have one master and zero or more slaves. Our default configuration allows a maximum of 16 slaves, you can change it in `postgresql.conf` if required.
|
In a replication cluster you can have one master and zero or more slaves. When replication is enabled the master node is in read-write mode, while the slaves are in read-only mode. For best performance its advisable to limit the reads to the slaves.
|
||||||
|
|
||||||
When replication is enabled writes can occur only on the master while reads can take place on both the master or slaves. For best performance you should limit the reads to the slaves and use the master only for the writes.
|
|
||||||
|
|
||||||
### Step 1: Create the replication master
|
### Step 1: Create the replication master
|
||||||
|
|
||||||
|
|
@ -211,12 +208,10 @@ docker run --name postgresql-master \
|
||||||
-e POSTGRES_DB=my_database \
|
-e POSTGRES_DB=my_database \
|
||||||
-e POSTGRES_REPLICATION_USER=my_repl_user \
|
-e POSTGRES_REPLICATION_USER=my_repl_user \
|
||||||
-e POSTGRES_REPLICATION_PASSWORD=my_repl_password \
|
-e POSTGRES_REPLICATION_PASSWORD=my_repl_password \
|
||||||
bitnami/postgresql
|
bitnami/postgresql:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
In this command we are configuring the container as the master using the `POSTGRES_MODE=master` parameter. Using the `POSTGRES_REPLICATION_USER` and `POSTGRES_REPLICATION_PASSWORD` parameters we are creating a replication user that will be used by the slaves to connect to the master and perform streaming replication.
|
In this command we are configuring the container as the master using the `POSTGRES_MODE=master` parameter. A replication user is specified using the `POSTGRES_REPLICATION_USER` and `POSTGRES_REPLICATION_PASSWORD` parameters.
|
||||||
|
|
||||||
By default a container is configured as a `master`. As a result you can drop the `POSTGRES_MODE=master` from the above command.
|
|
||||||
|
|
||||||
### Step 2: Create the replication slave
|
### Step 2: Create the replication slave
|
||||||
|
|
||||||
|
|
@ -230,28 +225,12 @@ docker run --name postgresql-slave \
|
||||||
-e POSTGRES_MASTER_PORT=5432 \
|
-e POSTGRES_MASTER_PORT=5432 \
|
||||||
-e POSTGRES_REPLICATION_USER=my_repl_user \
|
-e POSTGRES_REPLICATION_USER=my_repl_user \
|
||||||
-e POSTGRES_REPLICATION_PASSWORD=my_repl_password \
|
-e POSTGRES_REPLICATION_PASSWORD=my_repl_password \
|
||||||
bitnami/postgresql
|
bitnami/postgresql:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
In this command we are configuring the container as a slave using the `POSTGRES_MODE=slave` parameter. Before the replication slave is started, the `POSTGRES_MASTER_HOST` and `POSTGRES_MASTER_PORT` parameters are used by the slave container to connect to the master and replicate the initial database from the master. The `POSTGRES_REPLICATION_USER` and `POSTGRES_REPLICATION_PASSWORD` credentials are used to authenticate with the master.
|
In the above command the container is configured as a `slave` using the `POSTGRES_REPLICATION_MODE` parameter. Before the replication slave is started, the `POSTGRES_MASTER_HOST` and `POSTGRES_MASTER_PORT` parameters are used by the slave container to connect to the master and replicate the initial database from the master. The `POSTGRES_REPLICATION_USER` and `POSTGRES_REPLICATION_PASSWORD` credentials are used to authenticate with the master.
|
||||||
|
|
||||||
Using the `master` docker link alias, the Bitnami PostgreSQL Docker image automatically fetches the replication paramaters from the master container, namely:
|
With these two commands you now have a two node PostgreSQL master-slave streaming replication cluster up and running. You can scale the cluster by adding/removing slaves without incurring any downtime.
|
||||||
|
|
||||||
- `POSTGRES_MASTER_HOST`
|
|
||||||
- `POSTGRES_MASTER_PORT`
|
|
||||||
- `POSTGRES_REPLICATION_USER`
|
|
||||||
- `POSTGRES_REPLICATION_PASSWORD`
|
|
||||||
|
|
||||||
As a result you can drop all of these parameters from the slave.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
docker run --name postgresql-slave \
|
|
||||||
--link postgresql-master:master \
|
|
||||||
-e POSTGRES_MODE=slave \
|
|
||||||
bitnami/postgresql
|
|
||||||
```
|
|
||||||
|
|
||||||
With these two commands you now have a two node PostgreSQL master-slave streaming replication cluster up and running. When required you can add more slaves to the cluster without any downtime allowing you to scale the cluster horizontally.
|
|
||||||
|
|
||||||
> **Note**: The cluster replicates the master in its entirety, which includes all users and databases.
|
> **Note**: The cluster replicates the master in its entirety, which includes all users and databases.
|
||||||
|
|
||||||
|
|
@ -267,7 +246,7 @@ With Docker Compose the master-slave replication can be setup using:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
master:
|
master:
|
||||||
image: bitnami/postgresql
|
image: bitnami/postgresql:latest
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_MODE=master
|
- POSTGRES_MODE=master
|
||||||
- POSTGRES_USER=my_user
|
- POSTGRES_USER=my_user
|
||||||
|
|
@ -277,11 +256,15 @@ master:
|
||||||
- POSTGRES_REPLICATION_PASSWORD=my_repl_password
|
- POSTGRES_REPLICATION_PASSWORD=my_repl_password
|
||||||
|
|
||||||
slave:
|
slave:
|
||||||
image: bitnami/postgresql
|
image: bitnami/postgresql:latest
|
||||||
links:
|
links:
|
||||||
- master:master
|
- master:master
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_MODE=slave
|
- POSTGRES_MODE=slave
|
||||||
|
- POSTGRES_MASTER_HOST=master
|
||||||
|
- POSTGRES_MASTER_PORT=5432
|
||||||
|
- POSTGRES_REPLICATION_USER=my_repl_user
|
||||||
|
- POSTGRES_REPLICATION_PASSWORD=my_repl_password
|
||||||
```
|
```
|
||||||
|
|
||||||
Scale the number of slaves using:
|
Scale the number of slaves using:
|
||||||
|
|
@ -294,46 +277,25 @@ The above command scales up the number of slaves to `3`. You can scale down in t
|
||||||
|
|
||||||
> **Note**: You should not scale up/down the number of master nodes. Always have only one master node running.
|
> **Note**: You should not scale up/down the number of master nodes. Always have only one master node running.
|
||||||
|
|
||||||
## Command-line options
|
|
||||||
|
|
||||||
The simplest way to configure your PostgreSQL server is to pass custom command-line options when running the image.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
docker run bitnami/postgresql -N 1000
|
|
||||||
```
|
|
||||||
|
|
||||||
or using Docker Compose:
|
|
||||||
|
|
||||||
```
|
|
||||||
postgresql:
|
|
||||||
image: bitnami/postgresql
|
|
||||||
command: -N 1000
|
|
||||||
```
|
|
||||||
|
|
||||||
**Further Reading:**
|
|
||||||
|
|
||||||
- [Server Command Options](http://www.postgresql.org/docs/9.4/static/app-postgres.html)
|
|
||||||
- [Caveats](#caveats)
|
|
||||||
|
|
||||||
## Configuration file
|
## Configuration file
|
||||||
|
|
||||||
This image looks for configuration in `/bitnami/postgresql/conf`. You can mount a volume there with your own configuration, or the default configuration will be copied to your volume if it is empty.
|
The image looks for configuration in the `conf/` directory of `/bitnami/postgresql`. As as mentioned in [Persisting your database](#persisting-your-data) you can mount a volume at this location and copy your own configurations in the `conf/` directory. The default configuration will be copied to the `conf/` directory if it's empty.
|
||||||
|
|
||||||
### Step 1: Run the PostgreSQL image
|
### Step 1: Run the PostgreSQL image
|
||||||
|
|
||||||
Run the PostgreSQL image, mounting a directory from your host.
|
Run the PostgreSQL image, mounting a directory from your host.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run --name postgresql -v /path/to/postgresql/conf:/bitnami/postgresql/conf bitnami/postgresql
|
docker run --name postgresql -v /path/to/postgresql-persistence:/bitnami/postgresql bitnami/postgresql:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
or using Docker Compose:
|
or using Docker Compose:
|
||||||
|
|
||||||
```
|
```yaml
|
||||||
postgresql:
|
postgresql:
|
||||||
image: bitnami/postgresql
|
image: bitnami/postgresql:latest
|
||||||
volumes:
|
volumes:
|
||||||
- /path/to/postgresql/conf:/bitnami/postgresql/conf
|
- /path/to/postgresql-persistence:/bitnami/postgresql
|
||||||
```
|
```
|
||||||
|
|
||||||
### Step 2: Edit the configuration
|
### Step 2: Edit the configuration
|
||||||
|
|
@ -341,7 +303,7 @@ postgresql:
|
||||||
Edit the configuration on your host using your favorite editor.
|
Edit the configuration on your host using your favorite editor.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
vi /path/to/postgresql/conf/my.cnf
|
vi /path/to/postgresql-persistence/conf/postgresql.conf
|
||||||
```
|
```
|
||||||
|
|
||||||
### Step 3: Restart PostgreSQL
|
### Step 3: Restart PostgreSQL
|
||||||
|
|
@ -361,18 +323,6 @@ docker-compose restart postgresql
|
||||||
**Further Reading:**
|
**Further Reading:**
|
||||||
|
|
||||||
- [Server Configuration](http://www.postgresql.org/docs/9.4/static/runtime-config.html)
|
- [Server Configuration](http://www.postgresql.org/docs/9.4/static/runtime-config.html)
|
||||||
- [Caveats](#caveats)
|
|
||||||
|
|
||||||
## Caveats
|
|
||||||
|
|
||||||
The following options cannot be modified, to ensure that the image runs correctly.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
-D /opt/bitnami/postgresql/data
|
|
||||||
--config_file=/opt/bitnami/postgresql/conf/postgresql.conf
|
|
||||||
--hba_file=/opt/bitnami/postgresql/conf/pg_hba.conf
|
|
||||||
--ident_file=/opt/bitnami/postgresql/conf/pg_ident.conf
|
|
||||||
```
|
|
||||||
|
|
||||||
# Logging
|
# Logging
|
||||||
|
|
||||||
|
|
@ -394,24 +344,21 @@ docker-compose logs postgresql
|
||||||
|
|
||||||
This method of logging has the downside of not being easy to manage. Without an easy way to rotate logs, they could grow exponentially and take up large amounts of disk space on your host.
|
This method of logging has the downside of not being easy to manage. Without an easy way to rotate logs, they could grow exponentially and take up large amounts of disk space on your host.
|
||||||
|
|
||||||
## Logging to file
|
# Logging
|
||||||
|
|
||||||
To log to file, run the PostgreSQL image, mounting a directory from your host at `/bitnami/postgresql/logs`. This will instruct the container to send logs to a `postgresql.log` file in the mounted volume.
|
The Bitnami PostgreSQL Docker image sends the container logs to the `stdout`. To view the logs:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run --name postgresql -v /path/to/postgresql/logs:/bitnami/postgresql/logs bitnami/postgresql
|
docker logs postgresql
|
||||||
```
|
```
|
||||||
|
|
||||||
or using Docker Compose:
|
or using Docker Compose:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
postgresql:
|
docker-compose logs postgresql
|
||||||
image: bitnami/postgresql
|
|
||||||
volumes:
|
|
||||||
- /path/to/postgresql/logs:/bitnami/postgresql/logs
|
|
||||||
```
|
```
|
||||||
|
|
||||||
To perform operations (e.g. logrotate) on the logs, mount the same directory in a container designed to operate on log files, such as logstash.
|
You can configure the containers [logging driver](https://docs.docker.com/engine/admin/logging/overview/) using the `--log-driver` option if you wish to consume the container logs differently. In the default configuration docker uses the `json-file` driver.
|
||||||
|
|
||||||
# Maintenance
|
# Maintenance
|
||||||
|
|
||||||
|
|
@ -436,40 +383,38 @@ docker-compose stop postgresql
|
||||||
We need to mount two volumes in a container we will use to create the backup: a directory on your host to store the backup in, and the volumes from the container we just stopped so we can access the data.
|
We need to mount two volumes in a container we will use to create the backup: a directory on your host to store the backup in, and the volumes from the container we just stopped so we can access the data.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run --rm -v /path/to/backups:/backups --volumes-from postgresql busybox \
|
docker run --rm \
|
||||||
cp -a /bitnami/postgresql /backups/latest
|
-v /path/to/postgresql-backups:/backups \
|
||||||
|
--volumes-from postgresql busybox \
|
||||||
|
cp -a /bitnami/postgresql:latest /backups/latest
|
||||||
```
|
```
|
||||||
|
|
||||||
or using Docker Compose:
|
or using Docker Compose:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run --rm -v /path/to/backups:/backups --volumes-from `docker-compose ps -q postgresql` busybox \
|
docker run --rm \
|
||||||
cp -a /bitnami/postgresql /backups/latest
|
-v /path/to/postgresql-backups:/backups \
|
||||||
|
--volumes-from `docker-compose ps -q postgresql` busybox \
|
||||||
|
cp -a /bitnami/postgresql:latest /backups/latest
|
||||||
```
|
```
|
||||||
|
|
||||||
**Note!**
|
|
||||||
If you only need to backup database data, or configuration, you can change the first argument to `cp` to `/bitnami/postgresql/data` or `/bitnami/postgresql/conf` respectively.
|
|
||||||
|
|
||||||
## Restoring a backup
|
## Restoring a backup
|
||||||
|
|
||||||
Restoring a backup is as simple as mounting the backup as volumes in the container.
|
Restoring a backup is as simple as mounting the backup as volumes in the container.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run -v /path/to/backups/latest/data:/bitnami/postgresql/data \
|
docker run \
|
||||||
-v /path/to/backups/latest/conf:/bitnami/postgresql/conf \
|
-v /path/to/postgresql-backups/latest:/bitnami/postgresql \
|
||||||
-v /path/to/backups/latest/logs:/bitnami/postgresql/logs \
|
bitnami/postgresql:latest
|
||||||
bitnami/postgresql
|
|
||||||
```
|
```
|
||||||
|
|
||||||
or using Docker Compose:
|
or using Docker Compose:
|
||||||
|
|
||||||
```
|
```
|
||||||
postgresql:
|
postgresql:
|
||||||
image: bitnami/postgresql
|
image: bitnami/postgresql:latest
|
||||||
volumes:
|
volumes:
|
||||||
- /path/to/backups/latest/data:/bitnami/postgresql/data
|
- /path/to/postgresql-backups/latest:/bitnami/postgresql
|
||||||
- /path/to/backups/latest/conf:/bitnami/postgresql/conf
|
|
||||||
- /path/to/backups/latest/logs:/bitnami/postgresql/logs
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Upgrade this image
|
## Upgrade this image
|
||||||
|
|
@ -524,6 +469,13 @@ This image is tested for expected runtime behavior, using the [BATS](https://git
|
||||||
bats test.sh
|
bats test.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Notable Changes
|
||||||
|
|
||||||
|
## 9.5.3-r0
|
||||||
|
|
||||||
|
- All volumes have been merged at `/bitnami/postgresql`. Now you only need to mount a single volume at `/bitnami/postgresql` for persistence.
|
||||||
|
- The logs are always sent to the `stdout` and are no longer collected in the volume.
|
||||||
|
|
||||||
# Contributing
|
# Contributing
|
||||||
|
|
||||||
We'd love for you to contribute to this container. You can request new features by creating an [issue](https://github.com/bitnami/bitnami-docker-postgresql/issues), or submit a [pull request](https://github.com/bitnami/bitnami-docker-postgresql/pulls) with your contribution.
|
We'd love for you to contribute to this container. You can request new features by creating an [issue](https://github.com/bitnami/bitnami-docker-postgresql/issues), or submit a [pull request](https://github.com/bitnami/bitnami-docker-postgresql/pulls) with your contribution.
|
||||||
|
|
@ -536,8 +488,7 @@ If you encountered a problem running this container, you can file an [issue](htt
|
||||||
- Docker version (`docker version`)
|
- Docker version (`docker version`)
|
||||||
- Output of `docker info`
|
- Output of `docker info`
|
||||||
- Version of this container (`echo $BITNAMI_APP_VERSION` inside the container)
|
- Version of this container (`echo $BITNAMI_APP_VERSION` inside the container)
|
||||||
- The command you used to run the container, and any relevant output you saw (masking any sensitive
|
- The command you used to run the container, and any relevant output you saw (masking any sensitive information)
|
||||||
information)
|
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
$BITNAMI_APP_NAME cheatsheet:
|
|
||||||
|
|
||||||
ENVIRONMENT VARIABLES:
|
|
||||||
POSTGRES_USER: User to be created on first boot (default: postgres).
|
|
||||||
POSTGRES_PASSWORD: Password to be set for POSTGRES_USER on first boot (default: none).
|
|
||||||
POSTGRES_DB: Database to be created on first boot, accessible by POSTGRES_USER (default: none).
|
|
||||||
POSTGRES_MODE: Replication mode. Possible values master/slave (default: master).
|
|
||||||
POSTGRES_REPLICATION_USER: Replication user. User is created on the master at first boot (default: none).
|
|
||||||
POSTGRES_REPLICATION_PASSWORD: Replication users password. Password is set for POSTGRES_REPLICATION_USER on master on the first boot (default: none).
|
|
||||||
POSTGRES_MASTER_HOST: Hostname/IP of replication master (parameter available only on slave).
|
|
||||||
POSTGRES_MASTER_PORT: Port of replication master, defaults to 5432 (parameter available only on slave).
|
|
||||||
|
|
||||||
VOLUMES:
|
|
||||||
$BITNAMI_APP_VOL_PREFIX/data: Location of $BITNAMI_APP_NAME data files.
|
|
||||||
$BITNAMI_APP_VOL_PREFIX/conf: Location of $BITNAMI_APP_NAME config files.
|
|
||||||
$BITNAMI_APP_VOL_PREFIX/logs: Location of postgresql.log.
|
|
||||||
|
|
||||||
PORTS:
|
|
||||||
5432: $BITNAMI_APP_NAME default port.
|
|
||||||
|
|
||||||
MISC:
|
|
||||||
Options: You can add extra options during the docker run using the -- prefix.
|
|
||||||
Note: POSTGRES_USER works in conjunction with POSTGRES_DB environment variable.
|
|
||||||
Tip: Back up the $BITNAMI_APP_VOL_PREFIX/data and $BITNAMI_APP_VOL_PREFIX/conf directories regularly.
|
|
||||||
|
|
||||||
COMMANDS:
|
|
||||||
print-help: Print this page.
|
|
||||||
check-updates: Check if a new version of the $BITNAMI_APP_NAME image is available.
|
|
||||||
|
|
||||||
Visit $GITHUB_PAGE for more information.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
environment_variables:
|
|
||||||
POSTGRES_USER: "User to be created on first boot (default: postgres)."
|
|
||||||
POSTGRES_PASSWORD: "Password to be set for POSTGRES_USER on first boot (default: none)."
|
|
||||||
POSTGRES_DB: "Database to be created on first boot, accessible by POSTGRES_USER (default: none)."
|
|
||||||
POSTGRES_MODE: "Replication mode. Possible values master/slave (default: master)."
|
|
||||||
POSTGRES_REPLICATION_USER: "Replication user. User is created on the master at first boot (default: none)."
|
|
||||||
POSTGRES_REPLICATION_PASSWORD: "Replication users password. Password is set for POSTGRES_REPLICATION_USER on master on the first boot (default: none)."
|
|
||||||
POSTGRES_MASTER_HOST: "Hostname/IP of replication master (parameter available only on slave)."
|
|
||||||
POSTGRES_MASTER_PORT: "Port of replication master, defaults to 5432 (parameter available only on slave)."
|
|
||||||
volumes:
|
|
||||||
$BITNAMI_APP_VOL_PREFIX/data: "Location of $BITNAMI_APP_NAME data files."
|
|
||||||
$BITNAMI_APP_VOL_PREFIX/conf: "Location of $BITNAMI_APP_NAME config files."
|
|
||||||
$BITNAMI_APP_VOL_PREFIX/logs: "Location of postgresql.log."
|
|
||||||
ports:
|
|
||||||
5432: "$BITNAMI_APP_NAME default port."
|
|
||||||
misc:
|
|
||||||
Options: "You can add extra options during the docker run using the -- prefix."
|
|
||||||
Note: "The user and database creation happens only the first time you run the container."
|
|
||||||
Note: "POSTGRES_USER works in conjunction with POSTGRES_DB environment variable."
|
|
||||||
Tip: "Back up the $BITNAMI_APP_VOL_PREFIX/data and $BITNAMI_APP_VOL_PREFIX/conf directories regularly."
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
7cd347b3141f8637758372bca56a7cd17876f59b7420b2c85ff7fd6ad25d1d39 /tmp/installer.run
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
cd $BITNAMI_APP_DIR
|
|
||||||
|
|
||||||
set_pg_param() {
|
|
||||||
local key=${1}
|
|
||||||
local value=${2}
|
|
||||||
|
|
||||||
if [[ -n ${value} ]]; then
|
|
||||||
local current=$(sed -n -e "s/^\(${key} = '\)\([^ ']*\)\(.*\)$/\2/p" $BITNAMI_APP_DIR/conf.defaults/postgresql.conf)
|
|
||||||
if [[ "${current}" != "${value}" ]]; then
|
|
||||||
value="$(echo "${value}" | sed 's|[&]|\\&|g')"
|
|
||||||
sed -i "s|^[#]*[ ]*${key} = .*|${key} = '${value}'|" $BITNAMI_APP_DIR/conf.defaults/postgresql.conf
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
set_hba_param() {
|
|
||||||
local value=${1}
|
|
||||||
if ! grep -q "$(sed "s| | \\\+|g" <<< ${value})" $BITNAMI_APP_DIR/conf.defaults/pg_hba.conf; then
|
|
||||||
echo "${value}" >> $BITNAMI_APP_DIR/conf.defaults/pg_hba.conf
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# set up default configs
|
|
||||||
mkdir conf.defaults
|
|
||||||
s6-setuidgid $BITNAMI_APP_USER $BITNAMI_APP_DIR/bin/initdb -D $BITNAMI_APP_DIR/data \
|
|
||||||
-U $BITNAMI_APP_USER -E unicode -A trust >/dev/null
|
|
||||||
mv $BITNAMI_APP_DIR/data/postgresql.conf conf.defaults/
|
|
||||||
mv $BITNAMI_APP_DIR/data/pg_hba.conf conf.defaults/
|
|
||||||
mv $BITNAMI_APP_DIR/data/pg_ident.conf conf.defaults/
|
|
||||||
rm -rf $BITNAMI_APP_DIR/data
|
|
||||||
|
|
||||||
# default
|
|
||||||
set_pg_param "listen_addresses" "*"
|
|
||||||
set_pg_param "logging_collector" "on"
|
|
||||||
set_pg_param "log_directory" "$BITNAMI_APP_DIR/logs"
|
|
||||||
set_pg_param "log_filename" "postgresql.log"
|
|
||||||
|
|
||||||
# hot standby
|
|
||||||
set_pg_param "wal_level" "hot_standby"
|
|
||||||
set_pg_param "max_wal_senders" "16"
|
|
||||||
set_pg_param "checkpoint_segments" "8"
|
|
||||||
set_pg_param "wal_keep_segments" "32"
|
|
||||||
set_pg_param "hot_standby" "on"
|
|
||||||
|
|
||||||
set_hba_param "host all all 0.0.0.0/0 md5"
|
|
||||||
set_hba_param "host replication all 0.0.0.0/0 md5"
|
|
||||||
|
|
||||||
# symlink mount points at root to install dir
|
|
||||||
ln -s $BITNAMI_APP_DIR/data $BITNAMI_APP_VOL_PREFIX/data
|
|
||||||
ln -s $BITNAMI_APP_DIR/logs $BITNAMI_APP_VOL_PREFIX/logs
|
|
||||||
ln -s $BITNAMI_APP_DIR/conf $BITNAMI_APP_VOL_PREFIX/conf
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [[ "$1" == "harpoon" && "$2" == "start" ]]; then
|
||||||
|
status=`harpoon inspect $BITNAMI_APP_NAME`
|
||||||
|
if [[ "$status" == *'"lifecycle": "unpacked"'* ]]; then
|
||||||
|
harpoon initialize $BITNAMI_APP_NAME \
|
||||||
|
${POSTGRES_USER:+--username $POSTGRES_USER} \
|
||||||
|
${POSTGRES_PASSWORD:+--password $POSTGRES_PASSWORD} \
|
||||||
|
${POSTGRES_DB:+--database $POSTGRES_DB} \
|
||||||
|
${POSTGRES_MODE:+--replicationMode $POSTGRES_MODE} \
|
||||||
|
${POSTGRES_REPLICATION_USER:+--replicationUser $POSTGRES_REPLICATION_USER} \
|
||||||
|
${POSTGRES_REPLICATION_PASSWORD:+--replicationPassword $POSTGRES_REPLICATION_PASSWORD} \
|
||||||
|
${POSTGRES_MASTER_HOST:+--masterHost $POSTGRES_MASTER_HOST} \
|
||||||
|
${POSTGRES_MASTER_PORT:+--masterPort $POSTGRES_MASTER_PORT} \
|
||||||
|
${POSTGRES_MASTER_USER:+--masterUser $POSTGRES_MASTER_USER} \
|
||||||
|
${POSTGRES_MASTER_PASSWORD:+--masterPassword $POSTGRES_MASTER_PASSWORD}
|
||||||
|
fi
|
||||||
|
chown $BITNAMI_APP_USER: /bitnami/$BITNAMI_APP_NAME || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec /entrypoint.sh "$@"
|
||||||
|
|
@ -1,197 +0,0 @@
|
||||||
# PostgreSQL Utility functions
|
|
||||||
PROGRAM_OPTIONS="-D $BITNAMI_APP_DIR/data --config_file=$BITNAMI_APP_DIR/conf/postgresql.conf --hba_file=$BITNAMI_APP_DIR/conf/pg_hba.conf --ident_file=$BITNAMI_APP_DIR/conf/pg_ident.conf"
|
|
||||||
|
|
||||||
POSTGRES_MODE=${POSTGRES_MODE:-master}
|
|
||||||
case $POSTGRES_MODE in
|
|
||||||
master|slave) ;;
|
|
||||||
*)
|
|
||||||
echo "Replication mode \"$POSTGRES_MODE\" not supported!"
|
|
||||||
echo ""
|
|
||||||
exit -1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
set_recovery_param() {
|
|
||||||
local key=${1}
|
|
||||||
local value=${2}
|
|
||||||
|
|
||||||
if [[ -n ${value} ]]; then
|
|
||||||
local current=$(sed -n -e "s/^\(${key} = '\)\([^ ']*\)\(.*\)$/\2/p" $BITNAMI_APP_DIR/data/recovery.conf)
|
|
||||||
if [[ "${current}" != "${value}" ]]; then
|
|
||||||
value="$(echo "${value}" | sed 's|[&]|\\&|g')"
|
|
||||||
s6-setuidgid $BITNAMI_APP_USER sed -i "s|^[#]*[ ]*${key} = .*|${key} = '${value}'|" $BITNAMI_APP_DIR/data/recovery.conf
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
discover_replication_parameters() {
|
|
||||||
if [ "$POSTGRES_MODE" == "slave" ]; then
|
|
||||||
echo "==> Trying to fetch replication parameters exposed by docker links..."
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
POSTGRES_MASTER_HOST=${POSTGRES_MASTER_HOST:-$MASTER_PORT_5432_TCP_ADDR}
|
|
||||||
POSTGRES_MASTER_PORT=${POSTGRES_MASTER_PORT:-$MASTER_PORT_5432_TCP_PORT}
|
|
||||||
POSTGRES_REPLICATION_USER=${POSTGRES_REPLICATION_USER:-$MASTER_ENV_POSTGRES_REPLICATION_USER}
|
|
||||||
POSTGRES_REPLICATION_PASSWORD=${POSTGRES_REPLICATION_PASSWORD:-$MASTER_ENV_POSTGRES_REPLICATION_PASSWORD}
|
|
||||||
|
|
||||||
if [ ! $POSTGRES_MASTER_HOST ]; then
|
|
||||||
echo "In order to setup a replication slave you need to provide the POSTGRES_MASTER_HOST as well"
|
|
||||||
echo ""
|
|
||||||
exit -1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! $POSTGRES_MASTER_PORT ]; then
|
|
||||||
echo "POSTGRES_MASTER_PORT not specified. Defaulting to 5432"
|
|
||||||
echo ""
|
|
||||||
POSTGRES_MASTER_PORT=${POSTGRES_MASTER_PORT:-5432}
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! $POSTGRES_REPLICATION_USER ]; then
|
|
||||||
echo "In order to setup a replication slave you need to provide the POSTGRES_REPLICATION_USER as well"
|
|
||||||
echo ""
|
|
||||||
exit -1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! $POSTGRES_REPLICATION_PASSWORD ]; then
|
|
||||||
echo "In order to setup a replication slave you need to provide the POSTGRES_REPLICATION_PASSWORD as well"
|
|
||||||
echo ""
|
|
||||||
exit -1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
initialize_database() {
|
|
||||||
case "$POSTGRES_MODE" in
|
|
||||||
master)
|
|
||||||
echo "==> Initializing database..."
|
|
||||||
echo ""
|
|
||||||
s6-setuidgid $BITNAMI_APP_USER $BITNAMI_APP_DIR/bin/initdb -D $BITNAMI_APP_DIR/data \
|
|
||||||
-U $BITNAMI_APP_USER -E unicode -A trust >/dev/null
|
|
||||||
;;
|
|
||||||
slave)
|
|
||||||
echo "==> Waiting for replication master to accept connections (60s timeout)..."
|
|
||||||
echo ""
|
|
||||||
timeout=60
|
|
||||||
while ! $BITNAMI_APP_DIR/bin/pg_isready -h $POSTGRES_MASTER_HOST -p $POSTGRES_MASTER_PORT -t 1 >/dev/null 2>&1
|
|
||||||
do
|
|
||||||
timeout=$(expr $timeout - 1)
|
|
||||||
if [[ $timeout -eq 0 ]]; then
|
|
||||||
echo "Could not connect to replication master"
|
|
||||||
echo ""
|
|
||||||
exit -1
|
|
||||||
fi
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "==> Replicating the initial database..."
|
|
||||||
echo ""
|
|
||||||
sudo -Hu $BITNAMI_APP_USER \
|
|
||||||
PGPASSWORD=$POSTGRES_REPLICATION_PASSWORD $BITNAMI_APP_DIR/bin/pg_basebackup -D $BITNAMI_APP_DIR/data \
|
|
||||||
-h ${POSTGRES_MASTER_HOST} -p ${POSTGRES_MASTER_PORT} -U ${POSTGRES_REPLICATION_USER} -X stream -w -v -P >/dev/null 2>&1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
rm -rf $BITNAMI_APP_DIR/data/{pg_hba.conf,pg_ident.conf,postgresql.conf}
|
|
||||||
}
|
|
||||||
|
|
||||||
create_custom_database() {
|
|
||||||
if [ "$POSTGRES_MODE" == "master" ]; then
|
|
||||||
if [ "$POSTGRES_DB" ]; then
|
|
||||||
echo "==> Creating database $POSTGRES_DB..."
|
|
||||||
echo ""
|
|
||||||
echo "CREATE DATABASE \"$POSTGRES_DB\";" | \
|
|
||||||
s6-setuidgid $BITNAMI_APP_USER $BITNAMI_APP_DIR/bin/postgres --single $PROGRAM_OPTIONS >/dev/null
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
create_postgresql_user() {
|
|
||||||
if [ "$POSTGRES_MODE" == "master" ]; then
|
|
||||||
POSTGRES_USER=${POSTGRES_USER:-$BITNAMI_APP_USER}
|
|
||||||
if [ "$POSTGRES_USER" != "$BITNAMI_APP_USER" ]; then
|
|
||||||
if [ ! $POSTGRES_PASSWORD ]; then
|
|
||||||
echo "In order to use a custom POSTGRES_USER you need to provide the POSTGRES_PASSWORD as well"
|
|
||||||
echo ""
|
|
||||||
exit -1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! $POSTGRES_DB ]; then
|
|
||||||
echo "In order to use a custom POSTGRES_USER you need to provide the POSTGRES_DB as well"
|
|
||||||
echo ""
|
|
||||||
exit -1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$POSTGRES_USER" = $BITNAMI_APP_USER ]; then
|
|
||||||
echo "==> Creating $BITNAMI_APP_USER user with unrestricted access..."
|
|
||||||
echo "ALTER ROLE $POSTGRES_USER WITH PASSWORD '$POSTGRES_PASSWORD';" | \
|
|
||||||
s6-setuidgid $BITNAMI_APP_USER $BITNAMI_APP_DIR/bin/postgres --single $PROGRAM_OPTIONS >/dev/null
|
|
||||||
else
|
|
||||||
echo "==> Creating user $POSTGRES_USER..."
|
|
||||||
echo ""
|
|
||||||
echo "CREATE ROLE \"$POSTGRES_USER\" WITH LOGIN CREATEDB PASSWORD '$POSTGRES_PASSWORD';" | \
|
|
||||||
s6-setuidgid $BITNAMI_APP_USER $BITNAMI_APP_DIR/bin/postgres --single $PROGRAM_OPTIONS >/dev/null
|
|
||||||
|
|
||||||
echo "==> Granting access to $POSTGRES_USER to the database $POSTGRES_DB..."
|
|
||||||
echo ""
|
|
||||||
echo "GRANT ALL PRIVILEGES ON DATABASE \"$POSTGRES_DB\" to \"$POSTGRES_USER\";" | \
|
|
||||||
s6-setuidgid $BITNAMI_APP_USER $BITNAMI_APP_DIR/bin/postgres --single $PROGRAM_OPTIONS >/dev/null
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
create_replication_user() {
|
|
||||||
if [ "$POSTGRES_MODE" == "master" ]; then
|
|
||||||
if [ "$POSTGRES_REPLICATION_USER" ]; then
|
|
||||||
if [ ! $POSTGRES_REPLICATION_PASSWORD ]; then
|
|
||||||
echo "In order to create a replication user you need to provide the POSTGRES_REPLICATION_PASSWORD as well"
|
|
||||||
echo ""
|
|
||||||
exit -1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "==> Creating replication user $POSTGRES_REPLICATION_USER..."
|
|
||||||
echo ""
|
|
||||||
echo "CREATE ROLE \"$POSTGRES_REPLICATION_USER\" REPLICATION LOGIN ENCRYPTED PASSWORD '$POSTGRES_REPLICATION_PASSWORD';" | \
|
|
||||||
s6-setuidgid $BITNAMI_APP_USER $BITNAMI_APP_DIR/bin/postgres --single $PROGRAM_OPTIONS >/dev/null
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
configure_recovery() {
|
|
||||||
if [ "$POSTGRES_MODE" == "slave" ]; then
|
|
||||||
echo "==> Setting up streaming replication slave..."
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
s6-setuidgid $BITNAMI_APP_USER cp -a $BITNAMI_APP_DIR/share/recovery.conf.sample $BITNAMI_APP_DIR/data/recovery.conf
|
|
||||||
set_recovery_param "standby_mode" "on"
|
|
||||||
set_recovery_param "primary_conninfo" "host=${POSTGRES_MASTER_HOST} port=${POSTGRES_MASTER_PORT} user=${POSTGRES_REPLICATION_USER} password=${POSTGRES_REPLICATION_PASSWORD}"
|
|
||||||
set_recovery_param "trigger_file" "/tmp/postgresql.trigger.5432"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
print_postgresql_password() {
|
|
||||||
case "$POSTGRES_MODE" in
|
|
||||||
master)
|
|
||||||
if [ -z $POSTGRES_PASSWORD ]; then
|
|
||||||
echo "**none**"
|
|
||||||
else
|
|
||||||
echo $POSTGRES_PASSWORD
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
slave)
|
|
||||||
echo "**replication**"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
print_postgresql_database() {
|
|
||||||
case "$POSTGRES_MODE" in
|
|
||||||
master)
|
|
||||||
if [ $POSTGRES_DB ]; then
|
|
||||||
echo "Database: $POSTGRES_DB"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
slave)
|
|
||||||
echo "**replication**"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
#!/usr/bin/with-contenv bash
|
|
||||||
set -e
|
|
||||||
source $BITNAMI_PREFIX/bitnami-utils.sh
|
|
||||||
|
|
||||||
export LD_LIBRARY_PATH=$BITNAMI_PREFIX/common/lib:/opt/bitnami/postgresql/lib
|
|
||||||
|
|
||||||
chmod 0700 $BITNAMI_APP_DIR/data
|
|
||||||
chown $BITNAMI_APP_USER:$BITNAMI_APP_USER \
|
|
||||||
$BITNAMI_APP_DIR/conf/ \
|
|
||||||
$BITNAMI_APP_DIR/data/ \
|
|
||||||
$BITNAMI_APP_DIR/logs/ || true
|
|
||||||
|
|
||||||
if [ ! "$(ls -A $BITNAMI_APP_VOL_PREFIX/conf)" ]; then
|
|
||||||
generate_conf_files
|
|
||||||
fi
|
|
||||||
|
|
||||||
discover_replication_parameters
|
|
||||||
|
|
||||||
if [ ! -f $BITNAMI_APP_VOL_PREFIX/data/PG_VERSION ]; then
|
|
||||||
initialize_database
|
|
||||||
|
|
||||||
create_custom_database
|
|
||||||
|
|
||||||
create_postgresql_user
|
|
||||||
|
|
||||||
create_replication_user
|
|
||||||
|
|
||||||
print_app_credentials $BITNAMI_APP_NAME $POSTGRES_USER `print_postgresql_password` `print_postgresql_database`
|
|
||||||
else
|
|
||||||
print_container_already_initialized $BITNAMI_APP_NAME
|
|
||||||
fi
|
|
||||||
|
|
||||||
configure_recovery
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
/bin/true
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
#!/usr/bin/with-contenv bash
|
|
||||||
set -e
|
|
||||||
source $BITNAMI_PREFIX/bitnami-utils.sh
|
|
||||||
|
|
||||||
exec s6-setuidgid $BITNAMI_APP_USER tail -f -n 1000 $BITNAMI_APP_VOL_PREFIX/logs/*.log 2>/dev/null
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
#!/usr/bin/with-contenv bash
|
|
||||||
|
|
||||||
failcount=0
|
|
||||||
if [ -f $BITNAMI_APP_DIR/tmp/failcount ]; then
|
|
||||||
failcount=$(cat $BITNAMI_APP_DIR/tmp/failcount)
|
|
||||||
fi
|
|
||||||
|
|
||||||
start=$(cat $BITNAMI_APP_DIR/tmp/start)
|
|
||||||
stop=`date '+%d%H%M%S'`
|
|
||||||
interval=`expr $stop - $start`
|
|
||||||
if test $interval -lt 30 ; then
|
|
||||||
failcount=`expr $failcount + 1`
|
|
||||||
else
|
|
||||||
failcount=0
|
|
||||||
fi
|
|
||||||
echo -n $failcount > $BITNAMI_APP_DIR/tmp/failcount
|
|
||||||
|
|
||||||
# bring down container on frequent failures. something is definitely wrong
|
|
||||||
if test $failcount -ge 3 ; then
|
|
||||||
s6-svscanctl -t /var/run/s6/services
|
|
||||||
fi
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
#!/usr/bin/with-contenv bash
|
|
||||||
set -e
|
|
||||||
source $BITNAMI_PREFIX/bitnami-utils.sh
|
|
||||||
export LD_LIBRARY_PATH=$BITNAMI_PREFIX/common/lib:/opt/bitnami/postgresql/lib
|
|
||||||
|
|
||||||
mkdir -p $BITNAMI_APP_DIR/tmp
|
|
||||||
date '+%d%H%M%S' > $BITNAMI_APP_DIR/tmp/start
|
|
||||||
exec s6-setuidgid $BITNAMI_APP_USER $BITNAMI_APP_DAEMON $PROGRAM_OPTIONS ${EXTRA_OPTIONS:+"$EXTRA_OPTIONS"}
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
#!/usr/bin/env bats
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
POSTGRES_DB=test_database
|
POSTGRES_DB=test_database
|
||||||
POSTGRES_ROOT_USER=postgres
|
|
||||||
POSTGRES_USER=test_user
|
POSTGRES_USER=test_user
|
||||||
POSTGRES_PASSWORD=test_password
|
POSTGRES_PASSWORD=test_password
|
||||||
POSTGRES_REPLICATION_USER=repl_user
|
POSTGRES_REPLICATION_USER=repl_user
|
||||||
|
|
@ -9,7 +8,9 @@ POSTGRES_REPLICATION_PASSWORD=repl_password
|
||||||
|
|
||||||
# source the helper script
|
# source the helper script
|
||||||
APP_NAME=postgresql
|
APP_NAME=postgresql
|
||||||
SLEEP_TIME=15
|
VOL_PREFIX=/bitnami/$APP_NAME
|
||||||
|
VOLUMES=$VOL_PREFIX
|
||||||
|
SLEEP_TIME=30
|
||||||
container_link_and_run_command_DOCKER_ARGS="-e PGPASSWORD=$POSTGRES_PASSWORD"
|
container_link_and_run_command_DOCKER_ARGS="-e PGPASSWORD=$POSTGRES_PASSWORD"
|
||||||
load tests/docker_helper
|
load tests/docker_helper
|
||||||
|
|
||||||
|
|
@ -22,8 +23,8 @@ psql_client() {
|
||||||
|
|
||||||
# Cleans up all running/stopped containers and host mounted volumes
|
# Cleans up all running/stopped containers and host mounted volumes
|
||||||
cleanup_environment() {
|
cleanup_environment() {
|
||||||
container_remove_full slave0
|
|
||||||
container_remove_full default
|
container_remove_full default
|
||||||
|
container_remove_full slave0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Teardown called at the end of each test
|
# Teardown called at the end of each test
|
||||||
|
|
@ -35,103 +36,99 @@ teardown() {
|
||||||
cleanup_environment
|
cleanup_environment
|
||||||
|
|
||||||
@test "Port 5432 exposed and accepting external connections" {
|
@test "Port 5432 exposed and accepting external connections" {
|
||||||
container_create default -d \
|
container_create default -d
|
||||||
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD
|
|
||||||
|
|
||||||
# check if postgresql server is accepting connections
|
|
||||||
run container_link_and_run_command default pg_isready -h $APP_NAME -p 5432 -t 5
|
run container_link_and_run_command default pg_isready -h $APP_NAME -p 5432 -t 5
|
||||||
[[ "$output" =~ "accepting connections" ]]
|
[[ "$output" =~ "accepting connections" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "User postgres created with password" {
|
@test "Can create postgres user without password" {
|
||||||
container_create default -d \
|
container_create default -d \
|
||||||
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD
|
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD
|
||||||
|
|
||||||
# auth as POSTGRES_ROOT_USER user and list all databases
|
run container_exec default psql -U postgres -Axc "\l"
|
||||||
run psql_client default -U $POSTGRES_ROOT_USER -Axc "\l"
|
|
||||||
[[ "$output" =~ "Name|postgres" ]]
|
[[ "$output" =~ "Name|postgres" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "User postgres is superuser" {
|
@test "Can't login remotely as postgres user without a password" {
|
||||||
|
container_create default -d
|
||||||
|
|
||||||
|
run psql_client default -U postgres -w -Axc "\l"
|
||||||
|
[[ "$output" =~ "password authentication failed" ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "Can create postgres user with custom password" {
|
||||||
container_create default -d \
|
container_create default -d \
|
||||||
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD
|
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD
|
||||||
|
|
||||||
# check if POSTGRES_ROOT_USER user is a superuser
|
run psql_client default -U postgres -Axc "\l"
|
||||||
run psql_client default -U $POSTGRES_ROOT_USER -Axc "SHOW is_superuser;"
|
[[ "$output" =~ "Name|postgres" ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "Default postgres user is superuser" {
|
||||||
|
container_create default -d \
|
||||||
|
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD
|
||||||
|
|
||||||
|
run psql_client default -U postgres -Axc "SHOW is_superuser;"
|
||||||
[[ $output =~ "is_superuser|on" ]]
|
[[ $output =~ "is_superuser|on" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Custom database created" {
|
@test "Can create custom database" {
|
||||||
container_create default -d \
|
container_create default -d \
|
||||||
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
|
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
|
||||||
-e POSTGRES_DB=$POSTGRES_DB
|
-e POSTGRES_DB=$POSTGRES_DB
|
||||||
|
|
||||||
# auth as POSTGRES_ROOT_USER user and list all databases
|
run psql_client default -U postgres -Axc "\l"
|
||||||
run psql_client default -U $POSTGRES_ROOT_USER -Axc "\l"
|
|
||||||
[[ "$output" =~ "Name|$POSTGRES_DB" ]]
|
[[ "$output" =~ "Name|$POSTGRES_DB" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Can't create a custom user without a password" {
|
@test "Can't create custom user without password" {
|
||||||
# create container without specifying POSTGRES_PASSWORD
|
|
||||||
run container_create default \
|
run container_create default \
|
||||||
-e POSTGRES_USER=$POSTGRES_USER
|
-e POSTGRES_USER=$POSTGRES_USER
|
||||||
[[ "$output" =~ "you need to provide the POSTGRES_PASSWORD" ]]
|
[[ "$output" =~ "provide the --password property as well" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Can't create a custom user without database" {
|
@test "Can't create custom user without database" {
|
||||||
# create container without specifying POSTGRES_DB
|
|
||||||
run container_create default \
|
run container_create default \
|
||||||
-e POSTGRES_USER=$POSTGRES_USER \
|
-e POSTGRES_USER=$POSTGRES_USER \
|
||||||
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD
|
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD
|
||||||
[[ "$output" =~ "you need to provide the POSTGRES_DB" ]]
|
[[ "$output" =~ "provide the --database property as well" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Create custom user and database with password" {
|
@test "Can create custom user with password and database" {
|
||||||
container_create default -d \
|
container_create default -d \
|
||||||
-e POSTGRES_USER=$POSTGRES_USER \
|
-e POSTGRES_USER=$POSTGRES_USER \
|
||||||
-e POSTGRES_DB=$POSTGRES_DB \
|
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
|
||||||
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD
|
-e POSTGRES_DB=$POSTGRES_DB
|
||||||
|
|
||||||
# auth as POSTGRES_ROOT_USER user and list all databases, should fail
|
|
||||||
run psql_client default -U $POSTGRES_ROOT_USER -Axc "\l"
|
|
||||||
[[ "$output" =~ "authentication failed for user" ]]
|
|
||||||
|
|
||||||
# auth as POSTGRES_USER and list all databases
|
|
||||||
run psql_client default -U $POSTGRES_USER $POSTGRES_DB -Axc "\l"
|
run psql_client default -U $POSTGRES_USER $POSTGRES_DB -Axc "\l"
|
||||||
[[ "$output" =~ "Name|$POSTGRES_DB" ]]
|
[[ "$output" =~ "Name|$POSTGRES_DB" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Can't create a replication user without a password" {
|
@test "Custom user is not superuser" {
|
||||||
# create replication user without specifying POSTGRES_REPLICATION_PASSWORD
|
|
||||||
run container_create default \
|
|
||||||
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER
|
|
||||||
[[ "$output" =~ "you need to provide the POSTGRES_REPLICATION_PASSWORD" ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Create replication user with password" {
|
|
||||||
container_create default -d \
|
|
||||||
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
|
|
||||||
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
|
||||||
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD
|
|
||||||
|
|
||||||
run psql_client default -U $POSTGRES_ROOT_USER -Axc "SELECT usename FROM pg_catalog.pg_user WHERE usename = '$POSTGRES_REPLICATION_USER' AND userepl = 'true';"
|
|
||||||
[[ "$output" =~ "usename|$POSTGRES_REPLICATION_USER" ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "User and password settings are preserved after restart" {
|
|
||||||
container_create default -d \
|
container_create default -d \
|
||||||
-e POSTGRES_USER=$POSTGRES_USER \
|
-e POSTGRES_USER=$POSTGRES_USER \
|
||||||
-e POSTGRES_DB=$POSTGRES_DB \
|
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
|
||||||
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD
|
-e POSTGRES_DB=$POSTGRES_DB
|
||||||
|
|
||||||
|
run psql_client default -U $POSTGRES_USER $POSTGRES_DB -Axc "SHOW is_superuser;"
|
||||||
|
[[ "$output" =~ "is_superuser|off" ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "Can't create replication user without password" {
|
||||||
|
run container_create default \
|
||||||
|
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER
|
||||||
|
[[ "$output" =~ "provide the --replicationPassword property as well" ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "Data is preserved on container restart" {
|
||||||
|
container_create default -d \
|
||||||
|
-e POSTGRES_USER=$POSTGRES_USER \
|
||||||
|
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
|
||||||
|
-e POSTGRES_DB=$POSTGRES_DB
|
||||||
|
|
||||||
# restart container
|
|
||||||
container_restart default
|
container_restart default
|
||||||
|
|
||||||
# get container logs
|
|
||||||
run container_logs default
|
|
||||||
[[ "$output" =~ "The credentials were set on first boot." ]]
|
|
||||||
|
|
||||||
# auth as POSTGRES_USER and list all databases
|
|
||||||
run psql_client default -U $POSTGRES_USER $POSTGRES_DB -Axc "\l"
|
run psql_client default -U $POSTGRES_USER $POSTGRES_DB -Axc "\l"
|
||||||
[[ "$output" =~ "Name|$POSTGRES_DB" ]]
|
[[ "$output" =~ "Name|$POSTGRES_DB" ]]
|
||||||
}
|
}
|
||||||
|
|
@ -139,231 +136,142 @@ cleanup_environment
|
||||||
@test "All the volumes exposed" {
|
@test "All the volumes exposed" {
|
||||||
container_create default -d
|
container_create default -d
|
||||||
|
|
||||||
# get container introspection details and check if volumes are exposed
|
|
||||||
run container_inspect default --format {{.Mounts}}
|
run container_inspect default --format {{.Mounts}}
|
||||||
[[ "$output" =~ "$VOL_PREFIX/data" ]]
|
[[ "$output" =~ "$VOL_PREFIX" ]]
|
||||||
[[ "$output" =~ "$VOL_PREFIX/conf" ]]
|
|
||||||
[[ "$output" =~ "$VOL_PREFIX/logs" ]]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Data gets generated in conf, data and logs if bind mounted in the host" {
|
@test "Data gets generated in volume if bind mounted in the host" {
|
||||||
container_create_with_host_volumes default -d \
|
container_create_with_host_volumes default -d
|
||||||
-e POSTGRES_USER=$POSTGRES_USER \
|
|
||||||
-e POSTGRES_DB=$POSTGRES_DB \
|
|
||||||
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD
|
|
||||||
|
|
||||||
# files expected in conf volume (subset)
|
|
||||||
run container_exec default ls -la $VOL_PREFIX/conf/
|
|
||||||
[[ "$output" =~ "postgresql.conf" ]]
|
|
||||||
[[ "$output" =~ "pg_hba.conf" ]]
|
|
||||||
|
|
||||||
# files expected in data volume (subset)
|
|
||||||
run container_exec default ls -la $VOL_PREFIX/data/
|
run container_exec default ls -la $VOL_PREFIX/data/
|
||||||
[[ "$output" =~ "PG_VERSION" ]]
|
[[ "$output" =~ "PG_VERSION" ]]
|
||||||
[[ "$output" =~ "base" ]]
|
[[ "$output" =~ "base" ]]
|
||||||
|
|
||||||
# files expected in logs volume
|
run container_exec default ls -la $VOL_PREFIX/conf/
|
||||||
run container_exec default ls -la $VOL_PREFIX/logs/
|
[[ "$output" =~ "postgresql.conf" ]]
|
||||||
[[ "$output" =~ "postgresql.log" ]]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "If host mounted, password and settings are preserved after deletion" {
|
@test "If host mounted, password and settings are preserved after deletion" {
|
||||||
container_create_with_host_volumes default -d \
|
container_create_with_host_volumes default -d \
|
||||||
-e POSTGRES_USER=$POSTGRES_USER \
|
-e POSTGRES_USER=$POSTGRES_USER \
|
||||||
-e POSTGRES_DB=$POSTGRES_DB \
|
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
|
||||||
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD
|
-e POSTGRES_DB=$POSTGRES_DB
|
||||||
|
|
||||||
# stop and remove container
|
|
||||||
container_remove default
|
container_remove default
|
||||||
|
|
||||||
# recreate container without specifying any env parameters
|
|
||||||
container_create_with_host_volumes default -d
|
container_create_with_host_volumes default -d
|
||||||
|
|
||||||
# auth as POSTGRES_USER and list all databases
|
|
||||||
run psql_client default -U $POSTGRES_USER $POSTGRES_DB -Axc "\l"
|
run psql_client default -U $POSTGRES_USER $POSTGRES_DB -Axc "\l"
|
||||||
[[ "$output" =~ "Name|$POSTGRES_DB" ]]
|
[[ "$output" =~ "Name|$POSTGRES_DB" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Configuration changes are preserved after deletion" {
|
@test "Can't setup replication slave without specifying the master host" {
|
||||||
container_create_with_host_volumes default -d
|
|
||||||
|
|
||||||
# modify postgresql.conf
|
|
||||||
container_exec default sed -i 's|^[#]*[ ]*log_connections[ ]*=.*|log_connections=on|' $VOL_PREFIX/conf/postgresql.conf
|
|
||||||
container_exec default sed -i 's|^[#]*[ ]*log_disconnections[ ]*=.*|log_disconnections=on|' $VOL_PREFIX/conf/postgresql.conf
|
|
||||||
|
|
||||||
# stop and remove container
|
|
||||||
container_remove default
|
|
||||||
|
|
||||||
# relaunch container with host volumes
|
|
||||||
container_create_with_host_volumes default -d
|
|
||||||
|
|
||||||
run container_exec default cat $VOL_PREFIX/conf/postgresql.conf
|
|
||||||
[[ "$output" =~ "log_connections=on" ]]
|
|
||||||
[[ "$output" =~ "log_disconnections=on" ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Can't setup replication slave without master host" {
|
|
||||||
# create replication slave without specifying POSTGRES_MASTER_HOST
|
|
||||||
run container_create slave0 \
|
run container_create slave0 \
|
||||||
-e POSTGRES_MODE=slave
|
-e POSTGRES_MODE=slave
|
||||||
[[ "$output" =~ "you need to provide the POSTGRES_MASTER_HOST" ]]
|
[[ "$output" =~ "provide the --masterHost property as well" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Can't setup replication slave without replication user" {
|
@test "Can't setup replication slave without replication user" {
|
||||||
# create replication slave without specifying POSTGRES_REPLICATION_USER
|
|
||||||
run container_create slave0 \
|
run container_create slave0 \
|
||||||
-e POSTGRES_MODE=slave \
|
-e POSTGRES_MODE=slave \
|
||||||
-e POSTGRES_MASTER_HOST=master
|
-e POSTGRES_MASTER_HOST=master
|
||||||
[[ "$output" =~ "you need to provide the POSTGRES_REPLICATION_USER" ]]
|
[[ "$output" =~ "provide the --replicationUser property as well" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Can't setup replication slave without replication password" {
|
@test "Can't setup replication slave without password for replication user" {
|
||||||
# create replication slave without specifying POSTGRES_REPLICATION_PASSWORD
|
|
||||||
run container_create slave0 \
|
run container_create slave0 \
|
||||||
-e POSTGRES_MODE=slave \
|
-e POSTGRES_MODE=slave \
|
||||||
-e POSTGRES_MASTER_HOST=master \
|
-e POSTGRES_MASTER_HOST=master \
|
||||||
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER
|
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER
|
||||||
[[ "$output" =~ "you need to provide the POSTGRES_REPLICATION_PASSWORD" ]]
|
[[ "$output" =~ "provide the --replicationPassword property as well" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Master database is replicated on slave" {
|
@test "Can setup master/slave replication with minimal configuration" {
|
||||||
container_create default -d \
|
container_create default -d \
|
||||||
-e POSTGRES_USER=$POSTGRES_USER \
|
|
||||||
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
|
|
||||||
-e POSTGRES_DB=$POSTGRES_DB \
|
|
||||||
-e POSTGRES_MODE=master \
|
-e POSTGRES_MODE=master \
|
||||||
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
||||||
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD
|
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD \
|
||||||
|
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
|
||||||
|
-e POSTGRES_DB=$POSTGRES_DB
|
||||||
|
|
||||||
container_create slave0 -d \
|
container_create slave0 -d \
|
||||||
$(container_link default $CONTAINER_NAME) \
|
$(container_link default $CONTAINER_NAME) \
|
||||||
-e POSTGRES_MASTER_HOST=$CONTAINER_NAME \
|
|
||||||
-e POSTGRES_MASTER_PORT=5432 \
|
|
||||||
-e POSTGRES_MODE=slave \
|
-e POSTGRES_MODE=slave \
|
||||||
|
-e POSTGRES_MASTER_HOST=$CONTAINER_NAME \
|
||||||
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
||||||
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD
|
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD
|
||||||
|
|
||||||
# create users table on master and insert a record
|
psql_client default -U postgres $POSTGRES_DB -c \
|
||||||
psql_client default -U $POSTGRES_USER $POSTGRES_DB -c \
|
|
||||||
"CREATE TABLE users (id serial, name varchar(40) NOT NULL); \
|
"CREATE TABLE users (id serial, name varchar(40) NOT NULL); \
|
||||||
INSERT INTO users(name) VALUES ('Marko');"
|
INSERT INTO users(name) VALUES ('Marko');"
|
||||||
|
|
||||||
# verify that record is replicated on slave0
|
run psql_client slave0 -U postgres $POSTGRES_DB -Axc "SELECT * FROM users;"
|
||||||
run psql_client slave0 -U $POSTGRES_USER $POSTGRES_DB -Axc "SELECT * FROM users;"
|
|
||||||
[[ "$output" =~ "name|Marko" ]]
|
[[ "$output" =~ "name|Marko" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Replication slave can fetch replication parameters from link alias \"master\"" {
|
@test "Can setup master/slave replication with custom user" {
|
||||||
container_create default -d \
|
container_create default -d \
|
||||||
|
-e POSTGRES_MODE=master \
|
||||||
|
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
||||||
|
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD \
|
||||||
-e POSTGRES_USER=$POSTGRES_USER \
|
-e POSTGRES_USER=$POSTGRES_USER \
|
||||||
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
|
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
|
||||||
-e POSTGRES_DB=$POSTGRES_DB \
|
-e POSTGRES_DB=$POSTGRES_DB
|
||||||
-e POSTGRES_MODE=master \
|
|
||||||
|
container_create slave0 -d \
|
||||||
|
$(container_link default $CONTAINER_NAME) \
|
||||||
|
-e POSTGRES_MODE=slave \
|
||||||
|
-e POSTGRES_MASTER_HOST=$CONTAINER_NAME \
|
||||||
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
||||||
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD
|
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD
|
||||||
|
|
||||||
# create replication slave0 linked to master with alias named master
|
|
||||||
container_create slave0 -d \
|
|
||||||
$(container_link default master) \
|
|
||||||
-e POSTGRES_MODE=slave
|
|
||||||
|
|
||||||
# create users table on master and insert a new row
|
|
||||||
psql_client default -U $POSTGRES_USER $POSTGRES_DB -c \
|
psql_client default -U $POSTGRES_USER $POSTGRES_DB -c \
|
||||||
"CREATE TABLE users (id serial, name varchar(40) NOT NULL); \
|
"CREATE TABLE users (id serial, name varchar(40) NOT NULL); \
|
||||||
INSERT INTO users(name) VALUES ('Marko');"
|
INSERT INTO users(name) VALUES ('Marko');"
|
||||||
|
|
||||||
# check if row is replicated on slave
|
|
||||||
run psql_client slave0 -U $POSTGRES_USER $POSTGRES_DB -Axc "SELECT * FROM users;"
|
run psql_client slave0 -U $POSTGRES_USER $POSTGRES_DB -Axc "SELECT * FROM users;"
|
||||||
[[ "$output" =~ "name|Marko" ]]
|
[[ "$output" =~ "name|Marko" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Slave synchronizes with the master (delayed start)" {
|
@test "Slave synchronizes with the master (delayed start)" {
|
||||||
container_create default -d \
|
container_create default -d \
|
||||||
-e POSTGRES_USER=$POSTGRES_USER \
|
|
||||||
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
|
|
||||||
-e POSTGRES_DB=$POSTGRES_DB \
|
|
||||||
-e POSTGRES_MODE=master \
|
-e POSTGRES_MODE=master \
|
||||||
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
||||||
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD
|
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD \
|
||||||
|
-e POSTGRES_USER=$POSTGRES_USER \
|
||||||
|
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
|
||||||
|
-e POSTGRES_DB=$POSTGRES_DB
|
||||||
|
|
||||||
# create users table on master and insert a new row
|
|
||||||
psql_client default -U $POSTGRES_USER $POSTGRES_DB -c \
|
psql_client default -U $POSTGRES_USER $POSTGRES_DB -c \
|
||||||
"CREATE TABLE users (id serial, name varchar(40) NOT NULL); \
|
"CREATE TABLE users (id serial, name varchar(40) NOT NULL); \
|
||||||
INSERT INTO users(name) VALUES ('Marko');"
|
INSERT INTO users(name) VALUES ('Marko');"
|
||||||
|
|
||||||
# start slave linked to the master
|
|
||||||
container_create slave0 -d \
|
container_create slave0 -d \
|
||||||
$(container_link default $CONTAINER_NAME) \
|
$(container_link default $CONTAINER_NAME) \
|
||||||
-e POSTGRES_MASTER_HOST=$CONTAINER_NAME \
|
|
||||||
-e POSTGRES_MASTER_PORT=5432 \
|
|
||||||
-e POSTGRES_MODE=slave \
|
-e POSTGRES_MODE=slave \
|
||||||
|
-e POSTGRES_MASTER_HOST=$CONTAINER_NAME \
|
||||||
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
||||||
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD
|
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD
|
||||||
|
|
||||||
# verify that master data is replicated on slave
|
|
||||||
run psql_client slave0 -U $POSTGRES_USER $POSTGRES_DB -Axc "SELECT * FROM users;"
|
run psql_client slave0 -U $POSTGRES_USER $POSTGRES_DB -Axc "SELECT * FROM users;"
|
||||||
[[ "$output" =~ "name|Marko" ]]
|
[[ "$output" =~ "name|Marko" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "Replication status is preserved after deletion" {
|
|
||||||
# create master container with host mounted volumes
|
|
||||||
run container_create_with_host_volumes default -d \
|
|
||||||
-e POSTGRES_USER=$POSTGRES_USER \
|
|
||||||
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
|
|
||||||
-e POSTGRES_DB=$POSTGRES_DB \
|
|
||||||
-e POSTGRES_MODE=master \
|
|
||||||
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
|
||||||
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD
|
|
||||||
|
|
||||||
# create users table on master and insert a new row
|
|
||||||
psql_client default -U $POSTGRES_USER $POSTGRES_DB -c \
|
|
||||||
"CREATE TABLE users (id serial, name varchar(40) NOT NULL); \
|
|
||||||
INSERT INTO users(name) VALUES ('Marko');"
|
|
||||||
|
|
||||||
# create slave0 container with host mounted volumes, should replicate the master data
|
|
||||||
container_create_with_host_volumes slave0 -d \
|
|
||||||
$(container_link default $CONTAINER_NAME) \
|
|
||||||
-e POSTGRES_MASTER_HOST=$CONTAINER_NAME \
|
|
||||||
-e POSTGRES_MASTER_PORT=5432 \
|
|
||||||
-e POSTGRES_MODE=slave \
|
|
||||||
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
|
||||||
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD
|
|
||||||
|
|
||||||
# stop and remove master and slave0 containers
|
|
||||||
container_remove slave0
|
|
||||||
container_remove default
|
|
||||||
|
|
||||||
# start master and slave0 containers with existing host volumes and no additional env arguments
|
|
||||||
container_create_with_host_volumes default -d
|
|
||||||
container_create_with_host_volumes slave0 -d $(container_link default $CONTAINER_NAME)
|
|
||||||
|
|
||||||
# insert new row into the master database
|
|
||||||
psql_client default -U $POSTGRES_USER $POSTGRES_DB -c "INSERT INTO users(name) VALUES ('Polo');"
|
|
||||||
|
|
||||||
# verify that all previous and new data is replicated on slave0
|
|
||||||
run psql_client slave0 -U $POSTGRES_USER $POSTGRES_DB -Axc "SELECT * FROM users;"
|
|
||||||
[[ "$output" =~ "name|Marko" ]]
|
|
||||||
[[ "$output" =~ "name|Polo" ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "Replication slave can be triggered to act as the master" {
|
@test "Replication slave can be triggered to act as the master" {
|
||||||
container_create default -d \
|
container_create default -d \
|
||||||
-e POSTGRES_USER=$POSTGRES_USER \
|
|
||||||
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
|
|
||||||
-e POSTGRES_DB=$POSTGRES_DB \
|
|
||||||
-e POSTGRES_MODE=master \
|
-e POSTGRES_MODE=master \
|
||||||
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
||||||
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD
|
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD \
|
||||||
|
-e POSTGRES_USER=$POSTGRES_USER \
|
||||||
|
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
|
||||||
|
-e POSTGRES_DB=$POSTGRES_DB
|
||||||
|
|
||||||
container_create slave0 -d \
|
container_create slave0 -d \
|
||||||
$(container_link default $CONTAINER_NAME) \
|
$(container_link default $CONTAINER_NAME) \
|
||||||
-e POSTGRES_MASTER_HOST=$CONTAINER_NAME \
|
|
||||||
-e POSTGRES_MASTER_PORT=5432 \
|
|
||||||
-e POSTGRES_MODE=slave \
|
-e POSTGRES_MODE=slave \
|
||||||
|
-e POSTGRES_MASTER_HOST=$CONTAINER_NAME \
|
||||||
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
||||||
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD
|
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD
|
||||||
|
|
||||||
# create users table on master and insert a new row
|
|
||||||
psql_client default -U $POSTGRES_USER $POSTGRES_DB -c \
|
psql_client default -U $POSTGRES_USER $POSTGRES_DB -c \
|
||||||
"CREATE TABLE users (id serial, name varchar(40) NOT NULL); \
|
"CREATE TABLE users (id serial, name varchar(40) NOT NULL); \
|
||||||
INSERT INTO users(name) VALUES ('Marko');"
|
INSERT INTO users(name) VALUES ('Marko');"
|
||||||
|
|
@ -375,20 +283,110 @@ cleanup_environment
|
||||||
container_exec slave0 touch /tmp/postgresql.trigger.5432
|
container_exec slave0 touch /tmp/postgresql.trigger.5432
|
||||||
sleep $SLEEP_TIME
|
sleep $SLEEP_TIME
|
||||||
|
|
||||||
# create slave1 that configures slave0 as the master
|
# create new slave that configures slave0 as the master
|
||||||
container_create default -d \
|
container_create default -d \
|
||||||
$(container_link slave0 $CONTAINER_NAME) \
|
$(container_link slave0 $CONTAINER_NAME) \
|
||||||
-e POSTGRES_MASTER_HOST=$CONTAINER_NAME \
|
|
||||||
-e POSTGRES_MASTER_PORT=5432 \
|
|
||||||
-e POSTGRES_MODE=slave \
|
-e POSTGRES_MODE=slave \
|
||||||
|
-e POSTGRES_MASTER_HOST=$CONTAINER_NAME \
|
||||||
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
||||||
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD
|
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD
|
||||||
|
|
||||||
# insert new row into slave0, since it is now the master it should allow writes
|
|
||||||
psql_client slave0 -U $POSTGRES_USER $POSTGRES_DB -c "INSERT INTO users(name) VALUES ('Polo');"
|
psql_client slave0 -U $POSTGRES_USER $POSTGRES_DB -c "INSERT INTO users(name) VALUES ('Polo');"
|
||||||
|
|
||||||
# verify that all past and new data is replicated on slave1
|
# verify that all past and new data is replicated on new slave
|
||||||
run psql_client default -U $POSTGRES_USER $POSTGRES_DB -Axc "SELECT * FROM users;"
|
run psql_client default -U $POSTGRES_USER $POSTGRES_DB -Axc "SELECT * FROM users;"
|
||||||
[[ "$output" =~ "name|Marko" ]]
|
[[ "$output" =~ "name|Marko" ]]
|
||||||
[[ "$output" =~ "name|Polo" ]]
|
[[ "$output" =~ "name|Polo" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "Replication setup and state is preserved after restart" {
|
||||||
|
container_create default -d \
|
||||||
|
-e POSTGRES_MODE=master \
|
||||||
|
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
||||||
|
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD \
|
||||||
|
-e POSTGRES_USER=$POSTGRES_USER \
|
||||||
|
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
|
||||||
|
-e POSTGRES_DB=$POSTGRES_DB
|
||||||
|
|
||||||
|
psql_client default -U $POSTGRES_USER $POSTGRES_DB -c \
|
||||||
|
"CREATE TABLE users (id serial, name varchar(40) NOT NULL); \
|
||||||
|
INSERT INTO users(name) VALUES ('Marko');"
|
||||||
|
|
||||||
|
container_create slave0 -d \
|
||||||
|
$(container_link default $CONTAINER_NAME) \
|
||||||
|
-e POSTGRES_MODE=slave \
|
||||||
|
-e POSTGRES_MASTER_HOST=$CONTAINER_NAME \
|
||||||
|
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
||||||
|
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD
|
||||||
|
|
||||||
|
container_restart default
|
||||||
|
container_restart slave0
|
||||||
|
|
||||||
|
psql_client default -U $POSTGRES_USER $POSTGRES_DB -c "INSERT INTO users(name) VALUES ('Polo');"
|
||||||
|
|
||||||
|
run psql_client slave0 -U $POSTGRES_USER $POSTGRES_DB -Axc "SELECT * FROM users;"
|
||||||
|
[[ "$output" =~ "name|Marko" ]]
|
||||||
|
[[ "$output" =~ "name|Polo" ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "Replication setup and state is preserved after deletion" {
|
||||||
|
container_create_with_host_volumes default -d \
|
||||||
|
-e POSTGRES_MODE=master \
|
||||||
|
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
||||||
|
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD \
|
||||||
|
-e POSTGRES_USER=$POSTGRES_USER \
|
||||||
|
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
|
||||||
|
-e POSTGRES_DB=$POSTGRES_DB
|
||||||
|
|
||||||
|
psql_client default -U $POSTGRES_USER $POSTGRES_DB -c \
|
||||||
|
"CREATE TABLE users (id serial, name varchar(40) NOT NULL); \
|
||||||
|
INSERT INTO users(name) VALUES ('Marko');"
|
||||||
|
|
||||||
|
container_create_with_host_volumes slave0 -d \
|
||||||
|
$(container_link default $CONTAINER_NAME) \
|
||||||
|
-e POSTGRES_MODE=slave \
|
||||||
|
-e POSTGRES_MASTER_HOST=$CONTAINER_NAME \
|
||||||
|
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
||||||
|
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD
|
||||||
|
|
||||||
|
container_remove default
|
||||||
|
container_remove slave0
|
||||||
|
|
||||||
|
container_create_with_host_volumes default -d
|
||||||
|
container_create_with_host_volumes slave0 -d $(container_link default $CONTAINER_NAME)
|
||||||
|
|
||||||
|
psql_client default -U $POSTGRES_USER $POSTGRES_DB -c "INSERT INTO users(name) VALUES ('Polo');"
|
||||||
|
|
||||||
|
run psql_client slave0 -U $POSTGRES_USER $POSTGRES_DB -Axc "SELECT * FROM users;"
|
||||||
|
[[ "$output" =~ "name|Marko" ]]
|
||||||
|
[[ "$output" =~ "name|Polo" ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "Slave recovers if master is temporarily offine" {
|
||||||
|
container_create_with_host_volumes default -d \
|
||||||
|
-e POSTGRES_MODE=master \
|
||||||
|
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
||||||
|
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD \
|
||||||
|
-e POSTGRES_USER=$POSTGRES_USER \
|
||||||
|
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
|
||||||
|
-e POSTGRES_DB=$POSTGRES_DB
|
||||||
|
|
||||||
|
psql_client default -U $POSTGRES_USER $POSTGRES_DB -c \
|
||||||
|
"CREATE TABLE users (id serial, name varchar(40) NOT NULL); \
|
||||||
|
INSERT INTO users(name) VALUES ('Marko');"
|
||||||
|
|
||||||
|
container_create_with_host_volumes slave0 -d \
|
||||||
|
$(container_link default $CONTAINER_NAME) \
|
||||||
|
-e POSTGRES_MODE=slave \
|
||||||
|
-e POSTGRES_MASTER_HOST=$CONTAINER_NAME \
|
||||||
|
-e POSTGRES_REPLICATION_USER=$POSTGRES_REPLICATION_USER \
|
||||||
|
-e POSTGRES_REPLICATION_PASSWORD=$POSTGRES_REPLICATION_PASSWORD
|
||||||
|
|
||||||
|
container_restart default
|
||||||
|
|
||||||
|
psql_client default -U $POSTGRES_USER $POSTGRES_DB -c "INSERT INTO users(name) VALUES ('Polo');"
|
||||||
|
|
||||||
|
run psql_client slave0 -U $POSTGRES_USER $POSTGRES_DB -Axc "SELECT * FROM users;"
|
||||||
|
[[ "$output" =~ "name|Marko" ]]
|
||||||
|
[[ "$output" =~ "name|Polo" ]]
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue