Sign inSign up

devopsnamasys/postgres

By devopsnamasys

•Updated over 5 years ago

This postgres creates the PGDATA folder path with the permission of 750.

Image
0

354

devopsnamasys/postgres repository overview

⁠devopsnamasys/postgres

This readme file tells about the changes, and the functions about the different version of the docker images of the postgres which we have in the available repo.

⁠v0.0.4

⁠Motivation :

*In this version of the docker image, we have introduced a new feature which is replication manager for the postgres deployed. *In simple terms, it means that you can create master-slaves of postgres which is termed as Replication in terms of Postgres.

  • You can have more than one slave in this postgres configuration.
  • The PgBouncer still works on 6432 port and the replication connection between the master and the slaves are done using the 5432 port.
⁠Execution :
⁠For single postgres instance :
docker run -d -p 6432:6432 \
-e POSTGRES_PASSWORD=${YOUR_PASSWORD} \ 
-e POSTGRES_USER=${YOUR USERNAME} \ 
-e POSTGRES_DB=${YOUR_DB_NAME} \
-e POSTGRESQL_MAX_CONNECTIONS=${YOUR_CONNECTION_COUNT} \
-v ${PATH_TO_YOUR_PGBOUNCER.INI}:/etc/pgbouncer/pgbouncer.ini \ 
-v ${PATH_TO_YOUR_USERLIST.TXT}:/etc/pgbouncer/userlist.txt \
--name postgres \
devopsnamasys/postgres:0.0.4
⁠In Replication Mode :

You can follow/use the following docker-compose file for initiating a postgres cluster with master and slave nodes.

version: '3.7'

services:
  postgresql-master:
    image: devopsnamasys/postgres:0.0.4
    ports:
      - '5400:6432'
    volumes:
      - './backups:/postgres/data/'
      - './pgbouncer_confFiles/pgbouncer.ini:/etc/pgbouncer/pgbouncer.ini'
      - './pgbouncer_confFiles/userlist.txt:/etc/pgbouncer/userlist.txt'
    environment:
      POSTGRESQL_REPLICATION_MODE: master
      POSTGRESQL_REPLICATION_USER: repl_user
      POSTGRESQL_REPLICATION_PASSWORD: repl_password
      POSTGRESQL_USERNAME: postgres
      POSTGRESQL_PASSWORD: root
      POSTGRESQL_DATABASE: nuwebapp
      ALLOW_EMPTY_PASSWORD: "yes"
      BACKUPTIME: "12:15:00"
      PGDATA: /postgres/data
      POSTGRESQL_MAX_CONNECTIONS: 500
  postgresql-slave1:
    image: devopsnamasys/postgres:0.0.4
    ports:
      - '5401:6432'
    depends_on:
      - postgresql-master
    environment:
      POSTGRESQL_REPLICATION_MODE: slave
      POSTGRESQL_REPLICATION_USER: repl_user
      POSTGRESQL_REPLICATION_PASSWORD: repl_password
      POSTGRESQL_MASTER_HOST: postgresql-master
      POSTGRESQL_PASSWORD: root
      POSTGRESQL_MASTER_PORT_NUMBER: "5432"
      ALLOW_EMPTY_PASSWORD: "yes"
      POSTGRESQL_MAX_CONNECTIONS: 500
    container_name: postgres_slave_1
  postgresql-slave2:
    image: devopsnamasys/postgres:0.0.4
    ports:
      - '5402:6432'
    depends_on:
      - postgresql-master
    environment:
      POSTGRESQL_REPLICATION_MODE: slave
      POSTGRESQL_REPLICATION_USER: repl_user
      POSTGRESQL_REPLICATION_PASSWORD: repl_password
      POSTGRESQL_MASTER_HOST: postgresql-master
      POSTGRESQL_PASSWORD: root
      POSTGRESQL_MASTER_PORT_NUMBER: "5432"
      ALLOW_EMPTY_PASSWORD: "yes"
      POSTGRESQL_MAX_CONNECTIONS: 500
    container_name: postgres_slave_2

volumes:
  backups:

⁠v0.0.3

⁠Motivation :

In this version of the docker image we have created an inbuilt pgbouncer installed for the connection pooling . The service runs on 6432 port inside the docker container. And port forwarding can be used to access the functions of the pgbouncer on the exposed port outside the container. PgBouncer has default pgbouncer.ini and userlist.txt, which can be mounted with customized .ini file and userlist.txt.

⁠Execution :
docker run -d -e POSTGRES_PASSWORD=1234 \
  -e BACKUPTIME="18:00:00"  \
 -e PGDATA=/postgres/data  \
-v .$PWD/pgdata/data:/postgres/data \
-v $PWD/pgbouncer.ini:/etc/pgbouncer/pgbouncer.ini \
-v $PWD/userlist.txt:/etc/pgbouncer/userlist.txt \
devopsnamasys/postgres:0.0.3

⁠v0.0.2

⁠Motivation :

In this version of the docker image we have created an inbuild function of the backup of the Postgres Databases. We introduced an environmental varibale called BACKUPFOLDER and BACKUPTIME.

  • BACKUPTIME: This will be the env varibale which we can define at what time do we want to create a backup of the databases available in the postgres.
⁠Execution :
docker run -d -e POSTGRES_PASSWORD=1234  -e BACKUPTIME="18:00:00" -v backup:/backups devopsnamasys/postgres:0.0.2

⁠v0.0.1

⁠Motivation :
  • By default the PGDATA folder/path inside the Postgres docker container has a permissions and ownership of the postgres user. When you try to mount the PGDATA of the container, then in that case on the host machine it coincides with the gid and uid of 999, because of which it is quite possible that the mounted folder on the host machine has permission issue and it can be accessed by any user.
  • So in order to create a permission for the folder to be atleast accessible by the root user on the host machine, we have added a chmod operation to make it accessible.
⁠Execution
docker run -d -e POSTGRES_PASSWORD=1234 -v pgdata:${PGDATA} devopsnamasys/postgres:0.0.1

Tag summary

Content type

Image

Digest

Size

181.6 MB

Last updated

over 5 years ago

docker pull devopsnamasys/postgres:0.0.4