Overview

Overview of PostgreSQL in Pigsty

Concept

Overview of PostgreSQL in Pigsty

Configuration

Describe the cluster you want

  • Identity: Parameters used for describing a PostgreSQL cluster
  • Primary: Define a single instance cluster
  • Replica: Define a basic HA cluster with one primary & one replica
  • Offline: Define a dedicated instance for OLAP/ETL/Interactive queries.
  • Sync Standby: Enable synchronous commit to ensure no data loss
  • Quorum Commit: Use quorum sync commit for an even higher consistency level
  • Standby Cluster: Clone an existing cluster and follow it
  • Delayed Cluster: Clone an existing cluster for emergency data recovery
  • Citus Cluster: Define a Citus distributed database cluster

Playbooks

Materialize the cluster you described

  • pgsql.yml : Init HA PostgreSQL clusters or adding new replicas.
  • pgsql-rm.yml : Remove PostgreSQL cluster, or remove replicas
  • pgsql-user.yml : Add new business user to existing PostgreSQL cluster
  • pgsql-db.yml : Add new business database to existing PostgreSQL cluster
  • pgsql-monitor.yml : Monitor remote postgres instance with local exporters
  • pgsql-migration.yml : Generate Migration manual & scripts for existing PostgreSQL

Dashboards

There are 23 default grafana dashboards about PostgreSQL and categorized into 4 levels, check PGSQL Monitor for details.

OverviewClusterInstanceDatabase
PGSQL OverviewPGSQL ClusterPGSQL InstancePGSQL Database
PGSQL AlertPGSQL Cluster-remotePGCAT InstancePGCAT Database
PGSQL ShardPGSQL ActivityPGSQL PersistPGSQL Tables
PGSQL ReplicationPGSQL ProxyPGSQL Table
PGSQL ServicePGSQL QueriesPGCAT Table
PGSQL DatabasesPGSQL SessionPGSQL Query
PGSQL XactsPGCAT Query

Administration

Admin your existing clusters

Parameters

API Reference for PGSQL module:

  • PG_ID : Calculate & Check Postgres Identity
  • PG_BUSINESS : Postgres Business Object Definition
  • PG_INSTALL : Install PGSQL Packages & Extensions
  • PG_BOOTSTRAP : Init a HA Postgres Cluster with Patroni
  • PG_PROVISION : Create users, databases, and in-database objects
  • PG_BACKUP : Setup backup repo with pgbackrest
  • PG_SERVICE : Exposing pg service, bind vip and register DNS
  • PG_EXPORTER : Add Monitor for PGSQL Instance

Parameters

ParameterSectionTypeLevelComment
pg_modePG_IDenumCpgsql cluster mode: pgsql,citus,gpsql
pg_clusterPG_IDstringCpgsql cluster name, REQUIRED identity parameter
pg_seqPG_IDintIpgsql instance seq number, REQUIRED identity parameter
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 addr 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 to true to enable offline query on this instance
pg_usersPG_BUSINESSuser[]Cpostgres business users
pg_databasesPG_BUSINESSdatabase[]Cpostgres business databases
pg_servicesPG_BUSINESSservice[]Cpostgres business services
pg_hba_rulesPG_BUSINESShba[]Cbusiness hba rules for postgres
pgb_hba_rulesPG_BUSINESShba[]Cbusiness 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 directory, /var/lib/pgsql by default
pg_dbsu_ssh_exchangePG_INSTALLboolCexchange postgres dbsu ssh key among same pgsql cluster
pg_versionPG_INSTALLenumCpostgres major version to be installed, 15 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 packages to be installed, ${pg_version} will be replaced
pg_extensionsPG_INSTALLstring[]Cpg extensions to be installed, ${pg_version} will be replaced
pg_safeguardPG_BOOTSTRAPboolG/C/Aprevent purging running postgres instance? false by default
pg_cleanPG_BOOTSTRAPboolG/C/Apurging existing postgres during pgsql init? true by default
pg_dataPG_BOOTSTRAPpathCpostgres data directory, /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_BOOTSTRAPipCpostgres listen address, 0.0.0.0 (all ipv4 addr) by default
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 communications 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_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 memory ratio, 0.25 by default, 0.1~0.4
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 libraries, 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_BOOTSTRAPenumCpasswords encryption algorithm: md5,scram-sha-256
pg_encodingPG_BOOTSTRAPenumCdatabase cluster encoding, UTF8 by default
pg_localePG_BOOTSTRAPenumCdatabase cluster local, C by default
pg_lc_collatePG_BOOTSTRAPenumCdatabase cluster collate, C by default
pg_lc_ctypePG_BOOTSTRAPenumCdatabase character type, en_US.UTF8 by default
pgbouncer_enabledPG_BOOTSTRAPboolCif disabled, pgbouncer will not be launched on pgsql host
pgbouncer_portPG_BOOTSTRAPportCpgbouncer listen port, 6432 by default
pgbouncer_log_dirPG_BOOTSTRAPpathCpgbouncer log dir, /pg/log/pgbouncer by default
pgbouncer_auth_queryPG_BOOTSTRAPboolCquery postgres to retrieve unlisted business users?
pgbouncer_poolmodePG_BOOTSTRAPenumCpooling mode: transaction,session,statement, transaction by default
pgbouncer_sslmodePG_BOOTSTRAPenumCpgbouncer client ssl mode, disable by default
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 authentication rules
pgb_default_hba_rulesPG_PROVISIONhba[]G/Cpgbouncer default host-based authentication 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_repoPG_BACKUPdictG/Cpgbackrest repo: https://pgbackrest.org/configuration.html#section-repository
pg_weightPG_SERVICEintIrelative load balance weight in service, 100 by default, 0-255
pg_service_providerPG_SERVICEenumG/Cdedicate haproxy node group name, or empty string for local nodes by default
pg_default_service_destPG_SERVICEenumG/Cdefault service destination if svc.dest=‘default’
pg_default_servicesPG_SERVICEservice[]G/Cpostgres default service definitions
pg_vip_enabledPG_SERVICEboolCenable a l2 vip for pgsql primary? false by default
pg_vip_addressPG_SERVICEcidr4Cvip address in <ipv4>/<mask> format, require if vip is enabled
pg_vip_interfacePG_SERVICEstringC/Ivip network interface to listen, eth0 by default
pg_dns_suffixPG_SERVICEstringCpgsql dns suffix, ’’ by default
pg_dns_targetPG_SERVICEenumCauto, primary, vip, none, or ad hoc ip
pg_exporter_enabledPG_EXPORTERboolCenable pg_exporter on pgsql hosts?
pg_exporter_configPG_EXPORTERstringCpg_exporter configuration file name
pg_exporter_cache_ttlsPG_EXPORTERstringCpg_exporter collector ttl stage in seconds, ‘1,10,60,300’ by default
pg_exporter_portPG_EXPORTERportCpg_exporter listen port, 9630 by default
pg_exporter_paramsPG_EXPORTERstringCextra url parameters for pg_exporter dsn
pg_exporter_urlPG_EXPORTERpgurlCoverwrite auto-generate pg dsn if specified
pg_exporter_auto_discoveryPG_EXPORTERboolCenable auto database discovery? enabled by default
pg_exporter_exclude_databasePG_EXPORTERstringCcsv of database that WILL NOT be monitored during auto-discovery
pg_exporter_include_databasePG_EXPORTERstringCcsv of database that WILL BE monitored during auto-discovery
pg_exporter_connect_timeoutPG_EXPORTERintCpg_exporter connect timeout in ms, 200 by default
pg_exporter_optionsPG_EXPORTERargCoverwrite extra options for pg_exporter
pgbouncer_exporter_enabledPG_EXPORTERboolCenable pgbouncer_exporter on pgsql hosts?
pgbouncer_exporter_portPG_EXPORTERportCpgbouncer_exporter listen port, 9631 by default
pgbouncer_exporter_urlPG_EXPORTERpgurlCoverwrite auto-generate pgbouncer dsn if specified
pgbouncer_exporter_optionsPG_EXPORTERargCoverwrite extra options for pgbouncer_exporter

Tutorials

  • Fork an existing PostgreSQL cluster.
  • Create a standby cluster of an existing PostgreSQL cluster.
  • Create a delayed cluster of another pgsql cluster?
  • Monitoring an existing postgres instance?
  • Migration from an external PostgreSQL with logical replication?
  • Use MinIO as a central pgBackRest repo.
  • Use dedicate etcd cluster for DCS?
  • Use dedicated haproxy for exposing PostgreSQL service.
  • Deploy a multi-node MinIO cluster?
  • Use CMDB instead of Config as inventory.
  • Use PostgreSQL as grafana backend storage ?
  • Use PostgreSQL as prometheus backend storage ?

Last modified 2023-02-27: refresh en docs to v2.0 (e82b371)