Pgpool-II is a PostgreSQL proxy. It stands between PostgreSQL servers and their clients providing connection pooling, load balancing, automated failover, and replication.
$ curl -sSL https://raw.githubusercontent.com/bitnami/bitnami-docker-pgpool/master/docker-compose.yml > docker-compose.yml
$ docker-compose up -d
- Bitnami closely tracks upstream source changes and promptly publishes new versions of this image using our automated systems.
- With Bitnami images the latest bug fixes and features are available as soon as possible.
- Bitnami containers, virtual machines and cloud images use the same components and configuration approach - making it easy to switch between formats based on your project needs.
- All our images are based on minideb a minimalist Debian based container image which gives you a small base container image and the familiarity of a leading linux distribution.
- All Bitnami images available in Docker Hub are signed with Docker Content Trust (DTC). You can use
DOCKER_CONTENT_TRUST=1
to verify the integrity of the images. - Bitnami container images are released daily with the latest distribution packages available.
This CVE scan report contains a security report with all open CVEs. To get the list of actionable security issues, find the "latest" tag, click the vulnerability report link under the corresponding "Security scan" field and then select the "Only show fixable" filter on the next page.
Deploying Bitnami applications as Helm Charts is the easiest way to get started with our applications on Kubernetes. Read more about the installation in the Bitnami PostgreSQL HA Chart GitHub repository.
Bitnami containers can be used with Kubeapps for deployment and management of Helm Charts in clusters.
Non-root container images add an extra layer of security and are generally recommended for production environments. However, because they run as a non-root user, privileged tasks are typically off-limits. Learn more about non-root containers in our docs.
Learn more about the Bitnami tagging policy and the difference between rolling tags and immutable tags in our documentation page.
Subscribe to project updates by watching the bitnami/pgpool GitHub repo.
The recommended way to get the Bitnami Pgpool-II Docker Image is to pull the prebuilt image from the Docker Hub Registry.
$ docker pull bitnami/pgpool:latest
To use a specific version, you can pull a versioned tag. You can view the list of available versions in the Docker Hub Registry.
$ docker pull bitnami/pgpool:[TAG]
If you wish, you can also build the image yourself.
$ docker build -t bitnami/pgpool:latest 'https://github.com/bitnami/bitnami-docker-pgpool.git#master:4/debian-10'
Using Docker container networking, a different server running inside a container can easily be accessed by your application containers and vice-versa.
Containers attached to the same network can communicate with each other using the container name as the hostname.
In this example, we will create a PostgreSQL client instance that will connect to the pgpool instance that is running on the same docker network as the client.
$ docker network create my-network --driver bridge
Use the --network <NETWORK>
argument to the docker run
command to attach the container to the my-network
network.
$ docker run --detach --rm --name pg-0 \
--network my-network \
--env REPMGR_PARTNER_NODES=pg-0,pg-1 \
--env REPMGR_NODE_NAME=pg-0 \
--env REPMGR_NODE_NETWORK_NAME=pg-0 \
--env REPMGR_PRIMARY_HOST=pg-0 \
--env REPMGR_PASSWORD=repmgrpass \
--env POSTGRESQL_POSTGRES_PASSWORD=adminpassword \
--env POSTGRESQL_USERNAME=customuser \
--env POSTGRESQL_PASSWORD=custompassword \
--env POSTGRESQL_DATABASE=customdatabase \
bitnami/postgresql-repmgr:latest
$ docker run --detach --rm --name pg-1 \
--network my-network \
--env REPMGR_PARTNER_NODES=pg-0,pg-1 \
--env REPMGR_NODE_NAME=pg-1 \
--env REPMGR_NODE_NETWORK_NAME=pg-1 \
--env REPMGR_PRIMARY_HOST=pg-0 \
--env REPMGR_PASSWORD=repmgrpass \
--env POSTGRESQL_POSTGRES_PASSWORD=adminpassword \
--env POSTGRESQL_USERNAME=customuser \
--env POSTGRESQL_PASSWORD=custompassword \
--env POSTGRESQL_DATABASE=customdatabase \
bitnami/postgresql-repmgr:latest
Use the --network <NETWORK>
argument to the docker run
command to attach the container to the my-network
network.
$ docker run --detach --rm --name pgpool \
--network my-network \
--env PGPOOL_BACKEND_NODES=0:pg-0:5432,1:pg-1:5432 \
--env PGPOOL_SR_CHECK_USER=customuser \
--env PGPOOL_SR_CHECK_PASSWORD=custompassword \
--env PGPOOL_ENABLE_LDAP=no \
--env PGPOOL_POSTGRES_USERNAME=postgres \
--env PGPOOL_POSTGRES_PASSWORD=adminpassword \
--env PGPOOL_ADMIN_USERNAME=admin \
--env PGPOOL_ADMIN_PASSWORD=adminpassword \
bitnami/pgpool:latest
Finally we create a new container instance to launch the PostgreSQL client and connect to the server created in the previous step:
$ docker run -it --rm \
--network my-network \
bitnami/postgresql:10 \
psql -h pgpool -U customuser -d customdatabase
When not specified, Docker Compose automatically sets up a new network and attaches all deployed services to that network. However, we will explicitly define a new bridge
network named my-network
. In this example we assume that you want to connect to the Pgpool server from your own custom application image which is identified in the following snippet by the service name myapp
.
version: '2'
networks:
my-network:
driver: bridge
services:
pg-0:
image: bitnami/postgresql-repmgr:11
ports:
- 5432
volumes:
- pg_0_data:/bitnami/postgresql
environment:
- POSTGRESQL_POSTGRES_PASSWORD=adminpassword
- POSTGRESQL_USERNAME=customuser
- POSTGRESQL_PASSWORD=custompassword
- POSTGRESQL_DATABASE=customdatabase
- REPMGR_PASSWORD=repmgrpassword
- REPMGR_PRIMARY_HOST=pg-0
- REPMGR_PARTNER_NODES=pg-0,pg-1
- REPMGR_NODE_NAME=pg-0
- REPMGR_NODE_NETWORK_NAME=pg-0
pg-1:
image: bitnami/postgresql-repmgr:11
ports:
- 5432
volumes:
- pg_1_data:/bitnami/postgresql
environment:
- POSTGRESQL_POSTGRES_PASSWORD=adminpassword
- POSTGRESQL_USERNAME=customuser
- POSTGRESQL_PASSWORD=custompassword
- POSTGRESQL_DATABASE=customdatabase
- REPMGR_PASSWORD=repmgrpassword
- REPMGR_PRIMARY_HOST=pg-0
- REPMGR_PARTNER_NODES=pg-0,pg-1
- REPMGR_NODE_NAME=pg-1
- REPMGR_NODE_NETWORK_NAME=pg-1
pgpool:
image: bitnami/pgpool:4
ports:
- 5432:5432
environment:
- PGPOOL_BACKEND_NODES=0:pg-0:5432,1:pg-1:5432
- PGPOOL_SR_CHECK_USER=customuser
- PGPOOL_SR_CHECK_PASSWORD=custompassword
- PGPOOL_ENABLE_LDAP=no
- PGPOOL_POSTGRES_USERNAME=postgres
- PGPOOL_POSTGRES_PASSWORD=adminpassword
- PGPOOL_ADMIN_USERNAME=admin
- PGPOOL_ADMIN_PASSWORD=adminpassword
healthcheck:
test: ["CMD", "/healthcheck.sh"]
interval: 10s
timeout: 5s
retries: 5
myapp:
image: 'YOUR_APPLICATION_IMAGE'
networks:
- my-network
volumes:
pg_0_data:
driver: local
pg_1_data:
driver: local
IMPORTANT:
- Please update the YOUR_APPLICATION_IMAGE_ placeholder in the above snippet with your application image
- In your application container, use the hostname
pgpool
to connect to the PostgreSQL server
Launch the containers using:
$ docker-compose up -d
A HA PostgreSQL cluster with Pgpool, Streaming replication and repmgr can easily be setup with the Bitnami PostgreSQL with Replication Manager and Pgpool Docker Images using the following environment variables:
Pgpool:
PGPOOL_PASSWORD_FILE
: Path to a file that contains the password for the custom user set in thePGPOOL_USERNAME
environment variable. This will override the value specified inPGPOOL_PASSWORD
. No defaults.PGPOOL_SR_CHECK_PERIOD
: Specifies the time interval in seconds to check the streaming replication delay. Defaults to30
.PGPOOL_SR_CHECK_USER
: Username to use to perform streaming checks. No defaults.PGPOOL_SR_CHECK_PASSWORD
: Password to use to perform streaming checks. No defaults.PGPOOL_SR_CHECK_PASSWORD_FILE
: Path to a file that contains the password to use to perform streaming checks. This will override the value specified inPGPOOL_SR_CHECK_PASSWORD
. No defaults.PGPOOL_BACKEND_NODES
: Comma separated list of backend nodes in the cluster. No defaults.PGPOOL_ENABLE_LDAP
: Whether to enable LDAP authentication. Defaults tono
.PGPOOL_DISABLE_LOAD_BALANCE_ON_WRITE
: Specify load balance behavior after write queries appear ('off', 'transaction', 'trans_transaction', 'always'). Defaults to 'transaction'PGPOOL_NUM_INIT_CHILDREN
: The number of preforked Pgpool-II server processes. num_init_children is also the concurrent connections limit to Pgpool-II from clients. Defaults to 32.PGPOOL_ENABLE_LOAD_BALANCING
: Whether to enable Load-Balancing mode. Defaults toyes
.PGPOOL_ENABLE_STATEMENT_LOAD_BALANCING
: Whether to decide the load balancing node for each read query. Defaults tono
.PGPOOL_ENABLE_POOL_HBA
: Whether to use the pool_hba.conf authentication. Defaults toyes
.PGPOOL_ENABLE_POOL_PASSWD
: Whether to use a password file specified byPGPOOL_PASSWD_FILE
for authentication. Defaults toyes
.PGPOOL_PASSWD_FILE
: The password file for authentication. Defaults topool_passwd
.PGPOOL_MAX_POOL
: The maximum number of cached connections in each child process. Defaults to15
.PGPOOL_LISTEN_BACKLOG_MULTIPLIER
: Specifies the length of connection queue from frontend to Pgpool-II. Defaults to2
.PGPOOL_SERIALIZE_ACCEPT
: When set to on, Pgpool-II enables the serialization on incoming client connections. Defaults tono
.PGPOOL_MEMORY_CACHE_ENABLED
: Setting to on enables the memory cache. Default is. Defaults tono
.PGPOOL_NUM_INIT_CHILDREN
: The number of preforked Pgpool server processes. Default is32
.PGPOOL_POSTGRES_USERNAME
: Postgres administrator user name, this will be use to allow postgres admin authentication through Pgpool.PGPOOL_POSTGRES_PASSWORD
: Password for the user set inPGPOOL_POSTGRES_USERNAME
environment variable. No defaults.PGPOOL_ADMIN_USERNAME
: Username for the pgpool administrator. No defaults.PGPOOL_ADMIN_PASSWORD
: Password for the user set inPGPOOL_ADMIN_USERNAME
environment variable. No defaults.PGPOOL_HEALTH_CHECK_USER
: Specifies the PostgreSQL user name to perform health check. Defaults to value set inPGPOOL_SR_CHECK_USER
.PGPOOL_HEALTH_CHECK_PERIOD
: Specifies the interval between the health checks in seconds. Defaults to30
.PGPOOL_HEALTH_CHECK_TIMEOUT
: Specifies the timeout in seconds to give up connecting to the backend PostgreSQL if the TCP connect does not succeed within this time. Defaults to10
.PGPOOL_HEALTH_CHECK_MAX_RETRIES
: Specifies the maximum number of retries to do before giving up and initiating failover when health check fails. Defaults to5
.PGPOOL_HEALTH_CHECK_RETRY_DELAY
: Specifies the amount of time in seconds to sleep between failed health check retries. Defaults to5
.PGPOOL_USER_CONF_FILE
: Configuration file to be added to the generated config file. This allow to override configuration set by the initializacion process. No defaults.PGPOOL_POSTGRES_CUSTOM_USERS
: List of comma or semicolon separeted list of postgres usernames. This will create entries inpgpool_passwd
. No defaults.PGPOOL_POSTGRES_CUSTOM_PASSWORDS
: List of comma or semicolon separated list for postgresql user passwords. These are the corresponding passwords for the users inPGPOOL_POSTGRES_CUSTOM_USERS
. No defaults.PGPOOL_ENABLE_SHARED_RELCACHE
: By setting to on, relation cache is shared among Pgpool-II child processes using the in memory query cache. Defaults toon
. Cache invalidation is not happen even if the system catalog is modified. So it is strongly recommend to set time out base cache invalidation by usingPGPOOL_RELCACHE_EXPIRE
.PGPOOL_RELCACHE_EXPIRE
: Specifies the relation cache expiration time in seconds. Defaults to0
, which means the cache never expires.PGPOOL_RELCACHE_SIZE
: Specifies the number of relcache entries. Defaults to256
.PGPOOL_RELCACHE_QUERY_TARGET
: The target node to send queries to create relation cache entries ('master', 'load_balance_node'). Defaults tomaster
.PGPOOL_CHECK_TEMP_TABLE
: Setting to catalog or trace, enables the temporary table check in the SELECT statements ('catalog', 'trace', 'none'). Defaults tocatalog
.PGPOOL_CHECK_UNLOGGED_TABLE
: Setting to on, enables the unlogged table check in the SELECT statements. Defaults toon
.PGPOOL_REGION
: Region of the Pgpool-II server. No defaults.PGPOOL_BACKEND_NODES_REGION_WEIGHT
: Comma separated list of backend nodes region weight in the cluster. No defaults. e.g this value ispg-0:eu-west:2,pg-1:eu-south:2
andPGPOOL_REGION
is set toeu-west
the weight of the backend nodepg-0
will be set to2
on startup.
PostgreSQL with Replication Manager:
POSTGRESQL_POSTGRES_PASSWORD
: Password forpostgres
user. No defaults.POSTGRESQL_POSTGRES_PASSWORD_FILE
: Path to a file that contains thepostgres
user password. This will override the value specified inPOSTGRESQL_POSTGRES_PASSWORD
. No defaults.POSTGRESQL_USERNAME
: Custom user to access the database. No defaults.POSTGRESQL_DATABASE
: Custom database to be created on first run. No defaults.POSTGRESQL_PASSWORD
: Password for the custom user set in thePOSTGRESQL_USERNAME
environment variable. No defaults.POSTGRESQL_PASSWORD_FILE
: Path to a file that contains the password for the custom user set in thePOSTGRESQL_USERNAME
environment variable. This will override the value specified inPOSTGRESQL_PASSWORD
. No defaults.REPMGR_USERNAME
: Username forrepmgr
user. Defaults torepmgr
.REPMGR_PASSWORD_FILE
: Path to a file that contains therepmgr
user password. This will override the value specified inREPMGR_PASSWORD
. No defaults.REPMGR_PASSWORD
: Password forrepmgr
user. No defaults.REPMGR_PRIMARY_HOST
: Hostname of the initial primary node. No defaults.REPMGR_PARTNER_NODES
: Comma separated list of partner nodes in the cluster. No defaults.REPMGR_NODE_NAME
: Node name. No defaults.REPMGR_NODE_NETWORK_NAME
: Node hostname. No defaults.
In a HA PostgreSQL cluster you can have one primary and zero or more standby nodes. The primary node is in read-write mode, while the standby nodes are in read-only mode. For best performance its advisable to limit the reads to the standby nodes.
$ docker network create my-network --driver bridge
The first step is to start the initial primary node:
$ docker run --detach --name pg-0 \
--network my-network \
--env REPMGR_PARTNER_NODES=pg-0,pg-1 \
--env REPMGR_NODE_NAME=pg-0 \
--env REPMGR_NODE_NETWORK_NAME=pg-0 \
--env REPMGR_PRIMARY_HOST=pg-0 \
--env REPMGR_PASSWORD=repmgrpass \
--env POSTGRESQL_POSTGRES_PASSWORD=adminpassword \
--env POSTGRESQL_USERNAME=customuser \
--env POSTGRESQL_PASSWORD=custompassword \
--env POSTGRESQL_DATABASE=customdatabase \
bitnami/postgresql-repmgr:latest
Next we start a standby node:
$ docker run --detach --name pg-1 \
--network my-network \
--env REPMGR_PARTNER_NODES=pg-0,pg-1 \
--env REPMGR_NODE_NAME=pg-1 \
--env REPMGR_NODE_NETWORK_NAME=pg-1 \
--env REPMGR_PRIMARY_HOST=pg-0 \
--env REPMGR_PASSWORD=repmgrpass \
--env REPMGR_PASSWORD=repmgrpass \
--env POSTGRESQL_POSTGRES_PASSWORD=adminpassword \
--env POSTGRESQL_USERNAME=customuser \
--env POSTGRESQL_PASSWORD=custompassword \
--env POSTGRESQL_DATABASE=customdatabase \
bitnami/postgresql-repmgr:latest
$ docker run --detach --rm --name pgpool \
--network my-network \
--env PGPOOL_BACKEND_NODES=0:pg-0:5432,1:pg-1:5432 \
--env PGPOOL_SR_CHECK_USER=postgres \
--env PGPOOL_SR_CHECK_PASSWORD=adminpassword \
--env PGPOOL_ENABLE_LDAP=no \
--env PGPOOL_USERNAME=customuser \
--env PGPOOL_PASSWORD=custompassword \
bitnami/pgpool:latest
With these three commands you now have a two node PostgreSQL primary-standby streaming replication cluster using Pgpool as proxy up and running. You can scale the cluster by adding/removing standby nodes without incurring any downtime.
Note: The cluster replicates the primary in its entirety, which includes all users and databases.
If the master goes down, repmgr will ensure any of the standby nodes takes the primary role, guaranteeing high availability.
Note: The configuration of the other nodes in the cluster needs to be updated so that they are aware of them. This would require you to restart the old nodes adapting the
REPMGR_PARTNER_NODES
environment variable. You also need to restart the Pgpoll instance adapting thePGPOOL_BACKEND_NODES
environment variable.
With Docker Compose the HA PostgreSQL cluster can be setup using the docker-compose.yml
file present in this repository:
$ curl -sSL https://raw.githubusercontent.com/bitnami/bitnami-docker-pgpool/master/docker-compose.yml > docker-compose.yml
$ docker-compose up -d
Everytime the container is started, it will execute the files with extension .sh
located at /docker-entrypoint-initdb.d
after initializing Pgpool.
In order to have your custom files inside the docker image you can mount them as a volume. With docker-compose:
image: bitnami/pgpool:4
ports:
- 5432:5432
+ volumes:
+ - /path/to/init-scripts:/docker-entrypoint-initdb.d
environment:
- PGPOOL_BACKEND_NODES=0:pg-0:5432,1:pg-1:5432
- PGPOOL_SR_CHECK_USER=customuser
You can override the default configuration by providing a configuration file. Set PGPOOL_USER_CONF_FILE
with the path of the file, and this will be added to the default configuration.
$ cat myconf.conf
max_pool='300'
Run the Pgpool image, mounting a directory from your host and setting PGPOOL_USER_CONF_FILE
. Using Docker Compose:
image: bitnami/pgpool:4
ports:
- 5432:5432
+ volumes:
+ - /path/to/myconf.conf:/config/myconf.conf
environment:
+ - PGPOOL_USER_CONF_FILE=/config/myconf.conf
- PGPOOL_BACKEND_NODES=0:pg-0:5432,1:pg-1:5432
- PGPOOL_SR_CHECK_USER=customuser
Start your Pgpool container for changes to take effect.
$ docker restart pgpool
or using Docker Compose:
$ docker-compose restart pgpool
Refer to the server configuration manual for the complete list of configuration options.
Pgpool does not reattach nodes automatically, to reattach a node you have to get the id
of the node and then run the attach command manually.
To get the node id
first connect to the pgpool container and open a psql session:
$ docker exec -it pgpool bash
$ PGPASSWORD=$PGPOOL_POSTGRES_PASSWORD psql -U $PGPOOL_POSTGRES_USERNAME -h localhost
and run: show pool_nodes;
postgres=# show pool_nodes;
node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay | replication_state | replication_sync_state | last_status_change
---------+----------+------+--------+-----------+---------+------------+-------------------+-------------------+-------------------+------------------------+---------------------
0 | pg-0 | 5432 | down | 0.500000 | standby | 0 | true | 0 | | | 2020-07-09 15:50:41
1 | pg-1 | 5432 | up | 0.500000 | primary | 0 | false | 0 | | | 2020-07-09 15:48:31
(2 rows)
In this example pg-0 is the node we want to reattach, we will use node 0
.
Now exit psql console and run the following command, 0
is the node id we got in the previous step.
$ pcp_attach_node -h localhost -U $PGPOOL_ADMIN_USERNAME 0
This command will prompt for a password, this password is the one set in the environment variable: PGPOOL_ADMIN_PASSWORD
Please see the list of environment variables available in the Bitnami Pgpool container in the next table:
Environment Variable | Default value |
---|---|
PGPOOL_BACKEND_NODES | nil |
PGPOOL_PORT_NUMBER | 5432 |
PGPOOL_SR_CHECK_USER | nil |
PGPOOL_SR_CHECK_PASSWORD | nil |
PGPOOL_SR_CHECK_PASSWORD_FILE | nil |
PGPOOL_POSTGRES_USERNAME | nil |
PGPOOL_POSTGRES_PASSWORD | nil |
PGPOOL_PASSWORD_FILE | nil |
PGPOOL_TIMEOUT | 360 |
PGPOOL_ENABLE_LDAP | no |
PGPOOL_ADMIN_USERNAME=admin | nil |
PGPOOL_ADMIN_PASSWORD=adminpassword | nil |
PGPOOL_ENABLE_LOAD_BALANCING | yes |
PGPOOL_ENABLE_POOL_HBA | yes |
PGPOOL_ENABLE_POOL_PASSWD | yes |
PGPOOL_PASSWD_FILE | pool_passwd |
PGPOOL_MAX_POOL | 15 |
PGPOOL_NUM_INIT_CHILDREN | 32 |
PGPOOL_POSTGRES_CUSTOM_USERS | nil |
PGPOOL_POSTGRES_CUSTOM_PASSWORDS | nil |
The Bitnami Pgpool-II Docker image sends the container logs to stdout
. To view the logs:
$ docker logs pgpool
You can configure the containers logging driver using the --log-driver
option if you wish to consume the container logs differently. In the default configuration docker uses the json-file
driver.
Bitnami provides up-to-date versions of Pgpool-II, including security patches, soon after they are made upstream. We recommend that you follow these steps to upgrade your container.
$ docker pull bitnami/pgpool:latest
Stop the currently running container using the command
$ docker-compose stop pgpool
$ docker-compose rm -v pgpool
Re-create your container from the new image.
$ docker-compose up pgpool
- The Pgpool container has been migrated to a "non-root" user approach. Previously the container ran as the
root
user and the Pgpool daemon was started as thepgpool
user. From now on, both the container and the Pgpool daemon run as user1001
. You can revert this behavior by changingUSER 1001
toUSER root
in the Dockerfile. - No backwards compatibility issues are expected.
- Environment variables related to LDAP configuration were renamed removing the
PGPOOL_
prefix. For instance, to indicate the LDAP URI to use, you must setLDAP_URI
instead ofPGPOOL_LDAP_URI
.
4.1.0-centos-7-r8
is considered the latest image based on CentOS.- Standard supported distros: Debian & OEL.
We'd love for you to contribute to this container. You can request new features by creating an issue, or submit a pull request with your contribution.
If you encountered a problem running this container, you can file an issue. For us to provide better support, be sure to include the following information in your issue:
- Host OS and version
- Docker version (
docker version
) - Output of
docker info
- Version of this container
- The command you used to run the container, and any relevant output you saw (masking any sensitive information)
Copyright 2020 Bitnami
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.