Skip to content

Repository files navigation

nfrastack/container-postgres

About

This will build a container image for PostgreSQL,A relational database.

Features:

  • Customizable Super user account and password
  • Multiple database and user creation
  • Extension Support
  • Replication (Main, Secondary, Snapshot) support
  • Monitoring support via Zabbix Agent 2
  • Customizable paths for logs, config, data

Maintainer

Table of Contents

Installation

Prebuilt Images

Feature limited builds of the image are available on the Github Container Registry and Docker Hub.

To unlock advanced features, one must provide a code to be able to change specific environment variables from defaults. Support the development to gain access to a code.

To get access to the image use your container orchestrator to pull from the following locations:

ghcr.io/nfrastack/container-postgres:(image_tag)
docker.io/nfrastack/postgres:(image_tag)

Image tag syntax is:

<image>:<branch>-<optional tag>-<optional_distribution>_<optional_distribution_variant>

Example:

ghcr.io/nfrastack/container-postgres:18 or

ghcr.io/nfrastack/container-postgres:latest or

ghcr.io/nfrastack/container-postgres:18-1.0 or

  • latest will be the most recent postgresql version and commit
  • branch will be the repositories branch, typically matching with the version of Postgres eg 18
  • An optional tag may exist that matches the CHANGELOG - These are the safest
  • If there are multiple distribution variations it may include a version - see the registry for availability

Have a look at the container registries and see what tags are available.

Multi-Architecture Support

Images are built for amd64 by default, with optional support for arm64 and other architectures.

Quick Start

Persistent Storage

The following directories are used for configuration and can be mapped for persistent storage.

DirectoryDescription
/certs/(optional) Drop TLS Certificates here
/data/Databases
/logs/Logfiles

Environment Variables

Base Images used

This image relies on a customized base image in order to work. Be sure to view the following repositories to understand all the customizable options:

ImageDescription
OS BaseBase Image

Below is the complete list of available options that can be used to customize your installation.

  • Variables showing an 'x' under the Advanced column can only be set if the containers advanced functionality is enabled.

Core Configuration

Container Options

ParameterDescriptionDefault
CERT_PATHCertificates location/certs/
CONFIG_PATHCustom location for configuration e.g /config/ - Drop custom .conf files here
CONFIG_MODEConfiguration mode COREDEFAULT - To be used at a later releaseCORE
DATA_PATHDatabase storage/data/
HBA_FILEHost based access file name/etc/postgres/pg_hba.conf
IDENT_FILEIdentity file name/etc/postgres/pg_ident.conf
LOG_FILELogfile namepostgresql.log
LOG_FORMATLog format NORMALJSON or CSV Filename extension will change from .log to either .json or .csvNORMAL
LOG_LEVELLog level messagesWARNING
Values can be in descending detail DEBUG5,DEBUG4,DEBUG3,DEBUG2,DEBUG1,
INFO,NOTICE,WARNING,ERROR,LOG,FATAL,PANIC
LOG_LEVEL_ERROR_STATEMENTSLog level for errorsERROR
LOG_PATHStore log files here/logs/
LOG_TYPELog Type CONSOLE or FILEFILE
SETUP_MODEAUTO generate configuration files based on env varsAUTO
WAL_PATHWrite ahead log path if needing to be seperate from DATA_PATH

Server Options

These options are related to overall server operations. Those bracketed with (init) cannot be changed after first run.

ParameterDescriptionDefault_FILE
ENABLE_DATA_CHECKSUMS(init) Enable Data ChecksummingFALSE
INITDB_ARGSSend arguments to initdb function
INITDB_ENCODING(init) DB EncodingUTF-8
INITDB_LC_COLLATE(init) Locale CollationC
INITDB_LC_CTYPE(init) Locale CTypeC
INITDB_LOCALE(init) Localeen
LISTEN_IPListen Interface*
LISTEN_PORTListening Port5432
MAX_CONNECTIONSMaximum concurrent connections to accept100
SERVER_ARGSSend arguments to main Postgresql server process
SUPERUSER_PASSPassword for postgres super user account``x
SUPERUSER_USERName of super user accountpostgresx
WAL_SEGMENT_SIZE_MB(init) Write ahead log segment size in MB18

Database Options

Automatically create user databases on startup. This can be done on each container start, and then removed on subsequent starts if desired.

ParameterDescriptionDefault_FILE
CREATE_DBAutomatically create databases on startupTRUEx
DB_NAMEDatabase Name e.g. databasex
DB_USERDatabase User e.g. userx
DB_PASSDatabase Pass e.g. passwordx
DB_EXTENSION(optional) Database Extension e.g. unaccentx

OR

Create multiple databases and different usernames and passwords to access. You can share usernames and passwords for multiple databases by using the same user and password in each entry.

ParameterDescriptionDefault_FILEAdvanced
DB01_NAMEFirst Database Name e.g. database1x
DB01_USERFirst Database User e.g. user1x
DB01_PASSFirst Database Pass e.g. password1x
DB01_EXTENSION(optional) Database Extension e.g. unaccentx
DB02_NAMESecond Database Name e.g. database1x
DB02_USERSecond Database User e.g. user2x
DB02_PASSSecond Database Pass e.g. password2x
DB02_EXTENSION(optional) Database Extension e.g. unaccent
DBXX_...As above, should be able to go all the way to 99x

Advanced mode allows you to maange more than 3 databases.

Replication Options

Enable replication from a main provider to a secondary read only node or a one time snapshot that can be used for read write later on.

ParameterDescriptionDefault_FILE
ENABLE_REPLICATIONEnable Replication FunctionalityFALSE
REPLICATION_IP_ALLOW(main) Allow connections from this IP0.0.0.0/0
REPLICATION_MODEReplication Mode main,secondary,snapshotmain
REPLICATION_USER(main/secondary/snapshot) Replication Userreplicatex
REPLICATION_HOST(secondary/snapshot) Hostname of Replication Main serverx
REPLICATION_PASS(main/secondary/snapshot) Password of Replication Userx
REPLICATION_PORT(secondary/snapshot) Port number of Replication Main server5432x
REPLICATION_TLS_MODEReplication TLS Modeprefer

Monitoring Options

  • Zabbix Monitoring only at this time
ParameterDescriptionDefaultFILE
CONTAINER_ENABLE_MONITORINGEnable Zabbix Agent 2 MonitoringTRUE
MONITOR_USERMonitoring Userzbx_monitorx
MONITOR_PASSMonitoring Passwordzabbixx

Users and Groups

TypeNameID
Userpostgres70
Grouppostgres70

Networking

PortProtocolDescription
5432tcpPostgres Server

Maintenance

Shell Access

For debugging and maintenance, bash and sh are available in the container.

Support & Maintenance

  • For community help, tips, and community discussions, visit the Discussions board.
  • For personalized support or a support agreement, see Nfrastack Support.
  • To report bugs, submit a Bug Report. Usage questions will be closed as not-a-bug.
  • Feature requests are welcome, but not guaranteed. For prioritized development, consider a support agreement.
  • Updates are best-effort, with priority given to active production use and support agreements.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Containerized relational database with multiple databases/users, replication, and monitoring support

Resources

Stars

14 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages