Module: PGSQL

Deploy and manage world’s most advanced open-source relational database — PostgreSQL, customizable and production-ready!

The world’s most advanced open-source relational database!

Pigsty brings it to full potential: batteries-included, reliable, observable, maintainable, and scalable! Config | Admin | Playbooks | Dashboards | Parameters


Overview

Learn key topics and concepts about PostgreSQL.


Config

Describe your desired PostgreSQL cluster


Admin

Manage your PostgreSQL clusters.


Playbooks

Use idempotent playbooks to materialize your config.

Example: Install PGSQL Module

asciicast

Example: Remove PGSQL Module

asciicast


Monitoring

Check PostgreSQL status via Grafana dashboards.

Pigsty has 26 PostgreSQL-related dashboards:

OverviewClusterInstanceDatabase
PGSQL OverviewPGSQL ClusterPGSQL InstancePGSQL Database
PGSQL AlertPGRDS ClusterPGRDS InstancePGCAT Database
PGSQL ShardPGSQL ActivityPGCAT InstancePGSQL Tables
PGSQL ReplicationPGSQL PersistPGSQL Table
PGSQL ServicePGSQL ProxyPGCAT Table
PGSQL DatabasesPGSQL PgbouncerPGSQL Query
PGSQL PatroniPGSQL SessionPGCAT Query
PGSQL PITRPGSQL XactsPGCAT Locks
PGSQL ExporterPGCAT Schema

Parameters

Config params for the PGSQL module

  • PG_ID: Calculate & validate PostgreSQL instance identity
  • PG_BUSINESS: PostgreSQL biz object definitions
  • PG_INSTALL: Install PostgreSQL kernel, pkgs & extensions
  • PG_BOOTSTRAP: Init HA PostgreSQL cluster with Patroni
  • PG_PROVISION: Create PostgreSQL users, databases & in-db objects
  • PG_BACKUP: Setup backup repo with pgbackrest
  • PG_ACCESS: Expose PostgreSQL services, bindVIP (optional), register DNS
  • PG_MONITOR: Add monitoring for PostgreSQL instance and register to infra
  • PG_REMOVE: Remove PostgreSQL cluster, instance and related resources
Full Parameter List
ParameterSectionTypeLevelDescription
pg_modePG_IDenumCpgsql cluster mode: pgsql,citus,gpsql
pg_clusterPG_IDstringCpgsql cluster name, REQUIRED identity param
pg_seqPG_IDintIpgsql instance seq number, REQUIRED identity param
pg_rolePG_IDenumIpgsql role, REQUIRED, could be primary,replica,offline
pg_instancesPG_IDdictIdefine multiple pg instances on node in {port:ins_vars} format
pg_upstreamPG_IDipIrepl upstream ip for standby cluster or cascade replica
pg_shardPG_IDstringCpgsql shard name, optional identity for sharding clusters
pg_groupPG_IDintCpgsql shard index number, optional identity for sharding clusters
gp_rolePG_IDenumCgreenplum role of this cluster, could be master or segment
pg_exportersPG_IDdictCadditional pg_exporters to monitor remote postgres instances
pg_offline_queryPG_IDboolIset true to enable offline query on this instance
pg_usersPG_BUSINESSuser[]Cpostgres biz users
pg_databasesPG_BUSINESSdatabase[]Cpostgres biz databases
pg_servicesPG_BUSINESSservice[]Cpostgres biz services
pg_hba_rulesPG_BUSINESShba[]Cbiz hba rules for postgres
pgb_hba_rulesPG_BUSINESShba[]Cbiz hba rules for pgbouncer
pg_replication_usernamePG_BUSINESSusernameGpostgres replication username, replicator by default
pg_replication_passwordPG_BUSINESSpasswordGpostgres replication password, DBUser.Replicator by default
pg_admin_usernamePG_BUSINESSusernameGpostgres admin username, dbuser_dba by default
pg_admin_passwordPG_BUSINESSpasswordGpostgres admin password in plain text, DBUser.DBA by default
pg_monitor_usernamePG_BUSINESSusernameGpostgres monitor username, dbuser_monitor by default
pg_monitor_passwordPG_BUSINESSpasswordGpostgres monitor password, DBUser.Monitor by default
pg_dbsu_passwordPG_BUSINESSpasswordG/Cdbsu password, empty string means no dbsu password by default
pg_dbsuPG_INSTALLusernameCos dbsu name, postgres by default, better not change it
pg_dbsu_uidPG_INSTALLintCos dbsu uid and gid, 26 for default postgres users and groups
pg_dbsu_sudoPG_INSTALLenumCdbsu sudo privilege, none,limit,all,nopass. limit by default
pg_dbsu_homePG_INSTALLpathCpostgresql home dir, /var/lib/pgsql by default
pg_dbsu_ssh_exchangePG_INSTALLboolCexchange postgres dbsu ssh key among same pgsql cluster
pg_versionPG_INSTALLenumCpostgres major version to install, 18 by default
pg_bin_dirPG_INSTALLpathCpostgres binary dir, /usr/pgsql/bin by default
pg_log_dirPG_INSTALLpathCpostgres log dir, /pg/log/postgres by default
pg_packagesPG_INSTALLstring[]Cpg pkgs to install, ${pg_version} will be replaced
pg_extensionsPG_INSTALLstring[]Cpg extensions to install, ${pg_version} will be replaced
pg_cleanPG_BOOTSTRAPboolG/C/Apurge existing postgres during pgsql init? true by default
pg_dataPG_BOOTSTRAPpathCpostgres data dir, /pg/data by default
pg_fs_mainPG_BOOTSTRAPpathCmountpoint/path for postgres main data, /data by default
pg_fs_bkupPG_BOOTSTRAPpathCmountpoint/path for pg backup data, /data/backup by default
pg_storage_typePG_BOOTSTRAPenumCstorage type for pg main data, SSD,HDD, SSD by default
pg_dummy_filesizePG_BOOTSTRAPsizeCsize of /pg/dummy, hold 64MB disk space for emergency use
pg_listenPG_BOOTSTRAPip(s)C/Ipostgres/pgbouncer listen addr, comma separated list
pg_portPG_BOOTSTRAPportCpostgres listen port, 5432 by default
pg_localhostPG_BOOTSTRAPpathCpostgres unix socket dir for localhost connection
pg_namespacePG_BOOTSTRAPpathCtop level key namespace in etcd, used by patroni & vip
patroni_enabledPG_BOOTSTRAPboolCif disabled, no postgres cluster will be created during init
patroni_modePG_BOOTSTRAPenumCpatroni working mode: default,pause,remove
patroni_portPG_BOOTSTRAPportCpatroni listen port, 8008 by default
patroni_log_dirPG_BOOTSTRAPpathCpatroni log dir, /pg/log/patroni by default
patroni_ssl_enabledPG_BOOTSTRAPboolGsecure patroni RestAPI comms with SSL?
patroni_watchdog_modePG_BOOTSTRAPenumCpatroni watchdog mode: automatic,required,off. off by default
patroni_usernamePG_BOOTSTRAPusernameCpatroni restapi username, postgres by default
patroni_passwordPG_BOOTSTRAPpasswordCpatroni restapi password, Patroni.API by default
pg_etcd_passwordPG_BOOTSTRAPpasswordCetcd password for this pg cluster, empty to use pg_cluster
pg_primary_dbPG_BOOTSTRAPstringCprimary database in this cluster, optional, postgres by default
pg_parametersPG_BOOTSTRAPdictCextra params in postgresql.auto.conf
pg_filesPG_BOOTSTRAPpath[]Cextra files to copy to postgres data dir
pg_confPG_BOOTSTRAPenumCconfig template: oltp,olap,crit,tiny. oltp.yml by default
pg_max_connPG_BOOTSTRAPintCpostgres max connections, auto will use recommended value
pg_shared_buffer_ratioPG_BOOTSTRAPfloatCpostgres shared buffer mem ratio, 0.25 by default, 0.1~0.4
pg_io_methodPG_BOOTSTRAPenumCio method for postgres: auto,sync,worker,io_uring, worker by default
pg_rtoPG_BOOTSTRAPintCrecovery time objective in seconds, 30s by default
pg_rpoPG_BOOTSTRAPintCrecovery point objective in bytes, 1MiB at most by default
pg_libsPG_BOOTSTRAPstringCpreloaded libs, timescaledb,pg_stat_statements,auto_explain by default
pg_delayPG_BOOTSTRAPintervalIreplication apply delay for standby cluster leader
pg_checksumPG_BOOTSTRAPboolCenable data checksum for postgres cluster?
pg_pwd_encPG_BOOTSTRAPenumCpassword encryption algo: md5,scram-sha-256
pg_encodingPG_BOOTSTRAPenumCdatabase cluster encoding, UTF8 by default
pg_localePG_BOOTSTRAPenumCdatabase cluster locale, C by default
pg_lc_collatePG_BOOTSTRAPenumCdatabase cluster collate, C by default
pg_lc_ctypePG_BOOTSTRAPenumCdatabase char type, C by default
pgsodium_keyPG_BOOTSTRAPstringCpgsodium key, 64 hex digit, default to sha256(pg_cluster)
pgsodium_getkey_scriptPG_BOOTSTRAPpathCpgsodium getkey script path
pgbouncer_enabledPG_ACCESSboolCif disabled, pgbouncer will not be launched on pgsql host
pgbouncer_portPG_ACCESSportCpgbouncer listen port, 6432 by default
pgbouncer_log_dirPG_ACCESSpathCpgbouncer log dir, /pg/log/pgbouncer by default
pgbouncer_auth_queryPG_ACCESSboolCquery postgres to retrieve unlisted biz users?
pgbouncer_poolmodePG_ACCESSenumCpooling mode: transaction,session,statement, transaction by default
pgbouncer_sslmodePG_ACCESSenumCpgbouncer client ssl mode, disable by default
pgbouncer_ignore_paramPG_ACCESSstring[]Cpgbouncer ignore_startup_parameters list
pg_provisionPG_PROVISIONboolCprovision postgres cluster after bootstrap
pg_initPG_PROVISIONstringG/Cprovision init script for cluster template, pg-init by default
pg_default_rolesPG_PROVISIONrole[]G/Cdefault roles and users in postgres cluster
pg_default_privilegesPG_PROVISIONstring[]G/Cdefault privileges when created by admin user
pg_default_schemasPG_PROVISIONstring[]G/Cdefault schemas to be created
pg_default_extensionsPG_PROVISIONextension[]G/Cdefault extensions to be created
pg_reloadPG_PROVISIONboolAreload postgres after hba changes
pg_default_hba_rulesPG_PROVISIONhba[]G/Cpostgres default host-based auth rules
pgb_default_hba_rulesPG_PROVISIONhba[]G/Cpgbouncer default host-based auth rules
pgbackrest_enabledPG_BACKUPboolCenable pgbackrest on pgsql host?
pgbackrest_cleanPG_BACKUPboolCremove pg backup data during init?
pgbackrest_log_dirPG_BACKUPpathCpgbackrest log dir, /pg/log/pgbackrest by default
pgbackrest_methodPG_BACKUPenumCpgbackrest repo method: local,minio,etc…
pgbackrest_init_backupPG_BACKUPboolCtake a full backup after pgbackrest init?
pgbackrest_repoPG_BACKUPdictG/Cpgbackrest repo: https://pgbackrest.org/configuration.html#section-repository
pg_weightPG_ACCESSintIrelative load balance weight in service, 100 by default, 0-255
pg_service_providerPG_ACCESSenumG/Cdedicated haproxy node group name, or empty string for local nodes by default
pg_default_service_destPG_ACCESSenumG/Cdefault service dest if svc.dest=‘default’
pg_default_servicesPG_ACCESSservice[]G/Cpostgres default service definitions
pg_vip_enabledPG_ACCESSboolCenable L2 VIP for pgsql primary? false by default
pg_vip_addressPG_ACCESScidr4Cvip addr in <ipv4>/<mask> format, required if vip is enabled
pg_vip_interfacePG_ACCESSstringC/Ivip network interface to listen, eth0 by default
pg_dns_suffixPG_ACCESSstringCpgsql dns suffix, ’’ by default
pg_dns_targetPG_ACCESSenumCauto, primary, vip, none, or ad hoc ip
pg_exporter_enabledPG_MONITORboolCenable pg_exporter on pgsql hosts?
pg_exporter_configPG_MONITORstringCpg_exporter config file name
pg_exporter_cache_ttlsPG_MONITORstringCpg_exporter collector ttl stage in seconds, ‘1,10,60,300’ by default
pg_exporter_portPG_MONITORportCpg_exporter listen port, 9630 by default
pg_exporter_paramsPG_MONITORstringCextra url params for pg_exporter dsn
pg_exporter_urlPG_MONITORpgurlCoverwrite auto-gen pg dsn if specified
pg_exporter_auto_discoveryPG_MONITORboolCenable auto database discovery? enabled by default
pg_exporter_exclude_databasePG_MONITORstringCcsv of database that WILL NOT be monitored during auto-discovery
pg_exporter_include_databasePG_MONITORstringCcsv of database that WILL BE monitored during auto-discovery
pg_exporter_connect_timeoutPG_MONITORintCpg_exporter connect timeout in ms, 200 by default
pg_exporter_optionsPG_MONITORargCoverwrite extra options for pg_exporter
pgbouncer_exporter_enabledPG_MONITORboolCenable pgbouncer_exporter on pgsql hosts?
pgbouncer_exporter_portPG_MONITORportCpgbouncer_exporter listen port, 9631 by default
pgbouncer_exporter_urlPG_MONITORpgurlCoverwrite auto-gen pgbouncer dsn if specified
pgbouncer_exporter_optionsPG_MONITORargCoverwrite extra options for pgbouncer_exporter
pgbackrest_exporter_enabledPG_MONITORboolCenable pgbackrest_exporter on pgsql hosts?
pgbackrest_exporter_portPG_MONITORportCpgbackrest_exporter listen port, 9854 by default
pgbackrest_exporter_optionsPG_MONITORargCoverwrite extra options for pgbackrest_exporter
pg_safeguardPG_REMOVEboolG/C/Aprevent purging running postgres instance? false by default
pg_rm_dataPG_REMOVEboolG/C/Aremove postgres data during remove? true by default
pg_rm_backupPG_REMOVEboolG/C/Aremove pgbackrest backup during primary remove? true by default
pg_rm_pkgPG_REMOVEboolG/C/Auninstall postgres pkgs during remove? true by default

Tutorials

Tutorials for using/managing PostgreSQL in Pigsty.

  • Clone an existing PostgreSQL cluster
  • Create an online standby cluster of existing PostgreSQL cluster
  • Create a delayed standby cluster of existing PostgreSQL cluster
  • Monitor an existing postgres instance
  • Migrate from external PostgreSQL to Pigsty-managed PostgreSQL using logical replication
  • Use MinIO as centralized pgBackRest backup repo
  • Use dedicated etcd cluster as PostgreSQL / Patroni DCS
  • Use dedicated haproxy load balancer cluster to expose PostgreSQL services
  • Use pg-meta CMDB instead of pigsty.yml as inventory source
  • Use PostgreSQL as Grafana backend storage
  • Use PostgreSQL as Prometheus backend storage

Architecture

Introduction to the overall architecture and implementation details of PostgreSQL clusters.

Configuration

Choose the appropriate instance and cluster types based on your requirements to configure PostgreSQL database clusters that meet your needs.

Service/Access

Split read and write operations, route traffic correctly, and reliably deliver PostgreSQL cluster capabilities.

Access Control

Default role system and privilege model provided by Pigsty

Administration

Standard Operating Procedures (SOP) for database administration tasks

Backup & Restore

Point-in-Time Recovery (PITR) Backup and Restore

Data Migration

How to migrate an existing PostgreSQL cluster to a new Pigsty-managed PostgreSQL cluster with minimal downtime?

Tutorials

Step-by-step guides for common PostgreSQL tasks and scenarios.

Monitoring

Overview of Pigsty’s monitoring system architecture and how to monitor existing PostgreSQL instances

Parameters

Customize PostgreSQL clusters with 120 parameters in the PGSQL module

Playbook

How to manage PostgreSQL clusters with Ansible playbooks

Extensions

Harness the synergistic power of PostgreSQL extensions

Kernel Forks

How to use other PostgreSQL kernel forks in Pigsty? Such as Citus, Babelfish, IvorySQL, PolarDB, etc.

FAQ

Frequently asked questions about PostgreSQL

Misc

Miscellaneous Topics


Last Modified 2026-01-09: add supabase asciinema demo (693cfa8)