Learn about Pigsty’s features, architecture, design principles, use cases, and project background.
Features · Core Concepts · Architecture · High Availability · Backup & Recovery
This is the multi-page printable view of this section. .
The Pigsty v5.0 documentation focuses on Pigsty itself: architecture, installation, deployment, configuration, operations, and the complete manual for every first-party module.
v5.0 Docs Preview OINK 1.0.0 Local First
Press ⌘ with K on macOS, or Ctrl with K, to open offline search and the command palette anywhere on the site.
Learn about Pigsty’s features, architecture, design principles, use cases, and project background.
Features · Core Concepts · Architecture · High Availability · Backup & Recovery
Start with a fresh Linux host, configure Pigsty, and complete your first deployment.
Install · Configure · Run Playbooks · Offline Install · Web UI
Plan capacity, prepare resources, harden security, and deliver a multi-node production environment.
Planning · Preparation · Install · Security · Sandbox
Look up configuration templates, modules, parameters, playbooks, ports, and filesystem conventions.
Config Templates · Modules · Parameters · Playbooks · Ports · File Hierarchy
Highly available PostgreSQL clusters, services, backup, monitoring, security, and daily administration.
VictoriaMetrics, VictoriaLogs, Grafana, Nginx, and infrastructure services.
Host management, software baselines, log collection, VIP, and HAProxy load balancing.
Reliable distributed configuration storage for PostgreSQL high availability.
S3-compatible object storage and a PostgreSQL backup repository.
Primary-replica, Sentinel, and native cluster modes.
JuiceFS backed by PostgreSQL metadata and object storage.
Dynamic KRaft, TLS, ACL, and complete observability.
MySQL 8.4 LTS and InnoDB Cluster.
A managed Docker service and container runtime.
Code-Server, Jupyter, and an AI coding sandbox.
This site does not duplicate the standalone manuals for Pig, Patroni, pg_exporter, pgBackRest, PgBouncer, the software repository, application templates, or pilot projects. When these components must be referenced, the documentation links to the existing site; Pigsty’s own integration, configuration, and operational guidance remains in the relevant module manual.
Pigsty uses a scalable architecture design, suitable for both large-scale production environments and single-node development/demo environments. This guide focuses on the latter.
If you intend to learn about Pigsty, you can start with the Quick Start single-node deployment. A Linux virtual machine with 1C/2G is sufficient to run Pigsty.
You can use a Linux MiniPC, free/discounted virtual machines provided by cloud providers, Windows WSL, or create a virtual machine on your own laptop for Pigsty deployment. Pigsty provides out-of-the-box Vagrant templates and OpenTofu templates to help you provision Linux VMs with one click locally or in the cloud.
The single-node version of Pigsty includes all core features: 575 PG extensions, self-contained Grafana/Victoria monitoring, IaC provisioning capabilities, and local PITR point-in-time recovery. If you have external object storage (for PostgreSQL PITR backup), then for scenarios like demos, personal websites, and small services, even a single-node environment can provide a certain degree of data persistence guarantee. However, single-node cannot achieve High Availability—automatic failover requires at least 3 nodes.
If you want to install Pigsty in an environment without internet connection, please refer to the Offline Install mode. If you only need the PostgreSQL database itself, please refer to the Slim Install mode. If you are ready to start serious multi-node production deployment, please refer to the Deployment Guide.
Prepare a node with compatible Linux system, and execute as an admin user with passwordless ssh and sudo privileges:
Yes, it’s that simple. You can use pre-configured templates to bring up Pigsty with one click without understanding any details.
Next, you can explore the Graphical User Interface, access PostgreSQL database services; or perform configuration customization and execute playbooks to deploy more clusters.
This is the Pigsty single-node install guide Single Node. For multi-node HA production deployment, refer to the Deployment docs.
Pigsty single-node installation consists of three steps: Install, Configure, and Deploy.
Prepare a node with compatible OS, and run as an admin user with nopass ssh and sudo:
Choose a Pigsty download mirror:
This command runs the install script, downloads and extracts Pigsty source to your home directory and installs dependencies. Then complete Configure and Deploy:
Skip this step if you already have a prepared pigsty.yml.
After installation, access the Web UI via IP/domain + port 80/443 through Nginx,
and access the default PostgreSQL service via port 5432.
The complete process takes 3–10 minutes depending on server specs/network. Offline installation speeds this up significantly; for monitoring-free setups, use Slim Install for even faster deployment.
Video Example: Online Single-Node Installation (Debian 13, x86_64)
demo/install-hero.cast — /demo/install-hero.cast
Installing Pigsty involves some preparation work. Here’s a checklist.
For single-node installations, many constraints can be relaxed—typically you only need to know your IP address. If you don’t have a static IP, use 127.0.0.1.
| Item | Requirement | Item | Requirement |
|---|---|---|---|
| Node | 1-node, at least 1C2G, no upper limit |
Disk | /data mount point, xfs recommended |
| OS | Linux x86_64 / aarch64, EL/Debian/Ubuntu |
Network | Static IPv4; single-node without fixed IP can use 127.0.0.1 |
| SSH | nopass SSH login via public key |
SUDO | sudo privilege, preferably with nopass option |
Typically, you only need to focus on your local IP address—as an exception, for single-node deployment, use 127.0.0.1 if no static IP available.
Use the following commands to auto-install Pigsty source to ~/pigsty (recommended). Deployment dependencies (Ansible) are installed automatically.
Choose a Pigsty download mirror:
If you prefer not to run a remote script, you can manually download or clone the source. When using git, always checkout a specific version before use.
For manual download/clone installations, run the bootstrap script to install Ansible and other dependencies. You can also install them yourself.
In Pigsty, deployment blueprints are defined by the inventory, the pigsty.yml configuration file. You can customize through declarative configuration.
Pigsty provides the configure script as an optional configuration wizard,
which generates an inventory with good defaults based on your environment and input:
The generated config file is at ~/pigsty/pigsty.yml by default. Review and customize as needed before installation.
Many configuration templates are available for reference. You can skip the wizard and directly edit pigsty.yml:
The output below is from the current main branch (v5.0.0-preview). If you install another version, the first line reports that version.
Common configure Arguments
-i | --ip
,
The primary private IP of the current host, used to replace the 10.10.10.10 placeholder in the inventory.
-c | --conf
,
A configuration template name relative to conf/, without the .yml suffix.
-v | --version
,
PostgreSQL major version 14 through 19; PG19 is Beta, so use the dedicated pg19 template.
-r | --region
,
,
Upstream repository region for faster downloads: default, china, or europe.
-n | --non-interactive
,
,
Use command-line arguments for the primary IP and skip the interactive wizard.
-x | --proxy
,
,
Use current environment variables to configure proxy_env.
If your machine has multiple IPs bound, use -i|--ip <ipaddr> to explicitly specify the primary IP, or provide it in the interactive prompt.
The script replaces the placeholder 10.10.10.10 with your node’s primary IPv4 address. Choose a static IP; do not use public IPs.
We strongly recommend modifying default passwords and credentials in the config file before installation. See Security Recommendations for details.
Pigsty’s deploy.yml playbook applies the blueprint from Configure to target nodes.
When you see pgsql init done, PLAY RECAP and similar output at the end, installation is complete!
Upstream repos used by Pigsty (like Linux/PGDG repos) can sometimes enter a broken state due to improper updates, causing deployment failures (this has happened multiple times)! You can wait for upstream fixes or use pre-made offline packages to solve this.
Warning: Running deploy.yml again on an existing deployment may restart services and overwrite configurations!
After single-node installation, you typically have four modules installed on the current node:
PGSQL, INFRA, NODE, and ETCD.
The INFRA module provides a graphical management interface, accessible via Nginx on ports 80/443.
The PGSQL module provides a PostgreSQL database server, listening on 5432, also accessible via Pgbouncer/HAProxy proxies.
Use the current node as a base to deploy and monitor more clusters: add cluster definitions to the inventory and run:
Most modules require the NODE module installed first. See available modules for details:
Pigsty is designed for native Linux, but can also run in Linux containers with systemd. If you don’t have native Linux (e.g., macOS or Windows), use Docker to spin up a local single-node Pigsty for testing.
Enter the docker/ dir in Pigsty source and launch with one command:
After deployment, access services:
| Service | URL / Command | Credentials |
|---|---|---|
| SSH | ssh root@localhost -p 2222 |
Password: pigsty |
| Web Portal | http://localhost:8080 | - |
| Grafana | http://localhost:8080/ui | admin / grafana_admin_password |
| PostgreSQL | psql 'postgres://dbuser_dba:<pg_admin_password>@localhost:5432/postgres' |
pg_admin_password |
make launch runs ./configure -g internally to generate random passwords. You can check them with:
Web Portal and PostgreSQL are only available after Deployment (./deploy.yml) completes.
Docker deployment requires:
| Item | Requirement | Item | Requirement |
|---|---|---|---|
| Docker | Docker 20.10+ (Desktop or CE) | CPU | At least 1 core |
| RAM | At least 2GB | Disk | At least 20GB free |
Ensure default host ports (2222/8080/8443/5432) are available, or edit .env first.
Pigsty provides an out-of-the-box Docker image on Docker Hub.
| Image | Pull | Size | Contents |
|---|---|---|---|
pgsty/pigsty |
~500MB | 1.3GB | Debian 13 + systemd + SSH + pig + Ansible |
main branch and the site baseline both use v5.0.0-preview; verify that the matching remote image exists before pulling or deploying../deploy.ymlBuilt on Debian 13 (Trixie), pre-installed with pig CLI and Ansible, Pigsty source already initialized.
Pigsty provides out-of-the-box Docker support in the docker/ source directory.
Simplest way is make launch, which auto-completes: start container, generate config, and deploy:
Or step by step for inspection at each stage:
To build locally instead of pulling from Docker Hub:
Customize image version and port mappings via .env:
Port Mapping:
| Env Var | Default | Container | Description |
|---|---|---|---|
PIGSTY_VERSION |
v4.5.0 |
- | Current main source default; verify the remote tag separately |
PIGSTY_SSH_PORT |
2222 |
22 | SSH access port |
PIGSTY_HTTP_PORT |
8080 |
80 | Nginx HTTP port |
PIGSTY_HTTPS_PORT |
8443 |
443 | Nginx HTTPS port |
PIGSTY_PG_PORT |
5432 |
5432 | PostgreSQL port |
Override via env vars if defaults are occupied:
Pigsty Docker provides Makefile commands for container and image management.
Recommended way to run:
The current Makefile no longer provides a countdown prompt. After removing the container, make purge runs rm -rf -- ./data directly. Verify the current directory and target data first, and back it up when necessary.
If you prefer docker run over Docker Compose:
Or use Makefile’s make run:
Pigsty Docker image is based on Debian 13 (Trixie) with systemd as init.
Service management inside container stays consistent with native Linux via systemctl.
Key features:
pigsty--privileged for systemd/data volume mountImage build executes these init steps:
Running ./configure with -c docker applies the Docker-optimized config template:
127.0.0.1 as default IPEnsure Docker is properly installed with sufficient resources. On Docker Desktop, allocate at least 2GB RAM. Check for port conflicts on 2222, 8080, 8443, 5432.
Web Portal and PostgreSQL only available after deployment. Ensure ./deploy.yml finished successfully.
Use make status to check service status.
Override via .env or env vars:
Container data mounted to ./data. To wipe and start fresh:
On macOS with Docker Desktop, performance is worse than native Linux due to virtualization overhead. Expected—Docker deployment is for dev/testing. For production, use native Linux installation.
After single-node installation, you’ll have the INFRA module installed on the current node, which includes an out-of-the-box Nginx web server.
The default server configuration provides a WebUI graphical interface for displaying monitoring dashboards and unified proxy access to other component web interfaces.
You can access this graphical interface by entering the deployment node’s IP address in your browser. By default, Nginx serves on standard ports 80/443.
| Direct IP Access | Domain (HTTP) | Domain (HTTPS) | Demo |
|---|---|---|---|
http://10.10.10.10 |
http://i.pigsty |
https://i.pigsty |
https://demo.pigsty.io |
To access Pigsty’s monitoring system dashboards (Grafana), visit the /ui endpoint on the server.
| Direct IP Access | Domain (HTTP) | Domain (HTTPS) | Demo |
|---|---|---|---|
http://10.10.10.10/ui |
http://i.pigsty/ui |
https://i.pigsty/ui |
https://demo.pigsty.io/ui |
If your service is exposed to Internet or office network, we recommend accessing via domain names and enabling HTTPS encryption—only minimal configuration is needed.
By default, Nginx exposes the following endpoints via different paths on the default server at ports 80/443:
| Endpoint | Component | Native Port | Description | Public Demo |
|---|---|---|---|---|
/ |
Nginx | 80/443 |
Homepage, local repo, file service | demo.pigsty.io |
/ui/ |
Grafana | 3000 |
Grafana dashboard portal | demo.pigsty.io/ui/ |
/vmetrics/ |
VictoriaMetrics | 8428 |
Time series database Web UI | demo.pigsty.io/vmetrics/ |
/vlogs/ |
VictoriaLogs | 9428 |
Log database Web UI | demo.pigsty.io/vlogs/ |
/vtraces/ |
VictoriaTraces | 10428 |
Distributed tracing Web UI | demo.pigsty.io/vtraces/ |
/vmalert/ |
VMAlert | 8880 |
Alert rule management | demo.pigsty.io/vmalert/ |
/alertmgr/ |
AlertManager | 9059 |
Alert management Web UI | demo.pigsty.io/alertmgr/ |
/blackbox/ |
Blackbox | 9115 |
Blackbox exporter | |
/haproxy/* |
HAProxy | 9101 |
Load balancer admin Web UI | |
/pev |
PEV2 | 80 |
PostgreSQL execution plan visualizer | demo.pigsty.io/pev |
/nginx |
Nginx | 80 |
Nginx status page (for metrics) |
If you have your own domain name, you can point it to Pigsty server’s IP address to access various services via domain.
If you want to enable HTTPS, you should modify the home server configuration in the infra_portal parameter:
You can run make cert command after deployment to apply for a free Let’s Encrypt certificate for the domain.
If you don’t define the certbot field, Pigsty will use the local CA to issue a self-signed HTTPS certificate by default.
In this case, you must first trust Pigsty’s self-signed CA to access normally in your browser.
You can also mount local directories and other upstream services to Nginx. For more management details, refer to INFRA Management - Nginx.
PostgreSQL (abbreviated as PG) is the world’s most advanced and popular open-source relational database. Use it to store and retrieve multi-modal data.
This guide is for developers with basic Linux CLI experience but not very familiar with PostgreSQL, helping you quickly get started with PG in Pigsty.
We assume you’re a personal user deploying in the default single-node mode. For prod multi-node HA cluster access, refer to Prod Service Access.
In the default single-node installation template, you’ll create a PostgreSQL database cluster named pg-meta on the current node, with only one primary instance.
PostgreSQL listens on port 5432, and the cluster has a preset database meta available for use.
After installation, exit the current admin user ssh session and re-login to refresh environment variables.
Then simply type pp and press Enter to access the database cluster via the psql CLI tool (p is the shortcut for the pig CLI):
You can also switch to the postgres OS user and execute psql directly to connect to the default postgres admin database.
To access a PostgreSQL database, use a CLI tool or graphical client and fill in the PostgreSQL connection string:
Some drivers and tools may require you to fill in these parameters separately. The following five are typically required:
| Parameter | Description | Example Value | Notes |
|---|---|---|---|
host |
Database server address | 10.10.10.10 |
Replace with your node IP or domain; can omit for localhost |
port |
Port number | 5432 |
PG default port, can be omitted |
username |
Username | dbuser_dba |
Pigsty default database admin |
password |
Password | DBUser.DBA |
Pigsty default admin password (change this!) |
dbname |
Database name | meta |
Default template database name |
For personal use, you can directly use the Pigsty default database superuser dbuser_dba for connection and management. The dbuser_dba has full database privileges.
By default, if you specified the configure -g parameter when configuring Pigsty, the password will be randomly generated and saved in ~/pigsty/pigsty.yml:
Pigsty’s default single-node template presets the following database users, ready to use out of the box:
| Username | Password | Role | Purpose |
|---|---|---|---|
dbuser_dba |
DBUser.DBA |
Superuser | Database admin (change this!) |
dbuser_meta |
DBUser.Meta |
Business admin | App R/W (change this!) |
dbuser_view |
DBUser.Viewer |
Read-only user | Data viewing (change this!) |
For example, you can connect to the meta database in the pg-meta cluster using three different connection strings with three different users:
Note: These default passwords are automatically replaced with random strong passwords when using configure -g. Remember to replace the IP address and password with actual values.
psql is the official PostgreSQL CLI client tool, powerful and the first choice for DBAs and developers.
On a server with Pigsty deployed, you can directly use psql to connect to the local database:
After successful connection, you’ll see a prompt like this:
Common psql Commands
After entering psql, you can execute SQL statements or use meta-commands starting with \:
| Command | Description | Command | Description |
|---|---|---|---|
Ctrl+C |
Interrupt query | Ctrl+D |
Exit psql |
\? |
Show all meta commands | \h |
Show SQL command help |
\l |
List all databases | \c dbname |
Switch to database |
\d table |
View table structure | \d+ table |
View table details |
\du |
List all users/roles | \dx |
List installed extensions |
\dn |
List all schemas | \dt |
List all tables |
Executing SQL
In psql, directly enter SQL statements ending with semicolon ;:
If you prefer graphical interfaces, here are some popular PostgreSQL clients:
Grafana
Pigsty’s INFRA module includes Grafana with a pre-configured PostgreSQL data source (Meta).
You can directly query the database using SQL from the Grafana Explore panel through the browser graphical interface, no additional client tools needed.
Grafana’s default username is admin, and the password can be found in the grafana_admin_password field in the inventory (default pigsty).
DataGrip
DataGrip is a professional database IDE from JetBrains, with powerful features. IntelliJ IDEA’s built-in Database Console can also connect to PostgreSQL in a similar way.
DBeaver
DBeaver is a free open-source universal database tool supporting almost all major databases. It’s a cross-platform desktop client.
pgAdmin
pgAdmin is the official PostgreSQL-specific GUI tool from PGDG, available through browser or as a desktop client.
Pigsty provides a configuration template for one-click pgAdmin service deployment using Docker in Software Template: pgAdmin.
Pigsty provides many PostgreSQL monitoring dashboards, covering everything from cluster overview to single-table analysis.
We recommend starting with PGSQL Overview. Many elements in the dashboards are clickable, allowing you to drill down layer by layer to view details of each cluster, instance, database, and even internal database objects like tables, indexes, and functions.
One of PostgreSQL’s most powerful features is its extension ecosystem. Extensions can add new data types, functions, index methods, and more to the database.
Pigsty provides 575 extensions covering 16 major categories including time-series, geographic, vector, and full-text search, installable with one click.
Start with three commonly used extensions, then install more extensions such as timescaledb as needed.
postgis: Geographic information system for processing maps and location data (installed by default)pgvector: Vector database supporting AI embedding vector similarity search (installed by default)timescaledb: Time-series database for efficient storage and querying of time-series data (optional install)Congratulations on completing the PostgreSQL basics! Next, you can start configuring and customizing your database.
Besides using the configuration wizard to auto-generate configs, you can write Pigsty config files from scratch. This tutorial guides you through building a complex inventory step by step.
If you define NODE, INFRA, ETCD, MINIO, and PGSQL in the inventory upfront, deploy.yml can deploy this core path in one run—but it hides the details. Optional modules such as Docker, Redis, Kafka, native MySQL, JUICE, and VIBE require their own playbooks.
This doc breaks down all modules and playbooks, showing how to incrementally build from a simple config to a complete deployment.
The simplest valid config only defines the admin_ip variable—the IP address of the node where Pigsty is installed (admin node):
This config deploys nothing, but running ./deploy.yml generates a self-signed CA in files/pki/ca for issuing certificates.
For convenience, you can also set region to specify which region’s software mirrors to use (default, china, europe).
Pigsty’s NODE module manages cluster nodes. Any IP address in the inventory will be managed by Pigsty with the NODE module installed.
We added two global parameters:
node_repo_modules specifies repos to add;
region specifies which region’s mirrors to use.
These parameters enable the node to use correct repositories and install required packages. The NODE module offers many customization options: node names, DNS, repos, packages, NTP, kernel params, tuning templates, monitoring, log collection, etc. Even without changes, the defaults are sufficient.
Run deploy.yml or more precisely node.yml to bring the defined node under Pigsty management.
A full-featured RDS cloud database service needs infrastructure support: monitoring (metrics/log collection, alerting, visualization), NTP, DNS, and other foundational services.
Define a special group infra to deploy the INFRA module:
We also assigned an identity parameter: infra_seq to distinguish nodes in multi-node HA INFRA deployments.
Run infra.yml to install INFRA **](/docs/infra/) and [**NODE modules on 10.10.10.10:
demo/infra.cast — /demo/infra.cast
NODE module is implicitly defined as long as an IP exists. NODE is idempotent—re-running has no side effects.
After completion, you’ll have complete observability infrastructure and node monitoring, but PostgreSQL database service is not yet deployed.
If your goal is just to set up this monitoring system (Grafana + Victoria), you’re done! The infra template is designed for this.
Everything in Pigsty is modular: you can deploy only monitoring infra without databases;
or vice versa—run HA PostgreSQL clusters without infra—Slim Install.
To provide PostgreSQL service, install the PGSQL` module and its dependency ETCD—just two lines of config:
We added two new groups: etcd and pg-meta, defining a single-node etcd cluster and a single-node PostgreSQL cluster.
Use ./deploy.yml to converge the defined modules in the core path again, or deploy incrementally:
PGSQL depends on ETCD for HA consensus, so install ETCD first. After completion, you have a working PostgreSQL service!
| ID | NODE | INFRA | ETCD | PGSQL | Description |
|---|---|---|---|---|---|
| 1 | 10.10.10.10 |
infra-1 |
etcd-1 |
pg-meta-1 |
Add etcd and PostgreSQL cluster |
We used node.yml, infra.yml, etcd.yml, and pgsql.yml to deploy all four core modules on a single machine.
In Pigsty, you can customize PostgreSQL cluster internals like databases and users through the inventory:
pg_users: Defines a new user dbuser_meta with password DBUser.Metapg_databases: Defines a new database meta with Pigsty CMDB schema (optional) and vector extensionPigsty offers rich customization parameters covering all aspects of databases and users.
If you define these parameters upfront, they’re automatically created during ./pgsql.yml execution.
For existing clusters, you can incrementally create or modify users and databases:
You can install different major versions of PostgreSQL, and up to 575 extensions. Let’s remove the current default PG 18 and install PG 16:
We can customize parameters to install and enable common extensions by default: timescaledb, postgis, and pgvector:
pg_extensions: Install timescaledb, postgis, pgvector extensions.pg_libs: Configure loading timescaledb, pg_stat_statements, auto_explain dynamic libraries.pg_databases: Create and enable vector, postgis, timescaledb extensions for the meta database.Add more nodes to the deployment, bring them under Pigsty management, deploy monitoring, configure repos, install software…
demo/node.cast — /demo/node.cast
Now deploy a new database cluster pg-test on the three newly added nodes, using a three-node HA architecture:
demo/pgsql.cast — /demo/pgsql.cast
Pigsty provides optional Redis support as a caching service in front of PostgreSQL:
Redis HA requires cluster mode or sentinel mode. See Redis Configuration.
Pigsty’s MINIO module currently deploys Silo S3-compatible object storage, which can serve as a PostgreSQL backup repository. The module, inventory group, and playbooks retain the compatible minio name.
Serious production Silo deployments typically require at least 4 nodes with 4 disks each (4N/16D).
If you want to use containers to run tools for managing PG or software using PostgreSQL, install the DOCKER module:
Use pre-made application templates to launch common software tools with one click, such as the GUI tool for PG management: Pgadmin:
You can even self-host enterprise-grade Supabase with Pigsty, using external HA PostgreSQL clusters as the foundation and running stateless components in containers.
Pigsty uses Ansible to manage clusters, a very popular large-scale/batch/automation ops tool in the SRE community.
Ansible can use declarative approach for server configuration management. All module deployments are implemented through a series of idempotent Ansible playbooks.
For example, in single-node deployment, you’ll use the deploy.yml playbook. Pigsty has more built-in playbooks, you can choose to use as needed.
Understanding Ansible basics helps with better use of Pigsty, but this is not required, especially for single-node deployment.
Pigsty provides a “one-stop” deploy playbook deploy.yml for the core path: CA/software repository, NODE, INFRA, ETCD, PGSQL, and MINIO when enabled in the inventory. Optional modules such as Redis, Kafka, and native MySQL require their own module playbooks even when defined in the inventory.
| Playbook | Command | Group | infra |
[nodes] |
etcd |
minio |
[pgsql] |
|---|---|---|---|---|---|---|---|
infra.yml |
./infra.yml |
-l infra |
✓ | ✓ | |||
node.yml |
./node.yml |
✓ | ✓ | ✓ | ✓ | ||
etcd.yml |
./etcd.yml |
-l etcd |
✓ | ||||
minio.yml |
./minio.yml |
-l minio |
✓ | ||||
pgsql.yml |
./pgsql.yml |
✓ |
This is the simplest deployment method. You can also follow instructions in Customization Guide to incrementally complete deployment of all modules and nodes step by step.
When using the Pigsty installation script or the bootstrap phase of offline installation, Pigsty will automatically install ansible and its dependencies for you.
If you want to manually install Ansible, refer to the following instructions. The minimum supported Ansible version is 2.9.
Please note that EL10 EPEL repo doesn’t yet provide a complete Ansible package. Pigsty PGSQL EL10 repo supplements this.
Ansible is also available on macOS. You can use Homebrew to install Ansible on Mac, and use it as an admin node to manage remote cloud servers. This is convenient for single-node Pigsty deployment on cloud VPS, but not recommended in prod envs.
Ansible playbooks are executable YAML files containing a series of task definitions to execute.
Running playbooks requires the ansible-playbook executable in your environment variable PATH.
Running ./node.yml playbook is essentially executing the ansible-playbook node.yml command.
You can use some parameters to fine-tune playbook execution. The following 4 parameters are essential for effective Ansible use:
| Purpose | Parameter | Description |
|---|---|---|
| Target | -l|--limit <pattern> |
Limit execution to specific groups/hosts/patterns |
| Tasks | -t|--tags <tags> |
Only run tasks with specific tags |
| Params | -e|--extra-vars <vars> |
Extra command-line parameters |
| Config | -i|--inventory <path> |
Use a specific inventory file |
Playbook execution targets can be limited with -l|--limit <selector>.
This is convenient when running playbooks on specific hosts/nodes or groups/clusters.
Here are some host limit examples:
See all details in Ansible documentation: Patterns: targeting hosts and groups
Missing this value can be dangerous—most playbooks execute on all hosts. Use with caution.
Execution tasks can be controlled with -t|--tags <tags>.
If specified, only tasks with the given tags will execute instead of the entire playbook.
To run multiple tasks, specify multiple tags separated by commas -t tag1,tag2:
You can override config parameters at runtime using CLI arguments, which have highest priority.
Extra command-line parameters are passed via -e|--extra-vars KEY=VALUE, usable multiple times:
For complex parameters, use JSON strings to pass multiple complex parameters at once:
The default config file is pigsty.yml in the Pigsty home directory.
You can use -i <path> to specify a different inventory file path.
To permanently change the default config file, modify the inventory parameter in ansible.cfg.
Pigsty provides a series of convenience scripts to simplify common operations. These scripts are in the bin/ directory:
These scripts are simple wrappers around Ansible playbooks, making common operations more convenient.
Below are the built-in playbooks in Pigsty. You can also easily add your own playbooks, or customize and modify playbook implementation logic as needed.
| Module | Playbook | Function |
|---|---|---|
| INFRA | deploy.yml |
One-click deploy Pigsty on current node |
| INFRA | infra.yml |
Initialize Pigsty infrastructure on infra nodes |
| INFRA | infra-rm.yml |
Remove infrastructure components from infra nodes |
| INFRA | cache.yml |
Create offline packages from target node |
| INFRA | cert.yml |
Issue certificates using Pigsty self-signed CA |
| NODE | node.yml |
Initialize node, adjust to desired state |
| NODE | node-rm.yml |
Remove node from Pigsty |
| PGSQL | pgsql.yml |
Initialize HA PostgreSQL cluster or add replica |
| PGSQL | pgsql-rm.yml |
Remove PostgreSQL cluster or replica |
| PGSQL | pgsql-db.yml |
Add new business database to existing cluster |
| PGSQL | pgsql-user.yml |
Add new business user to existing cluster |
| PGSQL | pgsql-pitr.yml |
Perform point-in-time recovery on cluster |
| PGSQL | pgsql-monitor.yml |
Monitor remote PostgreSQL with local exporter |
| PGSQL | pgsql-migration.yml |
Generate migration manual and scripts |
| PGSQL | slim.yml |
Install Pigsty with minimal components |
| REDIS | redis.yml |
Initialize Redis cluster/node/instance |
| REDIS | redis-rm.yml |
Remove Redis cluster/node/instance |
| ETCD | etcd.yml |
Initialize ETCD cluster or add new member |
| ETCD | etcd-rm.yml |
Remove ETCD cluster/data or shrink member |
| MINIO | minio.yml |
Initialize a Silo object-storage cluster |
| MINIO | minio-rm.yml |
Remove Silo, its configuration, and optional data |
| DOCKER | docker.yml |
Install Docker on nodes |
| DOCKER | app.yml |
Install applications using Docker Compose |
| JUICE | juice.yml |
Install and configure JuiceFS |
| VIBE | vibe.yml |
Install the Vibe coding environment |
| KAFKA | kafka.yml |
Create or converge a Kafka dynamic KRaft cluster |
| KAFKA | kafka-rm.yml |
Remove a Kafka cluster or member |
| MYSQL (Pilot) | mysql.yml |
Deploy native MySQL 8.4 standalone or three-node clusters |
| MYSQL (Pilot) | mysql-rm.yml |
Stop and retire native MySQL while retaining local state |
Pigsty installs from Internet upstream by default, but some envs are isolated from the Internet. To address this, Pigsty supports offline installation using offline packages. Think of them as Linux-native Docker images.
Offline packages bundle all required RPM/DEB packages and dependencies; they are snapshots of the local APT/YUM repo after a normal installation.
In serious prod deployments, we strongly recommend using offline packages. They ensure all future nodes have consistent software versions with the existing env, and avoid online installation failures caused by upstream changes (quite common!), guaranteeing you can run it independently forever.
The following table records the historical v4.4.0 offline artifacts and the OS minor versions used to build them; these are not the currently recommended operating systems.
| Linux Distribution | System Code | Minor Version | Package |
|---|---|---|---|
| RockyLinux 9 x86_64 | el9.x86_64 |
9.7 |
pigsty-pkg-v4.4.0.el9.x86_64.tgz |
| RockyLinux 9 aarch64 | el9.aarch64 |
9.7 |
pigsty-pkg-v4.4.0.el9.aarch64.tgz |
| RockyLinux 10 x86_64 | el10.x86_64 |
10.1 |
pigsty-pkg-v4.4.0.el10.x86_64.tgz |
| RockyLinux 10 aarch64 | el10.aarch64 |
10.1 |
pigsty-pkg-v4.4.0.el10.aarch64.tgz |
| Debian 12 x86_64 | d12.x86_64 |
12.14 |
pigsty-pkg-v4.4.0.d12.x86_64.tgz |
| Debian 12 aarch64 | d12.aarch64 |
12.14 |
pigsty-pkg-v4.4.0.d12.aarch64.tgz |
| Debian 13 x86_64 | d13.x86_64 |
13.6 |
pigsty-pkg-v4.4.0.d13.x86_64.tgz |
| Debian 13 aarch64 | d13.aarch64 |
13.6 |
pigsty-pkg-v4.4.0.d13.aarch64.tgz |
| Ubuntu 26.04 x86_64 | u26.x86_64 |
26.04.0 |
pigsty-pkg-v4.4.0.u26.x86_64.tgz |
| Ubuntu 26.04 aarch64 | u26.aarch64 |
26.04.0 |
pigsty-pkg-v4.4.0.u26.aarch64.tgz |
| Ubuntu 24.04 x86_64 | u24.x86_64 |
24.04.4 |
pigsty-pkg-v4.4.0.u24.x86_64.tgz |
| Ubuntu 24.04 aarch64 | u24.aarch64 |
24.04.4 |
pigsty-pkg-v4.4.0.u24.aarch64.tgz |
| Ubuntu 22.04 x86_64 | u22.x86_64 |
22.04.5 |
pigsty-pkg-v4.4.0.u22.x86_64.tgz |
| Ubuntu 22.04 aarch64 | u22.aarch64 |
22.04.5 |
pigsty-pkg-v4.4.0.u22.aarch64.tgz |
If your OS exactly matches one of these historical artifact baselines, you can use the corresponding v4.4.0 offline package.
The v4.4.0 Community Edition publishes six dual-architecture artifacts for Debian 13, EL 10, and Ubuntu 24.04 on GitHub.
Artifact names and checksums for Debian 12, EL 9, Ubuntu 22.04, and Ubuntu 26.04 remain listed here; those offline packages are available with the Professional Edition.
Download Community Edition artifacts from the GitHub release page. The MD5 checksums for all v4.4.0 offline packages are:
When OS minor versions don’t match, it may work or may fail—we don’t recommend taking the risk.
Please note that the historical v4.4.0 artifacts above were built on EL 9.7/10.1, Debian 12.14/13.6, and Ubuntu 22.04.5/24.04.4/26.04.0.
Cross-minor installation may fail due to OpenSSL/system library differences.
Use online installation on matching OS versions to build your own offline package, or contact us for custom packages.
Offline installation steps:
/tmp/pkg.tgzcd ~/pigsty)./bootstrap, it will extract the package and configure using local repo (and install ansible from it offline)./configure -g -c rich, you can directly use the rich template configured for offline installation, or configure yourself./deploy.yml as usual to install the core path from the local repository; other optional modules still require their own playbooksdemo/install-offline.cast — /demo/install-offline.cast
If you encounter “No package nginx available” errors during offline installation, it usually means a previous installation attempt failed. Delete the /www/pigsty directory and re-run the deployment.
If you want to use the already extracted and configured offline package in your own config, modify and ensure these settings:
repo_enabled: Set to true, will build local software repo (explicitly disabled in most templates)node_repo_modules: Set to local, then all nodes in the env will install from the local software repo
node,infra,pgsql, i.e., install directly from these upstream repos.local will use the local software repo to install all packages, fastest, no interference from other repos.local,node,infra,pgsqlThe first parameter, if enabled, Pigsty will create a local software repo. The second parameter, if contains local, then all nodes in the env will use this local software repo.
If it only contains local, then it becomes the sole repo for all nodes. If you still want to install other packages from other upstream repos, you can add other repo module names too, e.g., local,node,infra,pgsql.
Hybrid Installation Mode
If your environment has Internet access, there’s a hybrid approach that combines the advantages of offline and online installation. You can use the offline package as a base, and supplement missing packages online.
Using the historical v4.4.0 artifacts as an example, suppose you run RockyLinux 9.6 while the package was built for RockyLinux 9.7.
You can use the el9 offline package (though made for 9.7), then execute make repo-build before formal installation to re-download missing packages for 9.6.
Pigsty will download the required increments from upstream repos.
If your OS isn’t in the default list, you can make your own offline package with the built-in cache.yml playbook:
rich template for an online installation (./configure -c rich), and confirm that the target INFRA node has generated its local repository at /www/pigsty; if not, run ./infra.yml -t repo against that node firstcd ~/pigsty; ./cache.yml -l <infra-host> to select one INFRA node that already has a local repository, build the package there, and fetch it~/pigsty/dist/${version}/pigsty-pkg-${version}.${os}.${arch}.tgz; copy it to the offline environment (ftp, scp, USB, etc.), then unpack it with bootstrapCurrent cache.yml defaults can be overridden with extra variables:
cache_pkg_name
,
cache_pkg_dir
,
cache_repo
,
We offer paid services providing tested, pre-made offline packages for specific Linux major.minor versions (¥200).
Pigsty relies on ansible to execute playbooks; this script is responsible for ensuring ansible is correctly installed in various ways.
Usually, you need to run this script in two cases:
git clone of the source package, so ansible isn’t installed.The bootstrap script will automatically detect if the offline package exists (-p to specify, default is /tmp/pkg.tgz).
If it exists, it will extract and use it, then install ansible from it.
If the offline package doesn’t exist, it will try to install ansible from the Internet. If that still fails, you’re on your own!
The bootloader will by default move away existing repo configurations to ensure only required repos are enabled.
You can find them in /etc/yum.repos.d/backup (EL) or /etc/apt/backup (Debian / Ubuntu).
If you want to keep existing repo configurations during bootstrap, use the -k|--keep parameter.
If you only want HA PostgreSQL database cluster itself without monitoring, infra, etc., consider Slim Installation.
Slim installation has no INFRA module, no monitoring, no local repo—just ETCD and PGSQL and partial NODE functionality.
To use slim installation, you need to:
slim.yml slim install config template (configure -c slim)slim.yml playbook instead of the default deploy.ymldemo/install-slim.cast — /demo/install-slim.cast
Slim installation only installs/configures these components:
| Component | Required | Description |
|---|---|---|
patroni |
⚠️ Required | Bootstrap HA PostgreSQL cluster |
etcd |
⚠️ Required | Meta database dependency (DCS) for Patroni |
pgbouncer |
✔️ Optional | PostgreSQL connection pooler |
vip-manager |
✔️ Optional | L2 VIP binding to PostgreSQL cluster primary |
haproxy |
✔️ Optional | Auto-routing services via Patroni health checks |
chronyd |
✔️ Optional | Time synchronization with NTP server |
tuned |
✔️ Optional | Node tuning template and kernel parameter management |
You can disable all optional components via configuration, keeping only the required patroni and etcd.
Because there’s no INFRA module’s Nginx providing local repo service, offline installation only works in single-node mode.
Slim installation config file example: conf/slim.yml:
Slim installation uses the slim.yml playbook instead of deploy.yml:
Slim installation can also deploy HA clusters—just add more nodes to the etcd and pg-meta groups. A three-node deployment example:
| ID | NODE | PGSQL | INFRA | ETCD |
|---|---|---|---|---|
| 1 | 10.10.10.10 |
pg-meta-1 |
No INFRA module | etcd-1 |
| 2 | 10.10.10.11 |
pg-meta-2 |
No INFRA module | etcd-2 |
| 3 | 10.10.10.12 |
pg-meta-3 |
No INFRA module | etcd-3 |
The default configuration targets local demonstrations and development or testing on a trusted intranet. If other hosts can reach the deployment, complete at least three checks: credentials, network boundaries, and critical files.
Production environments should also review the Security Model, Compliance, and Security Considerations.
Pigsty default credentials are public in the source code and documentation and must not be used directly in production.
The configuration wizard can randomize built-in parameters and example credentials that it recognizes:
configure -g does not replace:
cipher_pass;ha/safe;After generation, inspect pigsty.yml and replace every uncovered credential. The wizard prints generated passwords to the terminal, so protect terminal history and automation logs as sensitive data.
See the Default Credentials Checklist for the complete scope.
node_firewall_mode defaults to zone. It trusts the intranet defined by node_firewall_intranet and restricts ports exposed to public networks.
| Port | Service | Public by Default |
|---|---|---|
22 |
SSH | Yes |
80 |
Nginx HTTP | Yes |
443 |
Nginx HTTPS | Yes |
5432 |
PostgreSQL | Not in the base default; exposed additionally by the demo pigsty.yml |
Production deployments should normally remove 5432 from the demo configuration. If applications need direct database access, restrict source addresses in the cloud security group, host firewall, and HBA.
Also verify that the intranet definition matches the actual trust boundary. The default RFC 1918 ranges may be too broad; office networks, container networks, and other tenant networks should not become trusted automatically.
The following files and directories contain highly sensitive information:
pigsty.yml: system and application credentials, node definitions, and service configuration;files/pki/ca/ca.key: local CA private key;files/pki/misc/*.key: client-certificate private keys;/pg/tmp/pg-user-*.sql: SQL containing plaintext passwords generated during user creation.Restrict access to the admin node and configuration repository. Do not commit complete inventories or private keys to public repositories. Maintain controlled backups of the CA private key and required configuration.
Unlike Getting Started, production Pigsty deployments require more Architecture Planning and Preparation.
This chapter helps you understand the complete deployment process and provides best practices for production environments.
Before deploying to production, we recommend testing in Pigsty’s Sandbox to fully understand the workflow. Use Vagrant to create a local 4-node sandbox, or leverage OpenTofu to provision larger simulation environments in the cloud.
For production, you typically need at least three nodes for high availability. You should understand Pigsty’s core Concepts and common administration procedures, including Configuration, Ansible Playbooks, and Security Hardening for enterprise compliance.
This is the Pigsty production multi-node deployment guide. For single-node Demo/Dev setups, see Getting Started.
Prepare nodes with SSH access following your architecture plan,
install a compatible Linux OS, then execute with an admin user having passwordless ssh and sudo:
This runs the install script, downloading and extracting Pigsty source to your home directory with dependencies installed. Complete configuration and deployment to finish.
Before running deploy.yml for deployment, review and edit the configuration inventory: pigsty.yml.
After installation, access the WebUI via IP/domain + ports 80/443,
and PostgreSQL service via port 5432.
Full installation takes 3-10 minutes depending on specs/network. Offline installation significantly speeds this up; slim installation further accelerates when monitoring isn’t needed.
Video Example: 20-node Production Simulation (Ubuntu 24.04 x86_64)
demo/install-simu.cast — /demo/install-simu.cast
Production Pigsty deployment involves preparation work. Here’s the complete checklist:
| Item | Requirement | Item | Requirement |
|---|---|---|---|
| Node | At least 1C2G, no upper limit |
Plan | Multiple homogeneous nodes: 2/3/4 or more |
| Disk | /data as default mount point |
FS | xfs recommended; ext4/zfs as needed |
| VIP | L2 VIP, optional (unavailable in cloud) | Network | Static IPv4, single-node can use 127.0.0.1 |
| CA | Self-signed CA or specify existing certs | Domain | Local/public domain, optional, default i.pigsty |
| Kernel | Linux x86_64 / aarch64 |
Linux | el8, el9, el10, d12, d13, u22, u24, u26 |
| Locale | C.UTF-8 or C |
Firewall | Ports: 80/443/22/5432 (optional) |
| User | Avoid root and postgres |
Sudo | sudo privilege, preferably with nopass |
| SSH | Passwordless SSH via public key | Accessible | ssh <ip|alias> sudo ls no error |
Use the following to automatically install the Pigsty source package to ~/pigsty (recommended). Deployment dependencies (Ansible) are auto-installed.
If you prefer not to run remote scripts, manually download or clone the source. When using git, always checkout a specific version before use:
For manual download/clone, additionally run bootstrap to manually install Ansible and other dependencies, or install them yourself:
In Pigsty, deployment details are defined by the configuration inventory—the pigsty.yml config file. Customize through declarative configuration.
Pigsty provides configure as an optional configuration wizard,
generating a configuration inventory with good defaults based on your environment:
The generated config defaults to ~/pigsty/pigsty.yml. Review and customize before installation.
Many configuration templates are available for reference. You can skip the wizard and directly edit pigsty.yml:
The wizard only replaces the current node’s IP (use -s to skip replacement). For multi-node deployments, replace other node IPs manually.
Also customize the config as needed—modify default passwords, add nodes, etc.
Common configure parameters:
| Parameter | Description |
|---|---|
-c|--conf |
Specify config template relative to conf/, without .yml suffix |
-v|--version |
PostgreSQL major version 14 through 19; PG19 is currently Beta |
-r|--region |
Upstream repo region for faster downloads: default|china|europe |
-n|--non-interactive |
Use CLI params for primary IP, skip interactive wizard |
-x|--proxy |
Configure proxy_env from current environment variables |
If your machine has multiple IPs, explicitly specify one with -i|--ip <ipaddr> or provide it interactively.
The script replaces IP placeholder 10.10.10.10 with the current node’s primary IPv4. Use a static IP; never use public IPs.
Generated config is at ~/pigsty/pigsty.yml. Review and modify before installation.
Change default passwords and credentials before installation. See Security Recommendations.
Pigsty’s deploy.yml playbook applies the configuration blueprint to all target nodes.
When output ends with pgsql init done, PLAY RECAP, etc., installation is complete!
Upstream repos (Linux/PGDG) may break due to improper updates, causing deployment failures (quite common)! For serious production deployments, we strongly recommend using verified offline packages for offline installation.
Warning: Running deploy.yml again on an initialized environment may restart services and overwrite configs. Be careful!
Assuming the 4-node deployment template, your Pigsty environment should have a structure like:
| ID | NODE | PGSQL | INFRA | ETCD |
|---|---|---|---|---|
| 1 | 10.10.10.10 |
pg-meta-1 |
infra-1 |
etcd-1 |
| 2 | 10.10.10.11 |
pg-test-1 |
- | - |
| 3 | 10.10.10.12 |
pg-test-2 |
- | - |
| 4 | 10.10.10.13 |
pg-test-3 |
- | - |
The INFRA module provides a graphical management interface via browser, accessible through Nginx’s 80/443 ports.
The PGSQL module provides a PostgreSQL database server on port 5432, also accessible via Pgbouncer/HAProxy proxies.
For production multi-node HA PostgreSQL clusters, use service access for automatic traffic routing.
After installation, explore the WebUI and access PostgreSQL service via port 5432.
Deploy and monitor more clusters—add definitions to the configuration inventory and run:
Most modules require the NODE module first. See available modules:
Pigsty runs on nodes (physical machines or VMs). This document covers the planning and preparation required for deployment.
Pigsty currently runs on Linux kernel with x86_64 / aarch64 architecture.
A “node” refers to an SSH accessible resource that provides a bare Linux OS environment.
It can be a physical machine, virtual machine, or a systemd-enabled container equipped with systemd, sudo, and sshd.
Deploying Pigsty requires at least 1 node. You can prepare more and deploy everything in one pass via playbooks, or add nodes later.
The minimum spec requirement is 1C1G, but at least 1C2G is recommended. Higher is better—no upper limit. Parameters are auto-tuned based on available resources.
The number of nodes you need depends on your requirements. See Architecture Planning for details. Although a single-node deployment with external backup provides reasonable recovery guarantees, we recommend multiple nodes for production. A functioning HA setup requires at least 3 nodes; 2 nodes provide Semi-HA.
Pigsty uses /data as the default data directory. If you have a dedicated data disk, mount it there.
Use /data1, /data2, /dataN for additional disk drives.
To use a different data directory, configure these parameters:
| Name | Description | Default |
|---|---|---|
node_data |
Node main data directory | /data |
pg_fs_main |
PG main data directory | /data/postgres |
pg_fs_backup |
PG backup directory | /data/backups |
etcd_data |
ETCD data directory | /data/etcd |
infra_data |
Infra data directory | /data/infra |
nginx_data |
Nginx data directory | /data/nginx |
minio_data |
Silo data directory | /data/minio |
redis_fs_main |
Redis data directory | /data/redis |
kafka_data |
Kafka data directory | /data/kafka |
The native MySQL 8.4 pilot module does not currently expose a data-directory parameter and always uses /var/lib/mysql.
You can use any supported Linux filesystem for data disks. For production, we recommend xfs.
xfs is a Linux standard with excellent performance and CoW capabilities for instant large database cluster cloning. Multi-drive Silo deployments require xfs.
ext4 is another viable option with a richer data recovery tool ecosystem, but lacks CoW.
zfs provides RAID and snapshot features but with significant performance overhead and requires separate installation.
Choose among these three based on your needs. Avoid NFS for database services.
Pigsty assumes /data is owned by root:root with 755 permissions.
Admins can assign ownership for first-level directories; each application runs with a dedicated user in its subdirectory.
See FHS for the directory structure reference.
Pigsty defaults to online installation mode, requiring outbound Internet access. Offline installation eliminates the Internet requirement.
Internally, Pigsty requires a static network. Assign a fixed IPv4 address to each node.
The IP address serves as the node’s unique identifier—the primary IP bound to the main network interface for internal communications.
For single-node deployment without a fixed IP, use the loopback address 127.0.0.1 as a workaround.
Using public IP addresses as node identifiers can cause security and connectivity issues. Always use internal IP addresses.
Pigsty supports optional L2 VIP for NODE clusters (keepalived) and PGSQL clusters (vip-manager).
To use L2 VIP, you must explicitly assign an L2 VIP address for each node/database cluster. This is straightforward on your own hardware but may be challenging in public cloud environments.
To use optional Node VIP and PG VIP features, ensure all nodes are on the same L2 network.
Pigsty generates a self-signed CA infrastructure for each deployment, issuing all encryption certificates.
If you have an existing enterprise CA or self-signed CA, you can use it to issue the certificates Pigsty requires.
Pigsty uses a local static domain i.pigsty by default for WebUI access. This is optional—IP addresses work too.
For production, domain names are recommended to enable HTTPS and encrypted data transmission. Domains also allow multiple services on the same port, differentiated by domain name.
For Internet-facing deployments, use public DNS providers (Cloudflare, AWS Route53, etc.) to manage resolution. Point your domain to the Pigsty node’s public IP address. For LAN/office network deployments, use internal DNS servers with the node’s internal IP address.
For local-only access, add the following to /etc/hosts on machines accessing the Pigsty WebUI:
Pigsty runs on Linux. It currently targets 16 platform combinations: eight distribution major versions across two architectures. See the Compatible OS List.
We recommend Rocky Linux 9.8 / 10.2, Debian 12.15 / 13.6, or Ubuntu 22.04.5 / 24.04.4 / 26.04.0 as default options.
On macOS and Windows, use VM software or Docker systemd images to run Pigsty.
We strongly recommend a fresh OS installation. If your server already runs Nginx, PostgreSQL, or similar services, consider deploying on new nodes.
For multi-node deployments, ensure all nodes use the same Linux distribution, architecture, and version. Heterogeneous deployments may work but are unsupported and may cause unpredictable issues.
We recommend setting en_US as the primary OS language, or at minimum ensuring this locale is available, so PostgreSQL logs are in English.
Some distributions (e.g., Debian) may not provide the en_US locale by default. Enable it with:
For PostgreSQL, we strongly recommend using the built-in C.UTF-8 collation (PG 17+) as the default.
The configuration wizard automatically sets C.UTF-8 as the collation when PG version and OS support are detected.
Pigsty uses Ansible to control all managed nodes from the admin node. See Installing Ansible for details.
Pigsty installs Ansible on Infra nodes by default, making them usable as admin nodes (or backup admin nodes). For single-node deployment, the installation node serves as both the admin node running Ansible and the INFRA node hosting infrastructure.
You can install the current default Pigsty source with:
To install a specific version, use the -s <version> parameter:
To install the latest beta version:
For developers or the latest development version, clone the repository directly:
If your environment lacks Internet access, download the source tarball from GitHub Releases or the Pigsty repository:
Pigsty uses a modular architecture. You can combine modules like building blocks and express your intent through declarative configuration.
Here are common deployment patterns for reference. Customize based on your requirements:
| Pattern | INFRA | ETCD | PGSQL | MINIO | Description |
|---|---|---|---|---|---|
Single-node (meta) |
1 | 1 | 1 | Single-node deployment default | |
Slim deploy (slim) |
1 | 1 | Database only, no monitoring infra | ||
Infra-only (infra) |
1 | Monitoring infrastructure only | |||
Rich deploy (rich) |
1 | 1 | 1 | 1 | Single-node + object storage + local repo with all extensions |
| Multi-node Pattern | INFRA | ETCD | PGSQL | MINIO | Description |
|---|---|---|---|---|---|
Two-node (dual) |
1 | 1 | 2 | Semi-HA, tolerates specific node failure | |
Three-node (trio) |
3 | 3 | 3 | Standard HA, tolerates any one failure | |
Four-node (full) |
1 | 1 | 1+3 | Demo setup, single INFRA/ETCD | |
Production (simu) |
2 | 3 | n | n | 2 INFRA, 3 ETCD |
| Large-scale (custom) | 3 | 5 | n | n | 3 INFRA, 5 ETCD |
Your architecture choice depends on reliability requirements and available resources. Serious production deployments require at least 3 nodes for HA configuration. With only 2 nodes, use Semi-HA configuration.
We offer Architecture Consulting Services to help plan your Pigsty configuration.
The simplest configuration with everything on a single node. Installs four essential modules by default. Typically used for demos, devbox, or testing.
With an external S3/MinIO backup repository providing RTO/RPO guarantees, this configuration works for standard production environments.
Single-node variants:
rich): Production single-node template with local Silo object storage, local software repo, and all PG extensions.slim): Installs only PGSQL and ETCD, no monitoring infra. Slim installation can expand to multi-node HA deployment.infra): Opposite of slim—installs only INFRA monitoring infrastructure, no database services, for monitoring other instances.pgsql, mssql, polar, ivory, mysql, pgtde, oriole, agens, pgedge.Two-node configuration enables database replication and Semi-HA capability with better data redundancy and limited failover support:
Two-node HA auto-failover has limitations. This “Semi-HA” setup only auto-recovers from specific node failures:
node-1 fails: No automatic failover—requires manual promotion of node-2node-2 fails: Automatic failover works—node-1 auto-promotedThree-node template provides true baseline HA configuration, tolerating any single node failure with automatic recovery.
| ID | NODE | PGSQL | INFRA | ETCD |
|---|---|---|---|---|
| 1 | node-1 |
pg-meta-1 |
infra-1 |
etcd-1 |
| 2 | node-2 |
pg-meta-2 |
infra-2 |
etcd-2 |
| 3 | node-3 |
pg-meta-3 |
infra-3 |
etcd-3 |
Pigsty Sandbox uses the standard four-node configuration.
| ID | NODE | PGSQL | INFRA | ETCD |
|---|---|---|---|---|
| 1 | node-1 |
pg-meta-1 |
infra-1 |
etcd-1 |
| 2 | node-2 |
pg-test-1 |
||
| 3 | node-3 |
pg-test-2 |
||
| 4 | node-4 |
pg-test-3 |
For demo purposes, INFRA / ETCD modules aren’t configured for HA. You can adjust further:
| ID | NODE | PGSQL | INFRA | ETCD | MINIO |
|---|---|---|---|---|---|
| 1 | node-1 |
pg-meta-1 |
infra-1 |
etcd-1 |
minio-1 |
| 2 | node-2 |
pg-test-1 |
infra-2 |
etcd-2 |
|
| 3 | node-3 |
pg-test-2 |
etcd-3 |
||
| 4 | node-4 |
pg-test-3 |
With proper virtualization infrastructure or abundant resources, you can use more nodes for dedicated deployment of each module, achieving optimal reliability, observability, and performance.
| ID | NODE | INFRA | ETCD | MINIO | PGSQL |
|---|---|---|---|---|---|
| 1 | 10.10.10.10 |
infra-1 |
pg-meta-1 |
||
| 2 | 10.10.10.11 |
infra-2 |
pg-meta-2 |
||
| 3 | 10.10.10.21 |
etcd-1 |
|||
| 4 | 10.10.10.22 |
etcd-2 |
|||
| 5 | 10.10.10.23 |
etcd-3 |
|||
| 6 | 10.10.10.31 |
minio-1 |
|||
| 7 | 10.10.10.32 |
minio-2 |
|||
| 8 | 10.10.10.33 |
minio-3 |
|||
| 9 | 10.10.10.34 |
minio-4 |
|||
| 10 | 10.10.10.40 |
pg-src-1 |
|||
| 11 | 10.10.10.41 |
pg-src-2 |
|||
| 12 | 10.10.10.42 |
pg-src-3 |
|||
| 13 | 10.10.10.50 |
pg-test-1 |
|||
| 14 | 10.10.10.51 |
pg-test-2 |
|||
| 15 | 10.10.10.52 |
pg-test-3 |
|||
| 16 | …… |
Pigsty requires an OS admin user with passwordless SSH and Sudo privileges on all managed nodes.
This user must be able to SSH to all managed nodes and execute sudo commands on them.
Typically use names like dba or admin, avoiding root and postgres:
root for deployment is possible but not a production best practice.postgres (pg_dbsu) as admin user is strictly prohibited.The passwordless requirement is optional if you can accept entering a password for every ssh and sudo command.
Use -k|--ask-pass when running playbooks to prompt for SSH password,
and -K|--ask-become-pass to prompt for sudo password.
Some enterprise security policies may prohibit passwordless ssh or sudo. In such cases, use the options above,
or consider configuring a sudoers rule with a longer password cache time to reduce password prompts.
Typically, your server/VM provider creates an initial admin user.
If unsatisfied with that user, Pigsty’s deployment playbook can create a new admin user for you.
Assuming you have root access or an existing admin user on the node, create an admin user with Pigsty itself:
This leverages the existing admin to create a new one—a dedicated dba (uid=88) user described by these parameters, with sudo/ssh properly configured:
| Name | Description | Default |
|---|---|---|
node_admin_enabled |
Enable node admin user | true |
node_admin_uid |
Node admin user UID | 88 |
node_admin_username |
Node admin username | dba |
All admin users should have sudo privileges on all managed nodes, preferably with passwordless execution.
To configure an admin user with passwordless sudo from scratch, edit/create a sudoers file (assuming username vagrant):
For admin user dba, the /etc/sudoers.d/dba content should be:
If your security policy prohibits passwordless sudo, remove the NOPASSWD: part:
Ansible relies on sudo to execute commands with root privileges on managed nodes.
In environments where sudo is unavailable (e.g., inside Docker containers), install sudo first.
Your current user should have passwordless SSH access to all managed nodes as the corresponding admin user.
Your current user can be the admin user itself, but this isn’t required—as long as you can SSH as the admin user.
SSH configuration is Linux 101, but here are the basics:
If you don’t have an SSH key pair, generate one:
Pigsty will do this for you during the bootstrap stage if you lack a key pair.
Distribute your generated public key to remote (and local) servers, placing it in the admin user’s ~/.ssh/authorized_keys file on all nodes.
Use the ssh-copy-id utility:
When direct SSH access is unavailable (jumpserver, non-standard port, different credentials), configure SSH aliases in ~/.ssh/config:
Reference the alias in the inventory using ansible_host for the real SSH alias:
SSH parameters work directly in Ansible. See Ansible Inventory Guide for details. This technique enables accessing nodes in private networks via jumpservers, or using different ports and credentials, or using your local laptop as an admin node.
You should be able to passwordlessly ssh from the admin node to all managed nodes as your current user.
The remote user (admin user) should have privileges to run passwordless sudo commands.
To verify passwordless ssh/sudo works, run this command on the admin node for all managed nodes:
If there’s no password prompt or error, passwordless ssh/sudo is working as expected.
Production deployments typically require firewall configuration to block unauthorized port access.
By default, block inbound access from office/Internet networks except:
22 for node access80) / HTTPS (443) for WebUI services5432 for database accessIf accessing PostgreSQL via other ports, allow them accordingly. See used ports for the complete port list.
5432: PostgreSQL database6432: Pgbouncer connection pooler5433: PG primary service5434: PG replica service5436: PG default service5438: PG offline servicePigsty provides a standard 4-node sandbox environment for learning, testing, and feature demonstration.
The sandbox uses fixed IP addresses and predefined identity identifiers, making it easy to reproduce various demo use cases.
The default sandbox environment consists of 4 nodes, using the ha/full.yml configuration template.
| ID | IP Address | Node | PostgreSQL | INFRA | ETCD | MINIO |
|---|---|---|---|---|---|---|
| 1 | 10.10.10.10 |
meta |
pg-meta-1 |
infra-1 |
etcd-1 |
minio-1 |
| 2 | 10.10.10.11 |
node-1 |
pg-test-1 |
|||
| 3 | 10.10.10.12 |
node-2 |
pg-test-2 |
|||
| 4 | 10.10.10.13 |
node-3 |
pg-test-3 |
The sandbox configuration can be summarized as the following config:

The sandbox comes with a single-instance PostgreSQL cluster pg-meta on the meta node:
There’s also a 3-instance PostgreSQL HA cluster pg-test deployed on the other three nodes:
Two optional L2 VIPs are bound to the primary instances of pg-meta and pg-test clusters respectively.
The meta node also hosts:
etcd cluster providing DCS service for PostgreSQL HAminio cluster managed by the MINIO module, providing S3-compatible object storageha/full.yml also declares three Redis example topologies and enables Docker installation on the INFRA node. The standard deploy.yml does not deploy these two optional modules; run ./redis.yml and ./docker.yml separately when needed.
Pigsty provides out-of-the-box templates. You can use Vagrant to create a local sandbox, or use OpenTofu to create a cloud sandbox.
Local sandbox uses VirtualBox/libvirt to create local virtual machines, running free on your Mac / PC.
To run the full 4-node sandbox, your machine should have at least 4 CPU cores and 8GB memory.
The current Vagrant configuration uses the cloud-image/* boxes from Vagrant Cloud. See Vagrant: Supported Images for available images, source-pinned versions, and architecture details. Boxes without a version pinned in source are resolved by Vagrant to their currently available version.
Cloud sandbox uses public cloud API to create virtual machines. Easy to create and destroy, pay-as-you-go, ideal for quick testing.
Use the spec/aliyun-full.tf template to create a 4-node sandbox on Alibaba Cloud:
For more details, please refer to the OpenTofu documentation.
Besides the standard 4-node sandbox, Pigsty also provides other environment specs:
Run the following Makefile shortcuts from ~/pigsty/vagrant:
The simplest 1-node environment for quick start, development, and testing:
2-node environment for testing primary-replica replication:
3-node environment for testing basic high availability:
20-node large simulation environment for full production environment testing:
This environment includes:
meta1, meta2, meta3)Vagrant is a popular local virtualization tool that creates local virtual machines in a declarative manner.
Pigsty requires a Linux environment to run. You can use Vagrant to easily create Linux virtual machines locally for testing.
The currently recommended and validated baselines are Rocky Linux 9.8 / 10.2, Debian 12.15 / 13.6, and Ubuntu 22.04.5 / 24.04.4 / 26.04.0. Major-version Vagrant aliases map to pinned box versions.
First, ensure you have Vagrant and a virtual machine provider (such as VirtualBox or libvirt) installed on your system.
On macOS, you can use Homebrew for one-click installation:
After installing VirtualBox, you need to restart your system and allow its kernel extensions in System Preferences.
On Linux, you can use VirtualBox or vagrant-libvirt as the VM provider.
Use the Pigsty-provided make shortcuts to create virtual machines:
You can use variant aliases to specify different operating system images:
Available OS suffixes: 8 (EL8), 9 (EL9), 10 (EL10), 12 (Debian 12.15), 13 (Debian 13.6), 22 (Ubuntu 22.04.5), 24 (Ubuntu 24.04.4), 26 (Ubuntu 26.04.0)
You can also use the following aliases to create Pigsty build environments. These templates won’t replace the base image:
Pigsty provides multiple predefined VM specs in the vagrant/spec/ directory:
| Template | Nodes | Spec | Description | Alias |
|---|---|---|---|---|
| meta.rb | 1 node | 2c4g x 1 | Single-node devbox | Devbox |
| dual.rb | 2 nodes | 1c2g x 2 | Two-node environment | |
| trio.rb | 3 nodes | 1c2g x 3 | Three-node environment | |
| full.rb | 4 nodes | 2c4g + 1c2g x 3 | 4-node full sandbox | Sandbox |
| deci.rb | 10 nodes | Mixed | 10-node environment | |
| simu.rb | 20 nodes | Mixed | 20-node production simubox | Simubox |
| minio.rb | 4 nodes | 1c2g x 4 + disk | MinIO test environment | |
| citus.rb | 13 nodes | Mixed | Citus coordinator and six two-replica worker groups | |
| oss.rb | 7 nodes | 2c2g x 7 | 7-platform OSS build environment | |
| pro.rb | 7 nodes | 2c2g x 7 | 7-platform PRO build environment | |
| rpm.rb | 2 nodes | 1c2g x 2 | 2-node EL build environment | |
| deb.rb | 5 nodes | 1c2g x 5 | 5-node Deb build environment | |
| all.rb | 7 nodes | 1c2g x 7 | 7-node full build environment |
Each spec file contains a Specs variable describing the VM nodes. For example, full.rb contains the 4-node sandbox definition:
Current Vagrant templates explicitly provision a 32 GB primary system disk for every VM. Regular nodes also receive one data disk whose size comes from the spec’s disk value, defaulting to 128 GB when omitted. Object-storage nodes whose names begin with minio instead receive four 32 GB data disks mounted at /data1 through /data4.
These disks depend on Vagrant’s experimental disks feature. The repository Makefile exports VAGRANT_EXPERIMENTAL=disks automatically; set it yourself when invoking vagrant directly.
simu.rb provides a 20-node production environment simulation configuration:
meta1-3): 4c16gproxy1-2): 1c2gminio1-4): 1c2getcd1-5): 1c2gpg-src-1-3, pg-dst-1-3): 2c4gUse the vagrant/config script to generate the final Vagrantfile based on spec and options:
The config script supports various image aliases:
| Distro | Alias | Vagrant Box |
|---|---|---|
| Rocky 8 | el8, rocky8, r8 |
cloud-image/rocky-8 |
| Rocky 9 | el9, rocky9, el, r9 |
cloud-image/rocky-9 |
| Rocky 10 | el10, rocky10, r10 |
cloud-image/rocky-10 |
| Debian 12 | d12, debian12, deb12 |
cloud-image/debian-12 |
| Debian 13 | d13, debian13, deb13 |
cloud-image/debian-13 |
| Ubuntu 22.04.5 | u22, ubuntu22, ubuntu2204 |
cloud-image/ubuntu-22.04 |
| Ubuntu 24.04.4 | u24, ubuntu24, ubuntu2404, ubuntu |
cloud-image/ubuntu-24.04 |
| Ubuntu 26.04.0 | u26, ubuntu26, ubuntu2604 |
cloud-image/ubuntu-26.04 |
| AlmaLinux 8 | alma8 |
cloud-image/almalinux-8 |
| AlmaLinux 9 | alma9 |
cloud-image/almalinux-9 |
| AlmaLinux 10 | alma10 |
cloud-image/almalinux-10 |
| RHEL 8 / 9 | rhel8, rhel9 |
generic/rhel8, generic/rhel9 |
| Oracle Linux 8 / 9 | oracle8, oracle9 |
generic/oracle8, generic/oracle9 |
The historical d11/debian11/deb11 and u20/ubuntu20/ubuntu2004 aliases remain visible in the script mapping, but the current script explicitly rejects them; they are not supported images.
You can use the VM_SCALE environment variable to adjust the resource multiplier (default is 1):
For example, using VM_SCALE=4 with the meta spec will adjust the default 2c4g to 8c16g:
The simu and deci specs don’t support resource scaling. The scale parameter is automatically reset to 1 because their resource configurations are already optimized for simulation scenarios.
The vagrant/Makefile provides shortcuts for managing virtual machines. Run the following commands from that directory:
Pigsty Vagrant templates use your ~/.ssh/id_rsa[.pub] as the SSH key for VMs by default.
Before starting, ensure you have a valid SSH key pair. If not, generate one with:
The standard EL, Debian, Ubuntu, and AlmaLinux matrix uses cloud-image/* boxes from Vagrant Cloud. Explicit RHEL and Oracle Linux aliases use generic/* boxes. The current config script applies the same cloud-image/* mapping to VirtualBox, libvirt, amd64, and arm64; actual payload availability is still resolved by Vagrant Cloud at runtime.
VirtualBox and libvirt use the same mapping. vagrant/config writes the validated versions below for every supported cloud-image/* image, making amd64 and arm64 environments reproducible:
| OS | Vagrant Box | Source Version Policy |
|---|---|---|
| Rocky 8 | cloud-image/rocky-8 |
8.10.20240528.0 |
| Rocky 9 | cloud-image/rocky-9 |
9.8.20260525.0 |
| Rocky 10 | cloud-image/rocky-10 |
10.2.20260525.0 |
| Debian 12 | cloud-image/debian-12 |
20260806.2562.0 |
| Debian 13 | cloud-image/debian-13 |
20260810.2566.0 |
| Ubuntu 22.04 | cloud-image/ubuntu-22.04 |
20260810.0.0 |
| Ubuntu 24.04 | cloud-image/ubuntu-24.04 |
20260801.0.0 |
| Ubuntu 26.04 | cloud-image/ubuntu-26.04 |
20260731.0.0 |
| AlmaLinux 8 | cloud-image/almalinux-8 |
8.10.20260803 |
| AlmaLinux 9 | cloud-image/almalinux-9 |
9.8.20260810 |
| AlmaLinux 10 | cloud-image/almalinux-10 |
10.2.20260526.0 |
The retained but unsupported Debian 11 and Ubuntu 20.04 aliases are pinned to 20260618.2513.0 and 20250624.0.0; experimental generic/* RHEL, Oracle Linux, and CentOS 7 images are pinned to their final 4.3.12 release. These legacy images are outside the current support matrix.
You can use the following environment variables to control Vagrant behavior:
When using older versions of VirtualBox as Vagrant provider, additional configuration is required to use 10.x.x.x CIDR as Host-Only network:
The first time you use Vagrant to start a specific operating system, it will download the corresponding Box image file (typically 1-2 GB). After download, the image is cached and reused for subsequent VM creation.
If you’re using libvirt as the provider, you can use make info to view VMs, networks, and storage volume information, and make nuke to forcefully destroy all related resources.
OpenTofu is an open-source “Infrastructure as Code” tool that you can use to create virtual machines on public clouds with one click.
Pigsty uses OpenTofu by default and provides Terraform-compatible .tf templates for Alibaba Cloud, AWS (global and China), Azure, GCP, Tencent Cloud, Hetzner, Vultr, DigitalOcean, and Linode. The aliyun-s3.tf template also creates a private OSS bucket and dedicated RAM read/write credentials for S3/pgBackRest scenarios.
On macOS, you can use Homebrew to install OpenTofu:
For Debian, Ubuntu, RHEL, and other platforms, refer to the OpenTofu installation guide. The package and command name is tofu.
Enter the cloud-template directory, select a template, initialize provider plugins, and apply the configuration:
After reviewing the plan, run tofu apply and type yes to confirm. OpenTofu will then create VMs and related cloud resources.
After creation, print the public IP address of the admin node:
Global-cloud templates usually also provide an executable ssh_command output:
The repository’s ./ssh script is a compatibility tool for legacy templates whose outputs are all IP addresses and whose root password is PigstyDemo4. It iterates over the IaC outputs, treats them as IP addresses, writes them to ~/.ssh/pigsty_config, and distributes keys with sshpass. It is suitable for compatibility templates such as aliyun.tf, aliyun-full.tf, aliyun-oss.tf, and aliyun-pro.tf. Do not run it against modern templates that output ssh_command, private IPs, or access keys.
When using a compatible template:
If you want to use the configuration in ~/.ssh/pigsty_config, ensure your ~/.ssh/config includes:
After testing, you can destroy all created cloud resources with one click:
The directory and file names remain terraform/, .tf, terraform.tfvars, .terraform.lock.hcl, and terraform.tfstate because OpenTofu intentionally supports these compatibility names. Terraform remains available as an explicit compatibility option:
Use only one CLI in a working directory at a time. Before migrating existing state, preserve it and compare both plans:
Continue only when the OpenTofu plan contains the changes you expect. Never delete terraform.tfstate while reinitializing providers.
Pigsty provides multiple predefined cloud resource templates in the terraform/spec/ directory:
| Template File | Cloud Provider | Description |
|---|---|---|
aliyun.tf |
Alibaba Cloud | Single-node meta template, supports all distributions and AMD/ARM (default) |
aliyun-s3.tf |
Alibaba Cloud | Single node + private OSS bucket and RAM read/write credentials for S3/pgBackRest |
aliyun-full.tf |
Alibaba Cloud | Four-node sandbox, supports all distributions and AMD/ARM |
aliyun-oss.tf |
Alibaba Cloud | Six-node build template, supports all distributions and AMD/ARM |
aliyun-pro.tf |
Alibaba Cloud | Seven-node multi-distribution test template |
aws.tf |
AWS | Global AWS single node, Debian 12/13, AMD/ARM |
aws-cn.tf |
AWS | Legacy single-node environment for AWS China |
azure.tf |
Azure | Single node, Debian 12/13, AMD/ARM |
gcp.tf |
GCP | Single node, Debian 12/13, AMD/ARM |
qcloud.tf |
Tencent Cloud | Tencent Cloud single-node environment |
hetzner.tf |
Hetzner | Single node, Debian 12/13, AMD/ARM |
vultr.tf |
Vultr | Single node, Debian 12/13, currently AMD only |
digitalocean.tf |
DigitalOcean | Single node, Debian 12/13, currently AMD only |
linode.tf |
Linode | Single node, Debian 12/13, currently AMD only |
When using a template, copy the template file to terraform.tf:
Variables differ between templates. Alibaba Cloud templates support the full multi-distribution matrix and default to u26. Global AWS, Azure, GCP, Tencent Cloud, and Hetzner support Debian 12/13 with AMD/ARM selection and generally default to d12/amd64. Vultr, DigitalOcean, and Linode currently expose AMD instance choices only.
Alibaba Cloud templates expose the following resource parameters in a locals block. Other cloud templates use provider-specific instance, disk, and network variables or local values; consult the selected .tf file.
Add your Alibaba Cloud credentials to environment variables, for example in ~/.bash_profile or ~/.zshrc:
The following are commonly used ECS Public OS Image prefixes in Alibaba Cloud:
The currently recommended and validated baselines are Rocky Linux 9.8 / 10.2, Debian 12.15 / 13.6, and Ubuntu 22.04.5 / 24.04.4 / 26.04.0.
| Distro | Code | x86_64 Image Prefix | aarch64 Image Prefix |
|---|---|---|---|
| CentOS 7.9 | el7 |
centos_7_9_x64 |
- |
| Rocky 8.10 | el8 |
rockylinux_8_10_x64 |
rockylinux_8_10_arm64 |
| Rocky 9.8 | el9 |
rockylinux_9_8_x64 |
rockylinux_9_8_arm64 |
| Rocky 10.2 | el10 |
rockylinux_10_2_x64 |
rockylinux_10_2_arm64 |
| Debian 11.11 | d11 |
debian_11_11_x64 |
- |
| Debian 12.15 | d12 |
debian_12_15_x64 |
debian_12_15_arm64 |
| Debian 13.6 | d13 |
debian_13_6_x64 |
debian_13_6_arm64 |
| Ubuntu 22.04.5 LTS | u22 |
ubuntu_22_04_x64_20G |
ubuntu_22_04_arm64_20G |
| Ubuntu 24.04.4 LTS | u24 |
ubuntu_24_04_x64_20G |
ubuntu_24_04_arm64_20G |
| Ubuntu 26.04.0 LTS | u26 |
ubuntu_26_04_x64_20G |
ubuntu_26_04_arm64_20G |
| Anolis 8.10 | an8 |
anolisos_8_10_x64 |
anolisos_8_10_arm64 |
| Alibaba Cloud Linux 3 | al3 |
aliyun_3_x64_20G_alibase_[0-9]+ |
aliyun_3_arm64_20G_alibase_[0-9]+ |
The aliyun-s3.tf template additionally creates an OSS bucket and related permissions for PostgreSQL PITR backup:
pigsty-osspigsty-oss-user user~/pigsty.skoss:* permissions on the bucket and its objects for read/write useBoth global and China-region templates can read standard AWS environment variables or credential files:
aws.tf reads ~/.ssh/id_rsa.pub by default. The legacy China-region aws-cn.tf instead reads this dedicated public key:
aws.tf uses a rolling lookup for official Debian AMIs. aws-cn.tf uses a hard-coded China-region AMI and ~/.aws/pigsty-key.pub; verify the target region, AMI, and key before deployment.
Add Tencent Cloud credentials to environment variables:
Tencent Cloud templates are community-contributed examples and may need adjustments based on your specific requirements.
The GCP template also requires a project variable, for example tofu apply -var="project=my-project". Except for AWS China, current key-based templates read ~/.ssh/id_rsa.pub by default; edit the selected template to use another public-key path.
Pigsty provides OpenTofu-first Makefile shortcuts. Set IAC_CLI=terraform explicitly to use Terraform instead.
For modern templates with ssh_command, private-IP, or other non-IP outputs, run tofu apply directly; do not use make u, which invokes the legacy ./ssh script afterward. Automatic confirmation is available only through deliberately named up-auto, apply-auto, and destroy-auto targets.
Cloud resources created with OpenTofu incur costs. After testing, promptly use tofu destroy to destroy resources to avoid unnecessary expenses.
It’s recommended to use pay-as-you-go instance types for testing. Templates default to using Spot Instances to reduce costs.
Alibaba Cloud and Tencent Cloud templates set the default root password to PigstyDemo4; Linode uses PigstyDemo4! to satisfy its password-complexity rules.
Current AWS, Azure, GCP, Hetzner, Vultr, and DigitalOcean templates primarily use SSH public-key authentication and do not share a default root password. Example passwords are for temporary tests only; change them or disable password login in production.
These templates target demonstration and development. Their current security groups or cloud firewalls allow all or nearly all inbound traffic from 0.0.0.0/0 (some also include ::/0), not just the ports Pigsty requires.
Restrict source networks and ports before deployment; do not use these defaults unchanged in production.
After creation, SSH login to the admin node using:
Alibaba Cloud templates that retain the legacy output and password conventions can also use ./ssh or make ssh to write SSH aliases. For other templates, use their ssh_command output.
Pigsty defaults target development, testing, and demonstrations on a trusted intranet. A production deployment must configure credentials, network boundaries, authentication, certificates, backup, and audit according to its threat model.
See Security and Compliance for mechanisms and boundaries, and the Launch Hardening Checklist for executable checks. ha/safe is a hardening example, not a substitute for reviewing each control.
Protect these assets:
pigsty.yml and other inventories, which normally contain system and application credentials;files/pki/ca/ca.key, which can issue certificates trusted by the deployment;/pg/tmp/pg-user-*.sql files.Restrict access to the admin node and configuration repository. Do not commit complete inventories or private keys to public repositories. Back up the CA private key and recovery configuration through controlled channels.
Replace every public default credential before production. Start with:
This option does not replace the pgBackRest cipher_pass, every Silo example credential in ha/safe, or user-defined values. Review the result against the Default Credentials Checklist.
PostgreSQL stores newly set or updated passwords with SCRAM-SHA-256 by default. To enforce complexity, preload passwordcheck through pg_libs, or configure credcheck. Declare account lifetime with expire_in or expire_at.
Credential rotation must also update database users, the PgBouncer user list, component configuration, and client connection information. Prepare a rollback plan before rotating.
PostgreSQL listens on 0.0.0.0 by default. To constrain listen addresses, set:
A listen address is not the only boundary. Production reviews should also cover:
node_firewall_public_port;node_firewall_intranet trusts overly broad CIDRs;The demo pigsty.yml inventory also exposes 5432 publicly. Remove that exception in production. If direct database access is required, limit it to explicit application CIDRs.
pgbouncer_sslmode.patroni_ssl_enabled.HBA auth: ssl requires an encrypted connection only. Clients should also use sslmode=verify-full with a trusted CA to verify the database server; see Encrypted Communication.
Grafana, VictoriaMetrics, and other components may listen on node ports, but the default firewall does not expose them directly to public networks. Prefer Nginx for external access, and restrict management pages by source address and identity.
world rules.auth: cert for privileged remote users, with a process for delivering and revoking client certificates.revokeconn: true for multi-tenant shared clusters, and inspect effective database ACLs.role: offline explicitly on the HBA rule for dbrole_offline.After changing HBA, users, or roles, compare both the inventory and the effective database state.
Pigsty enables page checksums by default to detect page damage after write. Checksums do not detect every memory error, logical error, or incorrect application write.
The CRIT template enables Patroni strict synchronous mode and more detailed connection logging. The synchronous mode targets preservation of acknowledged transactions, but depends on synchronous_commit, synchronous-replica state, and failover conditions. Writes block when no synchronous replica is available.
CRIT configures watchdog as automatic; it activates only when the system has a usable watchdog device. Decide whether required is appropriate according to hardware and availability requirements.
pg_rpo and pg_rto, understand their configuration semantics and validate objectives through exercises.Replicas handle only some node failures; they do not replace backups.
pgbackrest_method: minio object-storage repository uses AES-256-CBC by default, but cipher_pass: pgBackRest is public and must be replaced.pgBR.${pg_cluster} in ha/safe is also an example and must not be used as the final key.See Data Security and Backup and Recovery for details.
The default OLTP template logs DDL, slow queries, and PostgreSQL 18 connection-authorization events. CRIT also logs connection and disconnection events.
pgaudit must be installed, preloaded, and configured with an audit policy. Installing the package alone does not produce SQL audit logs. When Vector and VictoriaLogs are enabled, adjust log retention, access, and archive policy to requirements.
Metrics, logs, and alerts are incident inputs only. Production also needs alert classification, on-call ownership, incident determination, response, evidence collection, and post-incident review.
permissive to enforcing after compatibility validation.Pigsty is a portable, extensible open-source PostgreSQL distribution for building production-grade database services in local environments with declarative configuration and automation. It has a vast ecosystem providing a complete set of tools, scripts, and best practices to bring PostgreSQL to enterprise-grade RDS service levels.
Pigsty’s name comes from PostgreSQL In Great STYle, also understood as Postgres, Infras, Graphics, Service, Toolbox, it’s all Yours—a self-hosted PostgreSQL solution with graphical monitoring that’s all yours. You can find the source code on GitHub, visit the official documentation for more information, or experience the Web UI in the online demo.
PostgreSQL is a sufficiently perfect database kernel, but it needs more tools and systems to become a truly excellent database service. In production environments, you need to manage every aspect of your database: high availability, backup recovery, monitoring alerts, access control, parameter tuning, extension installation, connection pooling, load balancing…
Wouldn’t it be easier if all this complex operational work could be automated? This is precisely why Pigsty was created.
Pigsty provides:
Out-of-the-Box PostgreSQL Distribution
Pigsty deeply integrates 575 extensions from the PostgreSQL ecosystem, providing out-of-the-box distributed, time-series, geographic, spatial, graph, vector, search, and other multi-modal database capabilities. From kernel to RDS distribution, providing production-grade database services for versions 14-18 on EL/Debian/Ubuntu.
Self-Healing High Availability Architecture
A high availability architecture built on Patroni, Etcd, and HAProxy enables automatic failover for hardware failures with seamless traffic handoff. Primary failure recovery time RTO < 45s, data recovery point RPO ≈ 0. You can perform rolling maintenance and upgrades on the entire cluster without application coordination.
Complete Point-in-Time Recovery Capability
Based on pgBackRest and an optional Silo object-storage cluster, providing out-of-the-box PITR point-in-time recovery capability. Giving you the ability to quickly return to any point in time, protecting against software defects and accidental data deletion.
Flexible Service Access and Traffic Management
Through HAProxy, Pgbouncer, and VIP, providing flexible service access patterns for read-write separation, connection pooling, and automatic routing. Delivering stable, reliable, auto-routing, transaction-pooled high-performance database services.
Stunning Observability
An observability stack based on VictoriaMetrics and Grafana provides unparalleled monitoring best practices. Over three thousand types of monitoring metrics describe every aspect of the system, from global dashboards to CRUD operations on individual objects.
Declarative Configuration Management
Following the Infrastructure as Code philosophy, using declarative configuration to describe the entire environment. You just tell Pigsty “what kind of database cluster you want” without worrying about how to implement it—the system automatically adjusts to the desired state.
Modular Architecture Design
A modular architecture design that can be freely combined to suit different scenarios. Beyond the core PostgreSQL module, it also provides optional modules for Redis, MINIO (Silo), Etcd, and support for various PG-compatible kernels and modes.
Industry-leading security practices: a self-signed CA for encrypted communication, AES-encrypted backups, SCRAM-SHA-256 password hashing, an out-of-the-box ACL model, and least-privilege HBA rules.
Simple and Easy Deployment
All dependencies are pre-packaged for one-click installation in environments without internet access. Local sandbox environments can run on micro VMs with 1 core and 2GB RAM, providing functionality identical to production environments. Provides Vagrant-based local sandboxes and Terraform-based cloud deployments.
Pigsty is not a traditional, all-encompassing PaaS (Platform as a Service) system.
Pigsty doesn’t provide basic hardware resources. It runs on nodes you provide, whether bare metal, VMs, or cloud instances, but it doesn’t create or manage these resources itself (though it provides Terraform templates to simplify cloud resource preparation).
Pigsty is not a container orchestration system. It runs directly on the operating system, not requiring Kubernetes or Docker as infrastructure. Of course, it can coexist with these systems and provides a Docker module for running stateless applications.
Pigsty is not a general database management tool. It focuses on PostgreSQL and its ecosystem. While it also supports peripheral components like Redis, Etcd, and Silo, the core is always built around PostgreSQL.
Pigsty won’t lock you in. It’s built on open-source components, doesn’t modify the PostgreSQL kernel, and introduces no proprietary protocols. You can continue using your well-managed PostgreSQL clusters anytime without Pigsty.
Pigsty doesn’t restrict how you should or shouldn’t build your database services. For example:
Pigsty provides a different level of abstraction than the hardware layer—it works at the database service layer, focusing on how to deliver PostgreSQL at its best, rather than reinventing the wheel.
To understand Pigsty’s value, let’s review the evolution of PostgreSQL deployment approaches.
In traditional deployment, DBAs needed to manually install and configure PostgreSQL, manually set up replication, manually configure monitoring, and manually handle failures. The problems with this approach are obvious:
To solve these problems, cloud providers offer managed database services (RDS). Cloud RDS does solve some operational issues, but also brings new challenges:
Pigsty represents a third approach: building database services in local environments that match or exceed cloud RDS.
Pigsty combines the advantages of both approaches:
This approach is particularly suitable for:
Now that you understand Pigsty’s basic concepts, you can:
Pigsty uses a modular architecture with a declarative interface. You can freely combine modules like building blocks as needed.
Pigsty uses a modular design with six main default modules: PGSQL, INFRA, NODE, ETCD, REDIS, and MINIO.
PGSQL: Self-healing HA Postgres clusters powered by Patroni, Pgbouncer, HAproxy, PgBackrest, and more.INFRA: Local software repo, Nginx, Grafana, Victoria, AlertManager, Blackbox Exporter—the complete observability stack.NODE: Tune nodes to desired state—hostname, timezone, NTP, ssh, sudo, haproxy, docker, vector, keepalived.ETCD: Distributed key-value store as DCS for HA Postgres clusters: consensus leader election/config management/service discovery.REDIS: Redis servers supporting standalone primary-replica, sentinel, and cluster modes with full monitoring.MINIO: S3-compatible simple object storage that can serve as an optional backup destination for PG databases.You can declaratively compose them freely. If you only want host monitoring, installing the INFRA module on infrastructure nodes and the NODE module on managed nodes is sufficient.
The ETCD and PGSQL modules are used to build HA PG clusters—installing these modules on multiple nodes automatically forms a high-availability database cluster.
You can reuse Pigsty infrastructure and develop your own modules; REDIS and MINIO can serve as examples. Protocol compatibility layers such as PostgreSQL Mongo mode are composed from standard PGSQL and Docker APP workflows.
Note that all modules depend strongly on the NODE module: in Pigsty, nodes must first have the NODE module installed to be managed before deploying other modules.
When nodes (by default) use the local software repo for installation, the NODE module has a weak dependency on the INFRA module. Therefore, the admin/infrastructure nodes with the INFRA module complete the bootstrap process in the deploy.yml playbook, resolving the circular dependency.
By default, Pigsty installs on a single node (physical/virtual machine). The deploy.yml playbook installs INFRA, ETCD, PGSQL, and optionally MINIO modules on the current node,
giving you a fully-featured observability stack (VictoriaMetrics, VictoriaLogs, VictoriaTraces, Grafana, Alertmanager, Blackbox Exporter, etc.), plus a built-in PostgreSQL standalone instance as a CMDB, ready to use out of the box (cluster name pg-meta, database name meta).
This node now has a complete self-monitoring system, visualization tools, and a Postgres database with PITR auto-configured (HA unavailable since you only have one node). You can use this node as a devbox, for testing, running demos, and data visualization/analysis. Or, use this node as an admin node to deploy and manage more nodes!
The installed standalone meta node can serve as an admin node and monitoring center to bring more nodes and database servers under its supervision and control.
Pigsty’s monitoring system can be used independently. If you want to install the VictoriaMetrics/Grafana observability stack, Pigsty provides best practices! It offers rich dashboards for host nodes and PostgreSQL databases. Whether or not these nodes or PostgreSQL servers are managed by Pigsty, with simple configuration, you immediately have a production-grade monitoring and alerting system, bringing existing hosts and PostgreSQL under management.
Pigsty helps you own your own production-grade HA PostgreSQL RDS service anywhere.
To create such an HA PostgreSQL cluster/RDS service, you simply describe it with a short config and run the playbook to create it:
In less than 10 minutes, you’ll have a PostgreSQL database cluster with service access, monitoring, backup PITR, and HA fully configured.
Hardware failures are covered by the self-healing HA architecture provided by patroni, etcd, and haproxy—in case of primary failure, automatic failover executes within 45 seconds by default. Clients don’t need to modify config or restart applications: Haproxy uses patroni health checks for traffic distribution, and read-write requests are automatically routed to the new cluster primary, avoiding split-brain issues. This process is seamless—for example, in case of replica failure or planned switchover, clients experience only a momentary flash of the current query.
Software failures, human errors, and datacenter-level disasters are covered by pgBackRest and the optional Silo cluster. This provides local/cloud PITR capabilities and, in case of datacenter failure, offers cross-region replication and disaster recovery.
A node is an abstraction of hardware resources and operating systems. It can be a physical machine, bare metal, virtual machine, or container/pod.
Any machine running a Linux OS (with systemd daemon) and standard CPU/memory/disk/network resources can be treated as a node.
Nodes can have modules installed. Pigsty has several node types, distinguished by which modules are deployed:
| Type | Description |
|---|---|
| Regular Node | A node managed by Pigsty |
| ADMIN Node | The node that runs Ansible to issue management commands |
| INFRA Node | Nodes with the INFRA module installed |
| ETCD Node | Nodes with the ETCD module for DCS |
| MINIO Node | Nodes with the MINIO module for object storage |
| PGSQL Node | Nodes with the PGSQL module installed |
| … | Nodes with other modules… |
In a singleton Pigsty deployment, multiple roles converge on one node: it serves as the regular node, admin node, infra node, ETCD node, and database node simultaneously.
Nodes managed by Pigsty can have modules installed. The node.yml playbook configures nodes to the desired state.
A regular node may run the following services:
| Component | Port | Description | Status |
|---|---|---|---|
node_exporter |
9100 |
Host metrics exporter | Enabled |
haproxy |
9101 |
HAProxy load balancer (admin port) | Enabled |
vector |
9598 |
Log collection agent | Enabled |
docker |
9323 |
Container runtime support | Optional |
keepalived |
n/a |
L2 VIP for node cluster | Optional |
keepalived_exporter |
9650 |
Keepalived status monitor | Optional |
Here, node_exporter exposes host metrics, vector sends logs to the collection system, and haproxy provides load balancing. These three are enabled by default.
Docker, keepalived, and keepalived_exporter are optional and can be enabled as needed.
A Pigsty deployment has exactly one admin node—the node that runs Ansible playbooks and issues control/deployment commands.
This node has ssh/sudo access to all other nodes. Admin node security is critical and access must be strictly controlled; see Security Model: Trust Boundaries for its trust scope and critical assets.
During single-node installation and configuration, the current node becomes the admin node. However, alternatives exist. For example, if your laptop can SSH to all managed nodes and has Ansible installed, it can serve as the admin node—though this isn’t recommended for production.
For instance, you might use your laptop to manage a Pigsty VM in the cloud. In this case, your laptop is the admin node.
In serious production environments, the admin node is typically 1-2 dedicated DBA machines. In resource-constrained setups, INFRA nodes often double as admin nodes since all INFRA nodes have Ansible installed by default.
A Pigsty deployment may have 1 or more INFRA nodes; large production environments typically have 2-3.
The infra group in the inventory defines which nodes are INFRA nodes. These nodes run the INFRA module with these components:
| Component | Port | Description |
|---|---|---|
nginx |
80/443 |
Web UI, local software repository |
grafana |
3000 |
Visualization platform |
victoriaMetrics |
8428 |
Time-series database (metrics) |
victoriaLogs |
9428 |
Log collection server |
victoriaTraces |
10428 |
Trace collection server |
vmalert |
8880 |
Alerting and derived metrics |
alertmanager |
9059 |
Alert aggregation and routing |
blackbox_exporter |
9115 |
Blackbox probing (ping nodes/VIPs) |
dnsmasq |
53 |
Internal DNS resolution |
chronyd |
123 |
NTP time server |
ansible |
- |
Playbook execution |
Nginx serves as the module’s entry point, providing the web UI and local software repository. With multiple INFRA nodes, services on each are independent, but you can access all monitoring data sources from any INFRA node’s Grafana.
Pigsty is licensed under Apache-2.0, though embedded Grafana component uses AGPLv3.
The ETCD module provides Distributed Consensus Service (DCS) for PostgreSQL high availability.
The etcd group in the inventory defines ETCD nodes. These nodes run etcd servers on two ports:
| Component | Port | Description |
|---|---|---|
etcd |
2379 |
ETCD key-value store (client port) |
etcd |
2380 |
ETCD cluster peer communication |
The MINIO module provides optional backup storage for PostgreSQL.
The minio inventory group defines MINIO module nodes. In v4.5.0, these nodes run Silo servers on:
| Component | Port | Description |
|---|---|---|
silo |
9000 |
S3 API endpoint |
silo |
9001 |
Silo admin console |
Nodes with the PGSQL module are called PGSQL nodes. Node and PostgreSQL instance have a 1:1 deployment—one PG instance per node.
PGSQL nodes can borrow identity from their PostgreSQL instance—controlled by node_id_from_pg, defaulting to true, meaning the node name is set to the PG instance name.
PGSQL nodes run these additional components beyond regular node services:
| Component | Port | Description | Status |
|---|---|---|---|
postgres |
5432 |
PostgreSQL database server | Enabled |
pgbouncer |
6432 |
PgBouncer connection pool | Enabled |
patroni |
8008 |
Patroni HA management | Enabled |
pg_exporter |
9630 |
PostgreSQL metrics exporter | Enabled |
pgbouncer_exporter |
9631 |
PgBouncer metrics exporter | Enabled |
pgbackrest_exporter |
9854 |
pgBackRest metrics exporter | Enabled |
vip-manager |
n/a |
Binds L2 VIP to cluster primary | Optional |
{{ pg_cluster }}-primary |
5433 |
HAProxy service: pooled read/write | Enabled |
{{ pg_cluster }}-replica |
5434 |
HAProxy service: pooled read-only | Enabled |
{{ pg_cluster }}-default |
5436 |
HAProxy service: primary direct connection | Enabled |
{{ pg_cluster }}-offline |
5438 |
HAProxy service: offline read | Enabled |
{{ pg_cluster }}-<service> |
543x |
HAProxy service: custom PostgreSQL services | Custom |
The vip-manager is only enabled when users configure a PG VIP.
Additional custom services can be defined in pg_services, exposed via haproxy using additional service ports.
Regular nodes typically reference an INFRA node via the admin_ip parameter as their infrastructure provider.
For example, with global admin_ip = 10.10.10.10, all nodes use infrastructure services at this IP.
Parameters that reference ${admin_ip}:
| Parameter | Module | Default Value | Description |
|---|---|---|---|
repo_endpoint |
INFRA |
http://${admin_ip}:80 |
Software repo URL |
repo_upstream.baseurl |
INFRA |
http://${admin_ip}/pigsty |
Local repo baseurl |
infra_portal.endpoint |
INFRA |
${admin_ip}:<port> |
Nginx proxy backend |
dns_records |
INFRA |
["${admin_ip} i.pigsty", ...] |
DNS records |
node_default_etc_hosts |
NODE |
["${admin_ip} i.pigsty"] |
Default static DNS |
node_etc_hosts |
NODE |
- | Custom static DNS |
node_dns_servers |
NODE |
["${admin_ip}"] |
Dynamic DNS servers |
node_ntp_servers |
NODE |
- | NTP servers (optional) |
Typically the admin node and INFRA node coincide. With multiple INFRA nodes, the admin node is usually the first one; others serve as backups.
In large-scale production deployments, you might separate the Ansible admin node from INFRA module nodes. For example, use 1-2 small dedicated hosts under the DBA team as the control hub (ADMIN nodes), and 2-3 high-spec physical machines as monitoring infrastructure (INFRA nodes).
Typical node counts by deployment scale:
| Scale | ADMIN | INFRA | ETCD | MINIO | PGSQL |
|---|---|---|---|---|---|
| Single-node | 1 | 1 | 1 | 0 | 1 |
| 3-node | 1 | 3 | 3 | 0 | 3 |
| Small prod | 1 | 2 | 3 | 0 | N |
| Large prod | 2 | 3 | 5 | 4+ | N |
Running production-grade, highly available PostgreSQL clusters typically requires a comprehensive set of infrastructure services (foundation) for support, such as monitoring and alerting, log collection, time synchronization, DNS resolution, and local software repositories. Pigsty provides the INFRA module to address this—it’s an optional module, but we strongly recommend enabling it.
The diagram below shows the architecture of a single-node deployment. The right half represents the components included in the INFRA module:
| Component | Type | Description |
|---|---|---|
| Nginx | Web Server | Unified entry for WebUI, local repo, reverse proxy for internal services |
| Repo | Software Repo | APT/DNF repository with all RPM/DEB packages needed for deployment |
| Grafana | Visualization | Displays metrics, logs, and traces; hosts dashboards, reports, and custom data apps |
| VictoriaMetrics | Time Series DB | Scrapes all metrics, Prometheus API compatible, provides VMUI query interface |
| VictoriaLogs | Log Platform | Centralized log storage; all nodes run Vector by default, pushing logs here |
| VictoriaTraces | Tracing | Collects slow SQL, service traces, and other tracing data |
| VMAlert | Eval Rule/Alert | Evaluates alerting rules, pushes events to Alertmanager |
| AlertManager | Alert Manager | Aggregates alerts, dispatches notifications via email, Webhook, etc. |
| BlackboxExporter | Blackbox Probe | Probes reachability of IPs/VIPs/URLs |
| DNSMASQ | DNS Service | Provides DNS resolution for domains used within Pigsty [Optional] |
| Chronyd | Time Sync | Provides NTP time synchronization to ensure consistent time across nodes [Optional] |
| CA | Certificate | Issues encryption certificates within the environment |
| Ansible | Orchestration | Batch, declarative, agentless tool for managing large numbers of servers |
Nginx is the access entry point for all WebUI services in Pigsty, using ports 80 / 443 for HTTP/HTTPS by default. Live Demo
| IP Access (replace) | Domain (HTTP) | Domain (HTTPS) | Public Demo |
|---|---|---|---|
http://10.10.10.10 |
http://i.pigsty |
https://i.pigsty |
https://demo.pigsty.io |
Infrastructure components with WebUIs can be exposed uniformly through Nginx, such as Grafana, VictoriaMetrics (VMUI), AlertManager, and HAProxy console. Additionally, the local software repository and other static resources are served via Nginx.
Nginx configures local web servers or reverse proxy servers based on definitions in infra_portal.
By default, it exposes Pigsty’s admin homepage: i.pigsty. Different endpoints on this page proxy different components:
| Endpoint | Component | Native Port | Notes | Public Demo |
|---|---|---|---|---|
/ |
Nginx | 80/443 |
Homepage, local repo, file server | demo.pigsty.io |
/ui/ |
Grafana | 3000 |
Grafana dashboard entry | demo.pigsty.io/ui/ |
/vmetrics/ |
VictoriaMetrics | 8428 |
Time series DB Web UI | demo.pigsty.io/vmetrics/ |
/vlogs/ |
VictoriaLogs | 9428 |
Log DB Web UI | demo.pigsty.io/vlogs/ |
/vtraces/ |
VictoriaTraces | 10428 |
Tracing Web UI | demo.pigsty.io/vtraces/ |
/vmalert/ |
VMAlert | 8880 |
Alert rule management | demo.pigsty.io/vmalert/ |
/alertmgr/ |
AlertManager | 9059 |
Alert management Web UI | demo.pigsty.io/alertmgr/ |
/blackbox/ |
Blackbox | 9115 |
Blackbox probe |
Pigsty allows rich customization of Nginx as a local file server or reverse proxy, with self-signed or real HTTPS certificates.
For more information, see: Tutorial: Nginx—Expose Web Services via Proxy and Tutorial: Certbot—Request and Renew HTTPS Certificates
Pigsty creates a local software repository on the Infra node during installation to accelerate subsequent software installations. Live Demo
This repository defaults to the /www/pigsty directory,
served by Nginx and mounted at the /pigsty path:
| IP Access (replace) | Domain (HTTP) | Domain (HTTPS) | Public Demo |
|---|---|---|---|
http://10.10.10.10/pigsty |
http://i.pigsty/pigsty |
https://i.pigsty/pigsty |
https://demo.pigsty.io/pigsty |
Pigsty supports offline installation, which essentially pre-copies a prepared local software repository to the target environment.
When Pigsty finds /www/pigsty/repo_complete during deployment, it skips upstream downloads and uses the existing repository directly.
The current source has sow generate this file as both a completion marker and a SHA-256 manifest of repository contents. To force a rebuild, run ./infra.yml -t repo_build -e repo_build=true.
For more information, see: Config: INFRA - REPO
Grafana is the core component of Pigsty’s monitoring system, used for visualizing metrics, logs, and various information. Live Demo
Grafana listens on port 3000 by default and is proxied via Nginx at the /ui path:
| IP Access (replace) | Domain (HTTP) | Domain (HTTPS) | Public Demo |
|---|---|---|---|
http://10.10.10.10/ui |
http://i.pigsty/ui |
https://i.pigsty/ui |
https://demo.pigsty.io/ui |
Pigsty provides pre-built dashboards based on VictoriaMetrics / Logs / Traces, with one-click drill-down and roll-up via URL jumps for rapid troubleshooting.
Grafana can also serve as a low-code visualization platform, so ECharts, victoriametrics-datasource, victorialogs-datasource plugins are installed by default,
with Vector / Victoria datasources registered uniformly as vmetrics-*, vlogs-*, vtraces-* for easy custom dashboard extension.

For more information, see: Config: INFRA - GRAFANA.
VictoriaMetrics is Pigsty’s time series database, responsible for scraping and storing all monitoring metrics. Live Demo
It listens on port 8428 by default, mounted at Nginx /vmetrics path, and also accessible via the p.pigsty domain:
| IP Access (replace) | Domain (HTTP) | Domain (HTTPS) | Public Demo |
|---|---|---|---|
http://10.10.10.10/vmetrics |
http://p.pigsty |
https://i.pigsty/vmetrics |
https://demo.pigsty.io/vmetrics |
VictoriaMetrics is fully compatible with the Prometheus API, supporting PromQL queries, remote read/write protocols, and the Alertmanager API. The built-in VMUI provides an ad-hoc query interface for exploring metrics data directly, and also serves as a Grafana datasource.
For more information, see: Config: INFRA - VMETRICS
VictoriaLogs is Pigsty’s log platform, centrally storing structured logs from all nodes. Live Demo
It listens on port 9428 by default, mounted at Nginx /vlogs path:
| IP Access (replace) | Domain (HTTP) | Domain (HTTPS) | Public Demo |
|---|---|---|---|
http://10.10.10.10/vlogs |
http://i.pigsty/vlogs |
https://i.pigsty/vlogs |
https://demo.pigsty.io/vlogs |
All managed nodes run Vector Agent by default, collecting system logs, PostgreSQL logs, Patroni logs, Pgbouncer logs, etc., processing them into structured format and pushing to VictoriaLogs. The built-in Web UI supports log search and filtering, and can be integrated with Grafana’s victorialogs-datasource plugin for visual analysis.
For more information, see: Config: INFRA - VLOGS
VictoriaTraces is used for collecting trace data and slow SQL records. Live Demo
It listens on port 10428 by default, mounted at Nginx /vtraces path:
| IP Access (replace) | Domain (HTTP) | Domain (HTTPS) | Public Demo |
|---|---|---|---|
http://10.10.10.10/vtraces |
http://i.pigsty/vtraces |
https://i.pigsty/vtraces |
https://demo.pigsty.io/vtraces |
VictoriaTraces provides a Jaeger-compatible interface for analyzing service call chains and database slow queries. Combined with Grafana dashboards, it enables rapid identification of performance bottlenecks and root cause tracing.
For more information, see: Config: INFRA - VTRACES
VMAlert is the alerting rule computation engine, responsible for evaluating alert rules and pushing triggered events to Alertmanager. Live Demo
It listens on port 8880 by default, mounted at Nginx /vmalert path:
| IP Access (replace) | Domain (HTTP) | Domain (HTTPS) | Public Demo |
|---|---|---|---|
http://10.10.10.10/vmalert |
http://i.pigsty/vmalert |
https://i.pigsty/vmalert |
https://demo.pigsty.io/vmalert |
VMAlert reads metrics data from VictoriaMetrics and periodically evaluates alerting rules. Pigsty provides pre-built alerting rules for PGSQL, NODE, REDIS, and other modules, covering common failure scenarios out of the box.
For more information, see: Config: INFRA - VMALERT
AlertManager handles alert event aggregation, deduplication, grouping, and dispatch. Live Demo
It listens on port 9059 by default, mounted at Nginx /alertmgr path, and also accessible via the a.pigsty domain:
| IP Access (replace) | Domain (HTTP) | Domain (HTTPS) | Public Demo |
|---|---|---|---|
http://10.10.10.10/alertmgr |
http://a.pigsty |
https://i.pigsty/alertmgr |
https://demo.pigsty.io/alertmgr |
AlertManager supports multiple notification channels: email, Webhook, Slack, PagerDuty, WeChat Work, etc. Through alert routing rules, differentiated dispatch based on severity level and module type is possible, with support for silencing, inhibition, and other advanced features.
For more information, see: Config: INFRA - AlertManager
Blackbox Exporter is used for active probing of target reachability, enabling blackbox monitoring.
It listens on port 9115 by default, mounted at Nginx /blackbox path:
| IP Access (replace) | Domain (HTTP) | Domain (HTTPS) | Public Demo |
|---|---|---|---|
http://10.10.10.10/blackbox |
http://i.pigsty/blackbox |
https://i.pigsty/blackbox |
https://demo.pigsty.io/blackbox |
It supports multiple probe methods including ICMP Ping, TCP ports, and HTTP/HTTPS endpoints. Useful for monitoring VIP reachability, service port availability, external dependency health, etc.—an important tool for assessing failure impact scope.
For more information, see: Config: INFRA - BLACKBOX
Ansible is Pigsty’s core orchestration tool; all deployment, configuration, and management operations are performed through Ansible Playbooks.
Pigsty automatically installs Ansible on the admin node (Infra node) during installation. It adopts a declarative configuration style and idempotent playbook design: the same playbook can be run repeatedly, and the system automatically converges to the desired state without side effects.
Ansible’s core advantages:
For more information, see: Playbooks: Pigsty Playbook
DNSMASQ provides DNS resolution on INFRA nodes, resolving domain names to their corresponding IP addresses.
DNSMASQ listens on port 53 (UDP/TCP) by default, providing DNS resolution for all nodes. Records are stored in the /etc/dnsmasq.d/pigsty directory.
Other modules automatically register their domain names with DNSMASQ during deployment, which you can use as needed. DNS is completely optional—Pigsty works normally without it. Client nodes can configure INFRA nodes as their DNS servers, allowing access to services via domain names without remembering IP addresses.
dns_records: Default DNS records written to INFRA nodesnode_dns_servers: Configure DNS servers for nodes, defaults to INFRA node via admin_ip (can also be disabled)For more information, see: Config: INFRA - DNS and Tutorial: DNS—Configure Domain Resolution
Chronyd provides NTP time synchronization, ensuring consistent clocks across all nodes. It listens on port 123 (UDP) by default as the time source.
Time synchronization is critical for distributed systems: log analysis requires aligned timestamps, certificate validation depends on accurate clocks, and PostgreSQL streaming replication is sensitive to clock drift. In isolated network environments, the INFRA node can serve as an internal NTP server with other nodes synchronizing to it.
In Pigsty, all nodes run chronyd by default for time sync. The default upstream is pool.ntp.org public NTP servers.
Chronyd is essentially managed by the Node module, but in isolated networks, you can use admin_ip to point to the INFRA node’s Chronyd service as the internal time source.
In this case, the Chronyd service on the INFRA node serves as the internal time synchronization infrastructure.
For more information, see: Config: NODE - TIME
In Pigsty, the relationship between nodes and infrastructure is a weak circular dependency: node_monitor → infra → node
The NODE module itself doesn’t depend on the INFRA module, but the monitoring functionality (node_monitor) requires the monitoring platform and services provided by the infrastructure module.
Therefore, in the infra.yml and deploy playbooks, an “interleaved deployment” technique is used:
If you don’t need “one-shot” deployment of all nodes, you can use phased deployment: initialize INFRA nodes first, then regular nodes.
Regular nodes reference an INFRA node via the admin_ip parameter as their infrastructure provider.
For example, when you configure global admin_ip = 10.10.10.10, all nodes will typically use infrastructure services at this IP.
This design allows quick, batch switching of infrastructure providers. Parameters that may reference ${admin_ip}:
| Parameter | Module | Default Value | Description |
|---|---|---|---|
repo_endpoint |
INFRA |
http://${admin_ip}:80 |
Software repo URL |
repo_upstream.baseurl |
INFRA |
http://${admin_ip}/pigsty |
Local repo baseurl |
infra_portal.endpoint |
INFRA |
${admin_ip}:<port> |
Nginx proxy backend |
dns_records |
INFRA |
["${admin_ip} i.pigsty", ...] |
DNS records |
node_default_etc_hosts |
NODE |
["${admin_ip} i.pigsty"] |
Default static DNS |
node_etc_hosts |
NODE |
[] |
Custom static DNS |
node_dns_servers |
NODE |
["${admin_ip}"] |
Dynamic DNS servers |
node_ntp_servers |
NODE |
["pool pool.ntp.org iburst"] |
NTP servers (optional) |
For example, when a node installs software, the local repo points to the Nginx local software repository at admin_ip:80/pigsty. The DNS server also points to DNSMASQ at admin_ip:53.
However, this isn’t mandatory—nodes can ignore the local repo and install directly from upstream internet sources (most single-node config templates); DNS servers can also remain unconfigured, as Pigsty has no DNS dependency.
The management-initiating ADMIN node typically coincides with the INFRA node.
In single-node deployment, this is exactly the case. In multi-node deployment with multiple INFRA nodes, the admin node is usually the first in the infra group; others serve as backups.
However, exceptions exist. You might separate them for various reasons:
For example, in large-scale production deployments, a classic pattern uses 1-2 dedicated management hosts (tiny VMs suffice) belonging to the DBA team as the control hub, with 2-3 high-spec physical machines (or more!) as monitoring infrastructure. Here, admin nodes are separate from infrastructure nodes. In this case, the admin_ip in your config should point to an INFRA node’s IP, not the current ADMIN node’s IP. This is for historical reasons: initially ADMIN and INFRA nodes were tightly coupled concepts, with separation capabilities evolving later, so the parameter name wasn’t changed.
Another common scenario is managing cloud nodes locally. For example, you can install Ansible on your laptop and specify cloud nodes as “managed targets.” In this case, your laptop acts as the ADMIN node, while cloud servers act as INFRA nodes.
By default, Pigsty only needs one INFRA node for most requirements. Even if the INFRA module goes down, it won’t affect database services on other nodes.
However, in production environments with high monitoring and alerting requirements, you may want multiple INFRA nodes to improve infrastructure availability. A common deployment uses two Infra nodes for redundancy, monitoring each other… or more nodes to deploy a distributed Victoria cluster for unlimited horizontal scaling.
Each Infra node is independent—Nginx points to services on the local machine. VictoriaMetrics independently scrapes metrics from all services in the environment, and logs are pushed to all VictoriaLogs collection endpoints by default. The only exception is Grafana: every Grafana instance registers all VictoriaMetrics / Logs / Traces / PostgreSQL instances as datasources. Therefore, each Grafana instance can see complete monitoring data.
If you modify Grafana—such as adding new dashboards or changing datasource configs—these changes only affect the Grafana instance on that node. To keep Grafana consistent across all nodes, use a PostgreSQL database as shared storage. See Tutorial: Configure Grafana High Availability for details.
The PGSQL module organizes PostgreSQL in production as clusters—logical entities composed of a group of database instances associated by primary-replica relationships.
The PGSQL module includes the following components, working together to provide production-grade PostgreSQL HA cluster services:
| Component | Type | Description |
|---|---|---|
postgres |
Database | The world’s most advanced open-source relational database, PGSQL core |
patroni |
HA | Manages PostgreSQL, coordinates failover, leader election, config changes |
pgbouncer |
Pool | Lightweight connection pooling middleware, reduces overhead, adds flexibility |
pgbackrest |
Backup | Full/incremental backup and WAL archiving, supports local and object storage |
pg_exporter |
Metrics | Exports PostgreSQL monitoring metrics in a Prometheus-compatible format |
pgbouncer_exporter |
Metrics | Exports Pgbouncer connection pool metrics |
pgbackrest_exporter |
Metrics | Exports backup status metrics |
vip-manager |
VIP | Binds L2 VIP to current primary node for transparent failover [Optional] |
The vip-manager is an on-demand component. Additionally, PGSQL uses components from other modules:
| Component | Module | Type | Description |
|---|---|---|---|
haproxy |
NODE | LB | Exposes service ports, routes traffic to primary or replicas |
vector |
NODE | Logging | Collects PostgreSQL, Patroni, Pgbouncer logs and ships to center |
etcd |
ETCD | DCS | Distributed consistent store for cluster metadata and leader info |
By analogy, the PostgreSQL database kernel is the CPU, while the PGSQL module packages it as a complete computer. Patroni and Etcd form the HA subsystem, while pgBackRest and optional Silo form the backup subsystem. HAProxy, Pgbouncer, and vip-manager form the access subsystem. Various Exporters and Vector build the observability subsystem; finally, you can swap different kernel CPUs and extension cards.

| Subsystem | Components | Function |
|---|---|---|
| HA Subsystem | Patroni + etcd | Failure detection, auto-failover, config management |
| Access Subsystem | HAProxy + Pgbouncer + vip-manager | Service exposure, load balancing, pooling, VIP |
| Backup Subsystem | pgBackRest (+ Silo) | Full/incremental backup, WAL archiving, PITR |
| Observability Subsystem | pg_exporter / pgbouncer_exporter / pgbackrest_exporter + Vector | Metrics collection, log aggregation |
pg_vip_address to the cluster primary node.
pgbackrest_method = local)
local (default), pgBackRest creates local repository under pg_fs_bkup on primary nodeminio, pgBackRest creates the backup repository on dedicated Silo or an external S3 serviceThe HA subsystem consists of Patroni and etcd, responsible for PostgreSQL cluster failure detection, automatic failover, and configuration management.
How it works: Patroni runs on each node, managing the local PostgreSQL process and writing cluster state (leader, members, config) to etcd. When the primary fails, Patroni coordinates election via etcd, promoting the healthiest replica to new primary. The entire process is automatic, with RTO typically under 45 seconds.
Key Interactions:
:8008), reporting instance roleFor more information, see: High Availability and Config: PGSQL - PG_BOOTSTRAP
The access subsystem consists of HAProxy, Pgbouncer, and vip-manager, responsible for service exposure, traffic routing, and connection pooling.
There are multiple access methods. A typical traffic path is: Client → DNS/VIP → HAProxy (543x) → Pgbouncer (6432) → PostgreSQL (5432)
| Layer | Component | Port | Role |
|---|---|---|---|
| L2 VIP | vip-manager | - | Binds L2 VIP to primary (optional) |
| L4 Load Bal | HAProxy | 543x | Service exposure, load balancing, health checks |
| L7 Pool | Pgbouncer | 6432 | Connection reuse, session management, transaction pooling |
Service Ports:
5433 primary: Read-write service, routes to primary Pgbouncer5434 replica: Read-only service, routes to replica Pgbouncer5436 default: Default service, direct to primary (bypasses pool)5438 offline: Offline service, direct to offline replica (ETL/analytics)Key Features:
For more information, see: Service Access and Config: PGSQL - PG_ACCESS
The backup subsystem consists of pgBackRest (optionally with Silo or external S3 as a remote repository), responsible for data backup and point-in-time recovery (PITR).
Backup Types:
Storage Backends:
local (default): Local disk, backups stored at pg_fs_bkup mount pointminio: S3-compatible object storage, supports centralized backup management and off-site DRKey Interactions:
For more information, see: PITR, Backup & Recovery, and Config: PGSQL - PG_BACKUP
The observability subsystem consists of three Exporters and Vector, responsible for metrics collection and log aggregation.
| Component | Port | Target | Key Metrics |
|---|---|---|---|
| pg_exporter | 9630 |
PostgreSQL | Sessions, transactions, replication lag, buffer hits |
| pgbouncer_exporter | 9631 |
Pgbouncer | Pool utilization, wait queue, hit rate |
| pgbackrest_exporter | 9854 |
pgBackRest | Latest backup time, size, type |
| vector | 9598 |
postgres/patroni/pgbouncer logs | Structured log stream |
Data Flow:
pg_exporter / pgbouncer_exporter connect to target services via local Unix socket, decoupled from HA topology. In slim install mode, these components can be disabled.
For more information, see: Config: PGSQL - PG_MONITOR
PostgreSQL is the PGSQL module core, listening on port 5432 by default for relational database services, deployed 1:1 with nodes.
Pigsty currently supports PostgreSQL 14-18 (lifecycle major versions), installed via binary packages from the PGDG official repo. Pigsty also allows you to use other PG kernel forks to replace the default PostgreSQL kernel, and install up to 575 extension plugins on top of the PG kernel.
PostgreSQL processes are managed by default by the HA agent—Patroni. When a cluster has only one node, that instance is the primary; when the cluster has multiple nodes, other instances automatically join as replicas: through physical replication, syncing data changes from the primary in real-time. Replicas can handle read-only requests and automatically take over when the primary fails.
You can access PostgreSQL directly, or through HAProxy and Pgbouncer connection pool.
For more information, see: Config: PGSQL - PG_BOOTSTRAP
Patroni is the PostgreSQL HA control component, listening on port 8008 by default.
Patroni takes over PostgreSQL startup, shutdown, configuration, and health status, writing leader and member information to etcd. It handles automatic failover, maintains replication factor, coordinates parameter changes, and provides a REST API for HAProxy, monitoring, and administrators.
HAProxy uses Patroni health check endpoints to determine instance roles and route traffic to the correct primary or replica. vip-manager monitors the leader key in etcd and automatically migrates the VIP when the primary changes.
For more information, see: Config: PGSQL - PG_BOOTSTRAP
Pgbouncer is a lightweight connection pooling middleware, listening on port 6432 by default, deployed 1:1 with PostgreSQL database and node.
Pgbouncer runs statelessly on each instance, connecting to PostgreSQL via local Unix socket, using Transaction Pooling by default for pool management, absorbing burst client connections, stabilizing database sessions, reducing lock contention, and significantly improving performance under high concurrency.
Pigsty routes production traffic (read-write service 5433 / read-only service 5434) through Pgbouncer by default,
while only the default service (5436) and offline service (5438) bypass the pool for direct PostgreSQL connections.
Pool mode is controlled by pgbouncer_poolmode, defaulting to transaction (transaction-level pooling).
Connection pooling can be disabled via pgbouncer_enabled.
For more information, see: Config: PGSQL - PG_ACCESS
pgBackRest is a professional PostgreSQL backup/recovery tool, one of the strongest in the PG ecosystem, supporting full/incremental/differential backup and WAL archiving.
Pigsty uses pgBackRest for PostgreSQL PITR capability, allowing you to roll back clusters to any point within the backup retention window.
pgBackRest works with PostgreSQL to create backup repositories on the primary, executing backup and archive tasks.
By default, it uses local backup repository (pgbackrest_method = local),
but can be configured for Silo or external S3 object storage for centralized backup management.
After initialization, pgbackrest_init_backup can automatically trigger the first full backup.
Recovery integrates with Patroni, supporting bootstrapping replicas as new primaries or standbys.
For more information, see: Backup & Recovery and Config: PGSQL - PG_BACKUP
HAProxy is the service entry point and load balancer, exposing multiple database service ports.
| Port | Service | Target | Description |
|---|---|---|---|
9101 |
Admin | - | HAProxy statistics and admin page |
5433 |
primary | Primary Pgbouncer | Read-write service, routes to primary pool |
5434 |
replica | Replica Pgbouncer | Read-only service, routes to replica pool |
5436 |
default | Primary Postgres | Default service, direct to primary (bypasses pool) |
5438 |
offline | Offline Postgres | Offline service, direct to offline replica (ETL/analytics) |
HAProxy uses Patroni REST API health checks to determine instance roles and route traffic to the appropriate primary or replica.
Service definitions are composed from pg_default_services and pg_services.
A dedicated HAProxy node group can be specified via pg_service_provider to handle higher traffic;
by default, HAProxy on local nodes publishes services.
For more information, see: Service Access and Config: PGSQL - PG_ACCESS
vip-manager binds L2 VIP to the current primary node. This is an optional component; enable it if your network supports L2 VIP.
vip-manager runs on each PG node, monitoring the leader key written by Patroni in etcd,
and binds pg_vip_address to the current primary node’s network interface.
When cluster failover occurs, vip-manager immediately releases the VIP from the old primary and rebinds it on the new primary, switching traffic to the new primary.
This component is optional, enabled via pg_vip_enabled.
When enabled, ensure all nodes are in the same VLAN; otherwise, VIP migration will fail.
Public cloud networks typically don’t support L2 VIP; it’s recommended only for on-premises and private cloud environments.
For more information, see: Tutorial: VIP Configuration and Config: PGSQL - PG_ACCESS
pg_exporter exports PostgreSQL monitoring metrics, listening on port 9630 by default.
pg_exporter runs on each PG node, connecting to PostgreSQL via local Unix socket, exporting rich metrics covering sessions, buffer hits, replication lag, transaction rates, etc., scraped by VictoriaMetrics on INFRA nodes.
Collection configuration is specified by pg_exporter_config,
with support for automatic database discovery (pg_exporter_auto_discovery),
and tiered cache strategies via pg_exporter_cache_ttls.
You can disable this component via parameters; in slim install, this component is not enabled.
For more information, see: Config: PGSQL - PG_MONITOR
pgbouncer_exporter exports Pgbouncer connection pool metrics, listening on port 9631 by default.
pgbouncer_exporter uses the same pg_exporter binary but with a dedicated metrics config file, supporting pgbouncer 1.8-1.25+.
pgbouncer_exporter reads Pgbouncer statistics views, providing pool utilization, wait queue, and hit rate metrics.
If Pgbouncer is disabled, this component is also disabled. In slim install, this component is not enabled.
For more information, see: Config: PGSQL - PG_MONITOR
pgbackrest_exporter exports backup status metrics, listening on port 9854 by default.
pgbackrest_exporter parses pgBackRest status, generating metrics for most recent backup time, size, type, etc. Combined with alerting policies, it quickly detects expired or failed backups, ensuring data safety. Note that when there are many backups or using large network repositories, collection overhead can be significant, so pgbackrest_exporter has a default 2-minute collection interval. In the worst case, you may see the latest backup status in the monitoring system 2 minutes after a backup completes.
For more information, see: Config: PGSQL - PG_MONITOR
etcd is a distributed consistent store (DCS), providing cluster metadata storage and leader election capability for Patroni.
etcd is deployed and managed by the independent ETCD module, not part of the PGSQL module itself, but critical for PostgreSQL HA. Patroni writes cluster state, leader info, and config parameters to etcd; all nodes reach consensus through etcd. vip-manager also reads the leader key from etcd to enable automatic VIP migration.
For more information, see: ETCD Module
Vector is a high-performance log collection component, deployed by the NODE module, responsible for collecting PostgreSQL-related logs.
Vector runs on nodes, tracking PostgreSQL, Pgbouncer, Patroni, and pgBackRest log directories, sending structured logs to VictoriaLogs on INFRA nodes for centralized storage and querying.
For more information, see: NODE Module
The largest entity concept in Pigsty is a Deployment. The main entities and relationships (E-R diagram) in a deployment are shown below:
A deployment can also be understood as an Environment. For example, Production (Prod), User Acceptance Testing (UAT), Staging, Testing, Development (Devbox), etc. Each environment corresponds to a Pigsty inventory that describes all entities and attributes in that environment.
Typically, an environment includes shared infrastructure (INFRA), which broadly includes ETCD (HA DCS) and MINIO (centralized backup repository),
serving multiple PostgreSQL database clusters (and other database module components). (Exception: there are also deployments without infrastructure)
In Pigsty, almost all database modules are organized as “Clusters”. Each cluster is an Ansible group containing several node resources. For example, PostgreSQL HA database clusters, Redis, Etcd, and Silo all exist as clusters. An environment can contain multiple clusters.
The INFRA module plays a special role in Pigsty: it’s not a traditional “cluster” but rather a management hub composed of a group of infrastructure nodes, providing core services for the entire Pigsty deployment. Each INFRA node is an autonomous infrastructure service unit running core components like Nginx, Grafana, and VictoriaMetrics, collectively providing observability and management capabilities for managed database clusters.
There are two core entities in Pigsty’s INFRA module:
INFRA nodes typically serve as Admin Nodes, the control plane of Pigsty.
Each INFRA node runs the following core components:
| Component | Port | Description |
|---|---|---|
| Nginx | 80/443 |
Web portal, local repo, unified reverse proxy |
| Grafana | 3000 |
Visualization platform, dashboards, data apps |
| VictoriaMetrics | 8428 |
Time-series database, Prometheus API compatible |
| VictoriaLogs | 9428 |
Log database, receives structured logs from Vector |
| VictoriaTraces | 10428 |
Trace storage for slow SQL / request tracing |
| VMAlert | 8880 |
Alert rule evaluator based on VictoriaMetrics |
| Alertmanager | 9059 |
Alert aggregation and dispatch |
| Blackbox Exporter | 9115 |
ICMP/TCP/HTTP black-box probing |
| DNSMASQ | 53 |
DNS server for internal domain resolution |
| Chronyd | 123 |
NTP time server |
These components together form Pigsty’s observability infrastructure.
Let’s look at a concrete example with a two-node INFRA deployment:
The above config fragment defines a two-node INFRA deployment:
| Group | Description |
|---|---|
infra |
INFRA infrastructure node group |
| Node | Description |
infra-1 |
10.10.10.10 INFRA node #1 |
infra-2 |
10.10.10.11 INFRA node #2 |
For production environments, deploying at least two INFRA nodes is recommended for infrastructure component redundancy.
Pigsty uses the INFRA_ID parameter group to assign deterministic identities to each INFRA module entity. One parameter is required:
| Parameter | Type | Level | Description | Format |
|---|---|---|---|---|
infra_seq |
int |
Node | INFRA node sequence, required | Natural number, starting from 1, unique within group |
With node sequence assigned at node level, Pigsty automatically generates unique identifiers for each entity based on rules:
| Entity | Generation Rule | Example |
|---|---|---|
| Node | infra-{{ infra_seq }} |
infra-1, infra-2 |
The INFRA module assigns infra-N format identifiers to nodes for distinguishing multiple infrastructure nodes in the monitoring system.
However, this doesn’t change the node’s hostname or system identity; nodes still use their existing hostname or IP address for identification.
INFRA nodes provide unified web service entry through Nginx. The infra_portal parameter defines services exposed through Nginx.
The default configuration only defines the home server:
Pigsty automatically configures reverse proxy endpoints for enabled components (Grafana, VictoriaMetrics, AlertManager, etc.). If you need to access these services via separate domains, you can explicitly add configurations:
| Domain | Service | Description |
|---|---|---|
i.pigsty |
Home | Pigsty homepage |
g.pigsty |
Grafana | Monitoring dashboard |
p.pigsty |
VictoriaMetrics | TSDB Web UI |
a.pigsty |
Alertmanager | Alert management UI |
Accessing Pigsty services via domain names is recommended over direct IP + port.
The number of INFRA nodes depends on deployment scale and HA requirements:
| Scale | INFRA Nodes | Description |
|---|---|---|
| Dev/Test | 1 | Single-node deployment, all on one node |
| Small Prod | 1-2 | Single or dual node, can share with other services |
| Medium Prod | 2-3 | Dedicated INFRA nodes, redundant components |
| Large Prod | 3+ | Multiple INFRA nodes, component separation |
In singleton deployment, INFRA components share the same node with PGSQL, ETCD, etc.
In small-scale deployments, INFRA nodes typically also serve as “Admin Node” / backup admin node and local software repository (/www/pigsty).
In larger deployments, these responsibilities can be separated to dedicated nodes.
Pigsty’s monitoring system collects metrics from INFRA components themselves. Unlike database modules, each component in the INFRA module is treated as an independent monitoring object, distinguished by the cls (class) label.
| Label | Description | Example |
|---|---|---|
cls |
Component type, each forming a “class” | nginx |
ins |
Instance name, format {component}-{infra_seq} |
nginx-1 |
ip |
INFRA node IP running the component | 10.10.10.10 |
job |
VictoriaMetrics scrape job, fixed as infra |
infra |
Using a two-node INFRA deployment (infra_seq: 1 and infra_seq: 2) as example, component monitoring labels are:
| Component | cls |
ins Example |
Port |
|---|---|---|---|
| Nginx | nginx |
nginx-1, nginx-2 |
9113 |
| Grafana | grafana |
grafana-1, grafana-2 |
3000 |
| VictoriaMetrics | vmetrics |
vmetrics-1, vmetrics-2 |
8428 |
| VictoriaLogs | vlogs |
vlogs-1, vlogs-2 |
9428 |
| VictoriaTraces | vtraces |
vtraces-1, vtraces-2 |
10428 |
| VMAlert | vmalert |
vmalert-1, vmalert-2 |
8880 |
| Alertmanager | alertmanager |
alertmanager-1, alertmanager-2 |
9059 |
| Blackbox | blackbox |
blackbox-1, blackbox-2 |
9115 |
All INFRA component metrics use a unified job="infra" label, distinguished by the cls label:
The PGSQL module organizes PostgreSQL in production as clusters—logical entities composed of a group of database instances associated by primary-replica relationships.
Each cluster is an autonomous business unit consisting of at least one primary instance, exposing capabilities through services.
There are four core entities in Pigsty’s PGSQL module:
Along with two business entities—“Database” and “Role”—these form the complete logical view as shown below:
Let’s look at two concrete examples. Using the four-node Pigsty sandbox, there’s a three-node pg-test cluster:
The above config fragment defines a high-availability PostgreSQL cluster with these related entities:
| Cluster | Description |
|---|---|
pg-test |
PostgreSQL 3-node HA cluster |
| Instance | Description |
pg-test-1 |
PostgreSQL instance #1, default primary |
pg-test-2 |
PostgreSQL instance #2, initial replica |
pg-test-3 |
PostgreSQL instance #3, initial replica |
| Service | Description |
pg-test-primary |
Read-write service (routes to primary pgbouncer) |
pg-test-replica |
Read-only service (routes to replica pgbouncer) |
pg-test-default |
Direct read-write service (routes to primary postgres) |
pg-test-offline |
Offline read service (routes to dedicated postgres) |
| Node | Description |
node-1 |
10.10.10.11 Node #1, hosts pg-test-1 PG instance |
node-2 |
10.10.10.12 Node #2, hosts pg-test-2 PG instance |
node-3 |
10.10.10.13 Node #3, hosts pg-test-3 PG instance |

Pigsty uses the PG_ID parameter group to assign deterministic identities to each PGSQL module entity. Three parameters are required:
| Parameter | Type | Level | Description | Format |
|---|---|---|---|---|
pg_cluster |
string |
Cluster | PG cluster name, required | Valid DNS name, regex [a-zA-Z0-9-]+ |
pg_seq |
int |
Instance | PG instance number, required | Natural number, starting from 0 or 1, unique within cluster |
pg_role |
enum |
Instance | PG instance role, required | Enum: primary, replica, offline |
With cluster name defined at cluster level and instance number/role assigned at instance level, Pigsty automatically generates unique identifiers for each entity based on rules:
| Entity | Generation Rule | Example |
|---|---|---|
| Instance | {{ pg_cluster }}-{{ pg_seq }} |
pg-test-1, pg-test-2, pg-test-3 |
| Service | {{ pg_cluster }}-{{ pg_role }} |
pg-test-primary, pg-test-replica, pg-test-offline |
| Node | Explicitly specified or borrowed from PG | pg-test-1, pg-test-2, pg-test-3 |
Because Pigsty adopts a 1:1 exclusive deployment model for nodes and PG instances, by default the host node identifier borrows from the PG instance identifier (node_id_from_pg).
You can also explicitly specify nodename to override, or disable nodename_overwrite to use the current default.
When using multiple PostgreSQL clusters (sharding) to serve the same business, two additional identity parameters are used: pg_shard and pg_group.
In this case, this group of PostgreSQL clusters shares the same pg_shard name with their own pg_group numbers, like this Citus cluster:
In this case, pg_cluster cluster names are typically composed of: {{ pg_shard }}{{ pg_group }}, e.g., pg-citus0, pg-citus1, etc.
Pigsty provides dedicated monitoring dashboards for horizontal sharding clusters, making it easy to compare performance and load across shards, but this requires using the above entity naming convention.
There are also other identity parameters for special scenarios, such as pg_upstream for specifying backup clusters/cascading replication upstream, gp_role for Greenplum cluster identity,
pg_exporters for external monitoring instances, pg_offline_query for offline query instances, etc. See PG_ID parameter docs.
Pigsty provides an out-of-box monitoring system that uses the above identity parameters to identify various PostgreSQL entities.
For example, the cls, ins, ip labels correspond to cluster name, instance name, and node IP—the identifiers for these three core entities.
They appear along with the job label in all native monitoring metrics collected by VictoriaMetrics and VictoriaLogs log streams.
The job name for collecting PostgreSQL metrics is fixed as pgsql;
The job name for monitoring remote PG instances is fixed as pgrds.
The job name for collecting PostgreSQL CSV logs is fixed as postgres;
The job name for collecting pgbackrest logs is fixed as pgbackrest, other PG components collect logs via job: syslog.
Additionally, some entity identity labels appear in specific entity-related monitoring metrics, such as:
datname: Database name, if a metric belongs to a specific database.relname: Table name, if a metric belongs to a specific table.idxname: Index name, if a metric belongs to a specific index.funcname: Function name, if a metric belongs to a specific function.seqname: Sequence name, if a metric belongs to a specific sequence.query: Query fingerprint, if a metric belongs to a specific query.The ETCD module organizes ETCD in production as clusters—logical entities composed of a group of ETCD instances associated through the Raft consensus protocol.
Each cluster is an autonomous distributed key-value storage unit consisting of at least one ETCD instance, exposing service capabilities through client ports.
There are three core entities in Pigsty’s ETCD module:
Compared to PostgreSQL clusters, the ETCD cluster model is simpler, without Services or complex Role distinctions. All ETCD instances are functionally equivalent, electing a Leader through the Raft protocol while others become Followers. During scale-out intermediate states, non-voting Learner instance members are also allowed.
Let’s look at a concrete example with a three-node ETCD cluster:
The above config fragment defines a three-node ETCD cluster with these related entities:
| Cluster | Description |
|---|---|
etcd |
ETCD 3-node HA cluster |
| Instance | Description |
etcd-1 |
ETCD instance #1 |
etcd-2 |
ETCD instance #2 |
etcd-3 |
ETCD instance #3 |
| Node | Description |
10.10.10.10 |
Node #1, hosts etcd-1 instance |
10.10.10.11 |
Node #2, hosts etcd-2 instance |
10.10.10.12 |
Node #3, hosts etcd-3 instance |
Pigsty uses the ETCD parameter group to assign deterministic identities to each ETCD module entity. Two parameters are required:
| Parameter | Type | Level | Description | Format |
|---|---|---|---|---|
etcd_cluster |
string |
Cluster | ETCD cluster name, required | Valid DNS name, defaults to fixed etcd |
etcd_seq |
int |
Instance | ETCD instance number, required | Natural number, starting from 1, unique within cluster |
With cluster name defined at cluster level and instance number assigned at instance level, Pigsty automatically generates unique identifiers for each entity based on rules:
| Entity | Generation Rule | Example |
|---|---|---|
| Instance | {{ etcd_cluster }}-{{ etcd_seq }} |
etcd-1, etcd-2, etcd-3 |
The ETCD module does not assign additional identity to host nodes; nodes are identified by their existing hostname or IP address.
Each ETCD instance listens on the following two ports:
| Port | Parameter | Purpose |
|---|---|---|
| 2379 | etcd_port |
Client port, accessed by Patroni, vip-manager, etc. |
| 2380 | etcd_peer_port |
Peer communication port, used for Raft consensus |
ETCD clusters enable TLS-encrypted communication by default and use RBAC authentication. Clients need the correct certificates and passwords to access ETCD services.
As a distributed coordination service, ETCD cluster size directly affects availability, requiring more than half (quorum) of nodes to be alive to maintain service.
| Cluster Size | Quorum | Fault Tolerance | Use Case |
|---|---|---|---|
| 1 node | 1 | 0 | Dev, test, demo |
| 3 nodes | 2 | 1 | Small-medium production |
| 5 nodes | 3 | 2 | Large-scale production |
Even-member ETCD clusters are technically valid, but they do not tolerate more failures than an odd cluster with one fewer member and add deployment and quorum cost. Production clusters therefore usually have one, three, or five members; clusters larger than five are uncommon.
Pigsty provides an out-of-box monitoring system that uses the above identity parameters to identify various ETCD entities.
For example, the cls, ins, ip labels correspond to cluster name, instance name, and node IP—the identifiers for these three core entities.
They appear along with the job label in all ETCD monitoring metrics collected by VictoriaMetrics.
The job name for collecting ETCD metrics is fixed as etcd.
MINIO is Pigsty’s compatibility module name for object storage. The current v4.5.0 source deploys Silo through minio_type: silo and organizes a group of object-storage instances into a cluster.
Each cluster is an autonomous S3-compatible object-storage unit consisting of at least one instance and exposing service through the S3 API port.
There are three core entities in Pigsty’s MINIO module:
Silo also retains the Storage Pool concept for expansion.
Silo supports Pigsty’s three inventory deployment modes:
| Mode | Code | Description | Use Case |
|---|---|---|---|
| Single-Node Single-Drive | SNSD | Single node, single data directory or disk | Dev, test, demo |
| Single-Node Multi-Drive | SNMD | Single node, multiple disks, typically 4+ | Resource-constrained small deployments |
| Multi-Node Multi-Drive | MNMD | Multiple nodes, multiple disks per node | Production recommended |
SNSD mode can use a regular directory for quick experimentation. Multi-drive Silo deployments should use real disk mount points or the service will refuse to start.
The following example explicitly selects the current default Silo backend and defines a four-node multi-drive cluster:
This config fragment defines a four-node Silo cluster with four disks per node. Instance identifiers retain the MINIO module’s compatibility naming:
| Cluster | Description |
|---|---|
minio |
Silo 4-node HA cluster |
| Instance | Description |
minio-1 |
Object-storage instance #1, managing 4 disks |
minio-2 |
Object-storage instance #2, managing 4 disks |
minio-3 |
Object-storage instance #3, managing 4 disks |
minio-4 |
Object-storage instance #4, managing 4 disks |
| Node | Description |
10.10.10.10 |
Node #1, hosts minio-1 instance |
10.10.10.11 |
Node #2, hosts minio-2 instance |
10.10.10.12 |
Node #3, hosts minio-3 instance |
10.10.10.13 |
Node #4, hosts minio-4 instance |
Pigsty uses the MINIO parameter group to assign deterministic identities to each MinIO module entity. Two parameters are required:
| Parameter | Type | Level | Description | Format |
|---|---|---|---|---|
minio_cluster |
string |
Cluster | Object-storage cluster name, required | Valid non-empty name, no default |
minio_seq |
int |
Instance | Object-storage instance number, required | Natural number, starting from 1, unique within cluster |
With cluster name defined at cluster level and instance number assigned at instance level, Pigsty automatically generates unique identifiers for each entity based on rules:
| Entity | Generation Rule | Example |
|---|---|---|
| Instance | {{ minio_cluster }}-{{ minio_seq }} |
minio-1, minio-2, minio-3, minio-4 |
The MINIO module does not assign additional identity to host nodes; nodes are identified by their existing hostname or IP address.
The minio_node parameter generates node names for internal Silo cluster use (written to /etc/hosts for cluster discovery), not host-node identity.
Roles locate actual members across the entire inventory by minio_cluster; the Ansible group name does not need to match the cluster name. minio_type is a retained backend selector and currently must be silo.
Beyond identity parameters, the following parameters are critical for Silo cluster configuration:
| Parameter | Type | Description |
|---|---|---|
minio_type |
enum |
Retained selector; currently only silo |
minio_data |
path |
Data directory, use {x...y} for multi-drive |
minio_node |
string |
Node name pattern for multi-node deployment |
minio_domain |
string |
Service domain, defaults to sss.pigsty |
These parameters determine minio_volumes, which the role writes to Silo’s MINIO_VOLUMES:
minio_data value, e.g., /data/miniominio_data directories, e.g., /data{1...4}minio_node and minio_data, e.g., https://minio-{1...4}.pigsty:9000/data{1...4}Each object-storage instance listens on the following ports:
| Port | Parameter | Purpose |
|---|---|---|
| 9000 | minio_port |
S3 API service port |
| 9001 | minio_admin_port |
Web admin console port |
The MINIO module enables HTTPS by default, controlled by minio_https. Keep HTTPS enabled with the default pgBackRest S3 repository configuration and install the Pigsty CA correctly.
Clients can reach a multi-node Silo cluster through any member. For a stable entry point, use a load balancer such as HAProxy with a VIP.
After Silo cluster deployment, Pigsty automatically creates the following resources (controlled by minio_provision):
Default Buckets (defined by minio_buckets):
| Bucket | Purpose |
|---|---|
pgsql |
PostgreSQL pgBackREST backup storage |
meta |
Metadata storage, versioning enabled |
data |
General data storage |
Default Users (defined by minio_users):
| User | Default Password | Policy | Purpose |
|---|---|---|---|
pgbackrest |
S3User.Backup |
pgsql |
PostgreSQL backup dedicated user |
s3user_meta |
S3User.Meta |
meta |
Access meta bucket |
s3user_data |
S3User.Data |
data |
Access data bucket |
These passwords are publicly documented default credentials, intended only for demonstrations and local development. Replace them before production deployment.
pgbackrest is used for PostgreSQL cluster backups; s3user_meta and s3user_data are reserved users not actively used.
Pigsty uses the identity parameters above to identify object-storage entities. A Silo availability series looks like this:
Here cls, ins, and ip identify the cluster name, instance name, and node IP. Compatible monitoring naming keeps job="minio", while the current backend label is flavor=silo. See the metric list for details.
The Redis module organizes Redis in production as clusters—logical entities composed of a group of Redis instances deployed on one or more nodes.
Each cluster is an autonomous high-performance cache/storage unit consisting of at least one Redis instance, exposing service capabilities through ports.
There are three core entities in Pigsty’s Redis module:
Unlike PostgreSQL, Redis uses a single-node multi-instance deployment model: one physical/virtual machine node typically deploys multiple Redis instances to fully utilize multi-core CPUs. Therefore, nodes and instances have a 1:N relationship. Additionally, production typically advises against Redis instances with memory > 12GB.
Redis has three different operating modes, specified by the redis_mode parameter:
| Mode | Code | Description | HA Mechanism |
|---|---|---|---|
| Standalone | standalone |
Classic master-replica, default mode | Requires Sentinel |
| Sentinel | sentinel |
HA monitoring and auto-failover for standalone | Multi-node quorum |
| Native Cluster | cluster |
Redis native distributed cluster, no sentinel needed | Built-in auto-failover |
replica_of parameter. Requires additional Sentinel cluster for HA.Let’s look at concrete examples for each mode:
Classic master-replica on a single node:
| Cluster | Description |
|---|---|
redis-ms |
Redis standalone cluster |
| Node | Description |
redis-ms-1 |
10.10.10.10 Node #1, hosts 2 instances |
| Instance | Description |
redis-ms-1-6379 |
Primary instance, listening on port 6379 |
redis-ms-1-6380 |
Replica instance, port 6380, replicates from 6379 |
Three sentinel instances on a single node for monitoring standalone clusters. Sentinel clusters specify monitored standalone clusters via redis_sentinel_monitor:
A Redis native distributed cluster with two nodes and six instances (minimum spec: 3 primaries, 3 replicas):
This creates a 3 primary 3 replica native Redis cluster.
| Cluster | Description |
|---|---|
redis-test |
Redis native cluster (3P3R) |
| Instance | Description |
redis-test-1-6379 |
Instance on node 1, port 6379 |
redis-test-1-6380 |
Instance on node 1, port 6380 |
redis-test-1-6381 |
Instance on node 1, port 6381 |
redis-test-2-6379 |
Instance on node 2, port 6379 |
redis-test-2-6380 |
Instance on node 2, port 6380 |
redis-test-2-6381 |
Instance on node 2, port 6381 |
| Node | Description |
redis-test-1 |
10.10.10.12 Node #1, hosts 3 instances |
redis-test-2 |
10.10.10.13 Node #2, hosts 3 instances |
Pigsty uses the REDIS parameter group to assign deterministic identities to each Redis module entity. Three parameters are required:
| Parameter | Type | Level | Description | Format |
|---|---|---|---|---|
redis_cluster |
string |
Cluster | Redis cluster name, required | Valid DNS name, regex [a-z][a-z0-9-]* |
redis_node |
int |
Node | Redis node number, required | Natural number, starting from 1, unique within cluster |
redis_instances |
dict |
Node | Redis instance definition, required | JSON object, key is port, value is instance config |
With cluster name defined at cluster level and node number/instance definition assigned at node level, Pigsty automatically generates unique identifiers for each entity:
| Entity | Generation Rule | Example |
|---|---|---|
| Instance | {{ redis_cluster }}-{{ redis_node }}-{{ port }} |
redis-ms-1-6379, redis-ms-1-6380 |
The Redis module does not assign additional identity to host nodes; nodes are identified by their existing hostname or IP address.
redis_node is used for instance naming, not host node identity.
redis_instances is a JSON object with port number as key and instance config as value:
Each Redis instance listens on a unique port within the node. You can choose any port number,
but avoid system reserved ports (< 1024) or conflicts with Pigsty used ports.
The replica_of parameter sets replication relationship in standalone mode, format '<ip> <port>', specifying upstream primary address and port.
Additionally, each Redis node runs a Redis Exporter collecting metrics from all local instances:
| Port | Parameter | Purpose |
|---|---|---|
| 9121 | redis_exporter_port |
Redis Exporter port |
Redis’s single-node multi-instance deployment model has some limitations:
Pigsty provides an out-of-box monitoring system that uses the above identity parameters to identify various Redis entities.
For example, the cls, ins, ip labels correspond to cluster name, instance name, and node IP—the identifiers for these three core entities.
They appear along with the job label in all Redis monitoring metrics collected by VictoriaMetrics.
The job name for collecting Redis metrics is fixed as redis.
Pigsty follows the IaC and GitOPS philosophy: use a declarative config inventory to describe the entire environment, and materialize it through idempotent playbooks.
Users describe their desired state declaratively through parameters, and playbooks idempotently adjust target nodes to reach that state. This is similar to Kubernetes CRDs & Operators, but Pigsty implements this functionality on bare metal and virtual machines through Ansible.
Pigsty was born to solve the operational management problem of ultra-large-scale PostgreSQL clusters. The idea behind it is simple — we need the ability to replicate the entire infrastructure (100+ database clusters + PG/Redis + observability) on ready servers within ten minutes. No GUI + ClickOps can complete such a complex task in such a short time, making CLI + IaC the only choice — it provides precise, efficient control.
The config inventory pigsty.yml file describes the state of the entire deployment. Whether it’s production (prod), staging, test, or development (devbox) environments,
the difference between infrastructures lies only in the config inventory, while the deployment delivery logic is exactly the same.
You can use git for version control and auditing of this deployment “seed/gene”, and Pigsty even supports storing the config inventory as database tables in PostgreSQL CMDB, further achieving Infra as Data capability. Seamlessly integrate with your existing workflows.
IaC is designed for professional users and enterprise scenarios but is also deeply optimized for individual developers and SMBs. Even if you’re not a professional DBA, you don’t need to understand these hundreds of adjustment knobs and switches. All parameters come with well-performing default values. You can get an out-of-the-box single-node database with zero configuration; Simply add two more IP addresses to get an enterprise-grade high-availability PostgreSQL cluster.
Take the following default config snippet as an example. This config describes a node 10.10.10.10 with INFRA, NODE, ETCD, and PGSQL modules installed.
To actually install these modules, execute the following playbooks:
You can declare PostgreSQL database clusters by installing the PGSQL module on multiple nodes, making them a service unit:
For example, to deploy a three-node high-availability PostgreSQL cluster using streaming replication on the following three Pigsty-managed nodes,
you can add the following definition to the all.children section of the config file pigsty.yml:
After defining, you can use playbooks to create the cluster:

You can use different instance roles such as primary, replica, offline, delayed, sync standby; as well as different clusters: such as standby clusters, Citus clusters, and even Redis / MINIO (Silo) / Etcd clusters
Not only can you define clusters declaratively, but you can also define databases, users, services, and HBA rules within the cluster. For example, the following config file deeply customizes the content of the default pg-meta single-node database cluster:
Including: declaring six business databases and seven business users, adding an extra standby service (synchronous standby, providing read capability with no replication delay), defining some additional pg_hba rules, an L2 VIP address pointing to the cluster primary, and a customized backup strategy.
You can also customize Pigsty’s access control through declarative configuration. For example, the following config file provides deep security customization for the pg-meta cluster:
Uses the three-node core cluster template: crit.yml, to ensure data consistency is prioritized with zero data loss during failover.
Enables L2 VIP and restricts database and connection pool listening addresses to local loopback IP + internal network IP + VIP three specific addresses.
The template enables TLS for the Patroni API and PgBouncer, and requires SSL for database access through HBA.
It also enables $libdir/passwordcheck in pg_libs to enforce a password-strength policy.
Finally, a separate pg-meta-delay cluster is declared as pg-meta’s delayed replica from one hour ago, for emergency data deletion recovery.
Below is a declarative configuration for a four-node Citus distributed cluster:
Below are declarative configuration examples for Redis primary-replica cluster, sentinel cluster, and Redis Cluster:
Below is a declarative configuration example for a three-node Etcd cluster:
Below is a declarative configuration example for a three-node Silo cluster. The inventory group and parameters retain the MINIO module’s compatibility names:
Every Pigsty deployment corresponds to an Inventory that describes key properties of the infrastructure and database clusters.
Pigsty uses Ansible YAML configuration format by default,
with a single YAML configuration file pigsty.yml as the inventory.
You can directly edit this configuration file to customize your deployment, or use the configure wizard script provided by Pigsty to automatically generate an appropriate configuration file.
The inventory uses standard Ansible YAML configuration format, consisting of two parts: global parameters (all.vars) and multiple groups (all.children).
You can define new clusters in all.children and describe the infrastructure using global variables: all.vars, which looks like this:
Each Ansible group may represent a cluster, which can be a node cluster, PostgreSQL cluster, Redis cluster, Etcd cluster, Silo cluster, etc.
A cluster definition consists of two parts: cluster members (hosts) and cluster parameters (vars).
You can define cluster members in <cls>.hosts and describe the cluster using configuration parameters in <cls>.vars.
Here’s an example of a 3-node high-availability PostgreSQL cluster definition:
Cluster-level vars (cluster parameters) override global parameters, and instance-level vars override both cluster parameters and global parameters.
If your deployment is large or you want to better organize configuration files, you can split the inventory into multiple files for easier management and maintenance.
You can place cluster member definitions in the hosts.yml file and put cluster-level configuration parameters in corresponding files under the group_vars directory.
You can temporarily specify a different inventory file when running playbooks using the -i parameter.
Additionally, Ansible supports multiple configuration methods. You can use local yaml|ini configuration files, or use CMDB and any dynamic configuration scripts as configuration sources.
In Pigsty, we specify pigsty.yml in the same directory as the default inventory through ansible.cfg in the Pigsty home directory. You can modify it as needed.
Additionally, Pigsty supports using a CMDB metabase to store the inventory, facilitating integration with existing systems.
Pigsty provides a configure script as a configuration wizard that automatically generates an appropriate pigsty.yml configuration file based on your current environment.
This is an optional script: if you already understand how to configure Pigsty, you can directly edit the pigsty.yml configuration file and skip the wizard.
Enter the pigsty source home directory and run ./configure to automatically start the configuration wizard. Without any arguments, it defaults to the meta single-node configuration template:
This command will use the selected template as a base, detect the current node’s IP address and region, and generate a pigsty.yml configuration file suitable for the current environment.
demo/configure.cast — /demo/configure.cast
The configure script performs the following adjustments based on environment and input, generating pigsty.yml in the Pigsty directory by default.
10.10.10.10 in the configuration template and sets it as the admin_ip parameter valueregion to default (global default repos) or china (using Chinese mirror repos)tiny parameter template for node_tune and pg_conf to optimize resource usage-v is specified, switches pg_version and pg18-* package-group aliases in the template to that major version; fixed-kernel templates mssql, polar, and pg19 are excluded from this replacement-g is specified, replaces default passwords recognized by the configuration wizard with randomly generated strong passwords; review uncovered values against the Default Credentials Checklist (strongly recommended)C.UTF-8 locale, or the OS-supported C.UTF-8ansible for deployment is available in the current environment-s to skip)| Argument | Description |
|---|---|
-c, --conf |
Generate config from conf/<template>.yml, supports subdirectories like ha/full |
-i, --ip |
Replace placeholder 10.10.10.10 in config template with specified IP |
-v, --version |
Specify PostgreSQL major version (14-19); PG19 is Beta, so prefer the dedicated pg19 template |
-r, --region |
Set software repo mirror region: default, china (Chinese mirrors), europe (European) |
-o, --output |
Output path, default pigsty.yml; relative paths use Pigsty home, absolute paths are used as given |
-s, --skip |
Skip IP probing, target SSH/Sudo checks, and effective IP replacement; keep 10.10.10.10 |
-x, --proxy |
Write current environment proxy variables (HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, NO_PROXY) to config |
-n, --non-interactive |
Non-interactive mode; a single/demo IP is auto-selected, while ambiguous multi-IP hosts require -i |
-p, --port |
SSH port used by readiness checks only; it does not write ansible_port into the generated config |
-g, --generate |
Generate random values for passwords in config file, improving security (strongly recommended) |
The configure script executes detection and configuration in the following order:
The script automatically detects the network environment to determine if you’re in mainland China (behind GFW):
region: default repositorieshttps://pigsty.cc is reachable, sets region: chinaregion: default and emits an internet-unreachable warning-r argumentThe script determines the primary IP address in the following priority:
-i, use it directly10.10.10.10 is detected, select it automatically (for sandbox environments)When fewer than 4 CPU cores are detected (1-3 cores), the script automatically adjusts configuration:
This ensures smooth operation on low-spec virtual machines.
The script automatically enables C.UTF-8 as the default locale when:
C.UTF-8 / C.utf8 localeWhen region is set to china, the script automatically:
docker_registry_mirrors Docker mirror accelerationPIP_MIRROR_URL Python mirror accelerationWhen using the -g argument, the script generates 24-character random strings for the following passwords:
| Password Parameter | Description |
|---|---|
grafana_admin_password |
Grafana admin password |
pg_admin_password |
PostgreSQL admin password |
pg_monitor_password |
PostgreSQL monitor user password |
pg_replication_password |
PostgreSQL replication user password |
patroni_password |
Patroni API password |
haproxy_admin_password |
HAProxy admin password |
minio_secret_key |
Silo Root Secret |
etcd_root_password |
ETCD Root password |
It also replaces the following placeholder passwords:
DBUser.Meta → random passwordDBUser.Viewer → random passwordS3User.Backup → random passwordS3User.Meta → random passwordS3User.Data → random passwordDBUser.Supa → random passwordVibe.Coding → random passwordThe script reads templates from conf/. The value of -c is a path relative to that directory without the .yml suffix, such as ha/full or app/immich.
| Template | Description |
|---|---|
meta |
Default template: Single-node installation with INFRA + NODE + ETCD + PGSQL |
rich |
Feature-rich version: Includes almost all extensions, Silo, local repo |
slim |
Minimal version: PostgreSQL + ETCD only, no monitoring infrastructure |
fat |
Complete version: rich base with more extensions installed |
pgsql |
Pure PostgreSQL template |
pg19 |
Single-node PostgreSQL 19 Beta evaluation template |
infra |
Pure infrastructure template |
ha/)
| Template | Description |
|---|---|
ha/dual |
2-node HA cluster |
ha/trio |
3-node HA cluster |
ha/full |
4-node complete sandbox environment |
ha/safe |
Security-hardened HA configuration |
ha/octo |
Compact 8-node HA simulation |
ha/simu |
20-node production simulation environment |
ha/citus |
13-node Citus distributed cluster |
| Template | Description |
|---|---|
supabase |
Supabase self-hosted configuration |
app/dify |
Dify AI platform configuration |
app/odoo |
Odoo ERP configuration |
app/electric |
Electric sync engine configuration |
app/insforge |
Insforge backend platform configuration |
app/hindsight |
Hindsight application configuration |
app/teable |
Teable table database configuration |
app/mattermost |
Mattermost collaboration platform configuration |
app/maybe |
Maybe finance application configuration |
app/registry |
Docker Registry configuration |
app/immich |
Immich photo and video management |
app/jumpserver |
JumpServer bastion host |
| Template | Description |
|---|---|
ivory |
IvorySQL: Oracle-compatible PostgreSQL |
mssql |
Babelfish: SQL Server-compatible PostgreSQL |
polar |
PolarDB: Alibaba Cloud open-source distributed PostgreSQL |
ha/citus |
Citus: Distributed PostgreSQL HA cluster |
mysql |
OpenHalo: MySQL protocol-compatible PostgreSQL |
pgtde |
Percona PostgreSQL Server: transparent encryption |
oriole |
OrioleDB: Next-generation storage engine |
agens |
AgensGraph: graph database kernel |
pgedge |
pgEdge: distributed PostgreSQL kernel |
mongo |
MongoDB-compatible stack template |
| Template | Description |
|---|---|
vibe |
Vibe Coding development environment |
docker |
Run Pigsty inside a Docker container |
demo/bare |
Minimal readable single-node example |
demo/el |
Full parameter example for EL distributions |
demo/debian |
Full parameter example for Debian/Ubuntu |
demo/demo |
Multi-module demo environment |
demo/kernel |
Ten-node database-kernel matrix |
demo/redis |
Redis replica, Sentinel, and native Cluster demo |
demo/minio |
Multi-node, multi-drive Silo demo (source default) |
demo/kafka |
Kafka KRaft development and secure-cluster demo |
demo/mysql |
Native MySQL 8.4 pilot demo |
demo/remote |
Remote PostgreSQL/RDS monitoring example |
demo/saas |
Legacy single-node SaaS component bundle |
demo/wool |
Small cloud-instance example for China |
build/oss |
Cross-distribution open-source package build env |
build/dev |
Three-node development and build environment |
The script supports the following environment variables:
| Environment Variable | Description | Default |
|---|---|---|
PIGSTY_HOME |
Pigsty installation directory | ~/pigsty |
METADB_URL |
Metabase connection URL | service=meta |
HTTP_PROXY |
HTTP proxy | - |
HTTPS_PROXY |
HTTPS proxy | - |
ALL_PROXY |
Universal proxy | - |
NO_PROXY |
Proxy whitelist | Built-in default |
Passwordless access: Before running configure, ensure the current user has passwordless sudo privileges and passwordless SSH to localhost. This can be automatically configured via the bootstrap script.
IP address selection: Choose an internal IP as the primary IP address, not a public IP or 127.0.0.1.
Password security: In production, always change default passwords in the configuration file. Use -g to randomize recognized credentials, then review the Default Credentials Checklist for remaining values.
Configuration review: After the script completes, it’s recommended to review the generated pigsty.yml file to confirm the configuration meets expectations.
Multiple executions: You can run configure multiple times to regenerate configuration; each run will overwrite the existing pigsty.yml.
macOS limitations: When running on macOS, the script skips some Linux-specific checks and uses placeholder IP 10.10.10.10. macOS can only serve as an admin node.
Place your configuration file in the conf/ directory, then specify it with the -c argument:
Use the -o argument to specify different output files:
Then specify the configuration file when running playbooks:
You must explicitly specify the IP address using the -i argument:
Use the -s argument to skip IP replacement:
In the inventory, you can use various parameters to fine-tune Pigsty customization. These parameters cover everything from infrastructure settings to database configuration.
According to the current source and parameter reference pages, Pigsty’s 10 official modules expose 373 public parameters for fine-grained control. See Reference - Parameter List for the complete list. The native MySQL 8.4 pilot module exposes 13 additional public parameters that are listed separately and excluded from this total.
| Module | Groups | Params | Description |
|---|---|---|---|
| PGSQL | 9 | 124 | PostgreSQL high-availability cluster configuration |
| INFRA | 10 | 73 | Software repositories and Victoria observability infrastructure |
| NODE | 11 | 73 | Node initialization, system tuning, and operations baseline |
| ETCD | 2 | 13 | ETCD cluster and removal protection parameters |
| MINIO | 2 | 22 | Silo deployment, observability, and removal parameters |
| REDIS | 2 | 22 | Redis/Valkey deployment and removal parameters |
| DOCKER | 1 | 8 | Docker engine parameters |
| JUICE | 1 | 2 | JuiceFS instance and cache parameters |
| VIBE | 1 | 18 | Code/Jupyter/Node.js/Claude/Codex configuration |
| KAFKA | 2 | 18 | Kafka deployment and removal-protection parameters |
Parameters are key-value pairs that describe entities. The Key is a string, and the Value can be one of five types: boolean, string, number, array, or object.
Parameters can be set at different levels with the following priority:
| Level | Location | Description | Priority |
|---|---|---|---|
| CLI | -e command line argument |
Passed via command line | Highest (5) |
| Host/Instance | <group>.hosts.<host> |
Parameters specific to a single host | Higher (4) |
| Group/Cluster | <group>.vars |
Parameters shared by hosts in group/cluster | Medium (3) |
| Global | all.vars |
Parameters shared by all hosts | Lower (2) |
| Default | <roles>/default/main.yml |
Role implementation defaults | Lowest (1) |
Here are some examples of parameter priority:
-e grafana_clean=true when running playbooks to wipe Grafana datapg_role on host variables to override pg instance rolepg_cluster on group variables to override pg cluster namenode_ntp_servers on global variables to specify global NTP serverspg_version is not set, Pigsty will use the default value from the pgsql role implementation (default is 18)Except for identity parameters, every parameter has an appropriate default value, so explicit setting is not required.
Identity parameters are special parameters that serve as entity ID identifiers, therefore they have no default values and must be explicitly set.
| Module | Identity Parameters |
|---|---|
PGSQL |
pg_cluster, pg_seq, pg_role, … |
NODE |
nodename, node_cluster |
ETCD |
etcd_cluster, etcd_seq |
MINIO |
minio_cluster, minio_seq |
REDIS |
redis_cluster, redis_node, redis_instances |
INFRA |
infra_seq |
The exception is etcd_cluster, which still defaults to etcd.
Object storage minio_cluster no longer has a default and must be defined explicitly in each object-storage cluster’s variables.
Do not place it in all.vars, or every host will be marked as a MINIO module member.
In Pigsty, deployment blueprint details are defined by the inventory, which is the pigsty.yml configuration file. You can customize it through declarative configuration.
However, writing configuration files directly can be daunting for new users. To address this, we provide some ready-to-use configuration templates covering common usage scenarios.
Each template is a predefined pigsty.yml configuration file containing reasonable defaults suitable for specific scenarios.
You can choose a template as your customization starting point, then modify it as needed to meet your specific requirements.
Pigsty provides the configure script as an optional configuration wizard that generates an inventory with good defaults based on your environment and input.
Use ./configure -c <conf> to specify a configuration template, where <conf> is the path relative to the conf directory (the .yml suffix can be omitted).
If no template is specified, Pigsty defaults to the meta.yml single-node configuration template.
The following are single-node configuration templates for installing Pigsty on a single server:
| Template | Description |
|---|---|
meta.yml |
Default template, single-node PostgreSQL online installation |
rich.yml |
Feature-rich template with local repo, Silo, and more examples |
slim.yml |
Minimal template, PostgreSQL only without monitoring and infrastructure |
Templates for various database management systems and kernels:
| Template | Description |
|---|---|
pgsql.yml |
Native PostgreSQL kernel, basic features (14~18) |
pg19.yml |
PostgreSQL 19 Beta trial template |
mssql.yml |
Babelfish kernel, SQL Server protocol compatible (17/18) |
polar.yml |
PolarDB PG kernel, Aurora/RAC style (17) |
ivory.yml |
IvorySQL kernel, Oracle syntax compatible (18) |
mysql.yml |
OpenHalo kernel, MySQL compatible (14) |
pgtde.yml |
Percona PostgreSQL Server transparent encryption (18) |
oriole.yml |
OrioleDB kernel, OLTP enhanced (16~18) |
agens.yml |
AgensGraph graph database kernel (17) |
pgedge.yml |
pgEdge distributed database kernel (15~18, default 18) |
supabase.yml |
Supabase self-hosted configuration (15~18) |
You can add more nodes later or use HA templates to plan your cluster from the start.
You can configure Pigsty to run on multiple nodes, forming a high-availability (HA) cluster:
| Template | Description |
|---|---|
dual.yml |
2-node semi-HA deployment |
trio.yml |
3-node standard HA deployment |
full.yml |
4-node standard deployment |
safe.yml |
4-node security-enhanced deployment with delayed replica |
octo.yml |
Compact 8-node HA simulation |
simu.yml |
20-node production environment simulation |
ha/citus.yml |
Citus distributed HA PostgreSQL (14~18) |
You can use the following templates to run Docker applications/software:
| Template | Description |
|---|---|
supabase.yml |
Start single-node Supabase |
odoo.yml |
Start Odoo ERP system |
dify.yml |
Start Dify AI workflow system |
electric.yml |
Start Electric sync engine |
insforge.yml |
Start Insforge backend platform |
hindsight.yml |
Start Hindsight application |
mattermost.yml |
Start Mattermost collaboration platform |
teable.yml |
Start Teable spreadsheet database |
maybe.yml |
Start Maybe finance app |
registry.yml |
Start Docker Registry |
Besides main templates, Pigsty provides a set of demo templates for different scenarios:
| Template | Description |
|---|---|
el.yml |
Full-parameter config file for EL 8/9 systems |
debian.yml |
Full-parameter config file for Debian/Ubuntu systems |
remote.yml |
Example config for monitoring remote PostgreSQL clusters or RDS |
redis.yml |
Redis cluster example configuration |
minio.yml |
4-node multi-drive Silo cluster example (source default) |
kafka.yml |
Kafka dynamic KRaft example with a single-node dev cluster and a three-node secure cluster |
mysql.yml |
Native MySQL 8.4 single-node/three-node pilot example; distinct from OpenHalo conf/mysql.yml |
demo.yml |
Configuration file for Pigsty public demo site |
fat.yml |
Single-node config with local repo and full feature set |
infra.yml |
Deploy only the infrastructure modules |
vibe.yml |
Vibe Coding / AI application development template |
mongo.yml |
FerretDB / MongoDB-compatible example |
docker.yml |
Docker application host template |
The following configuration templates are for development and testing purposes:
| Template | Description |
|---|---|
build/oss.yml |
Open source build config for EL 9/10, Debian 12/13, Ubuntu 22.04/24.04/26.04 |
build/dev.yml |
Development and testing build config |
Pigsty allows you to use a PostgreSQL metabase as a dynamic configuration source, replacing static YAML configuration files for more powerful configuration management capabilities.
CMDB (Configuration Management Database) is a method of storing configuration information in a database for management.
In Pigsty, the default configuration source is a static YAML file pigsty.yml,
which serves as Ansible’s inventory.
This approach is simple and direct, but when infrastructure scales and requires complex, fine-grained management and external integration, a single static file becomes insufficient.
| Feature | Static YAML File | CMDB Metabase |
|---|---|---|
| Querying | Manual search/grep | SQL queries with any conditions, aggregation analysis |
| Versioning | Depends on Git or manual backup | Database transactions, audit logs, time-travel snapshots |
| Access Control | File system permissions, coarse-grained | PostgreSQL fine-grained access control |
| Concurrent Editing | Requires file locking or merge conflicts | Database transactions naturally support concurrency |
| External Integration | Requires YAML parsing | Standard SQL interface, easy integration with any language |
| Scalability | Difficult to maintain when file becomes too large | Scales to physical limits |
| Dynamic Generation | Static file, changes require manual application | Immediate effect, real-time configuration changes |
Pigsty provides the CMDB database schema in the sample database pg-meta.meta schema baseline definition.
The core idea of CMDB is to replace the static configuration file with a dynamic script.
Ansible supports using executable scripts as inventory, as long as the script outputs inventory data in JSON format.
When you enable CMDB, Pigsty creates a dynamic inventory script named inventory.sh:
This script’s function is simple: every time Ansible needs to read the inventory, it queries configuration data from the PostgreSQL database’s pigsty.inventory view and returns it in JSON format.
The overall architecture is as follows:
flowchart LR
conf["bin/inventory_conf"]
tocmdb["bin/inventory_cmdb"]
load["bin/inventory_load"]
ansible["🚀 Ansible"]
subgraph static["📄 Static Config Mode"]
yml[("pigsty.yml")]
end
subgraph dynamic["🗄️ CMDB Dynamic Mode"]
sh["inventory.sh"]
cmdb[("PostgreSQL CMDB")]
end
conf -->|"switch"| yml
yml -->|"load config"| load
load -->|"write"| cmdb
tocmdb -->|"switch"| sh
sh --> cmdb
yml --> ansible
cmdb --> ansibleThe CMDB database schema is defined in files/cmdb.sql, with all objects in the pigsty schema.
| Table | Description | Primary Key |
|---|---|---|
pigsty.group |
Cluster/group definitions, corresponds to Ansible groups | cls |
pigsty.host |
Host definitions, belongs to a group | (cls, ip) |
pigsty.global_var |
Global variables, corresponds to all.vars |
key |
pigsty.group_var |
Group variables, corresponds to all.children.<cls>.vars |
(cls, key) |
pigsty.host_var |
Host variables, host-level variables | (cls, ip, key) |
pigsty.default_var |
Default variable definitions, stores parameter metadata | key |
pigsty.job |
Job records table, records executed tasks | id |
Cluster Table pigsty.group
Host Table pigsty.host
Global Variables Table pigsty.global_var
Group Variables Table pigsty.group_var
Host Variables Table pigsty.host_var
CMDB provides a series of views for querying and displaying configuration data:
| View | Description |
|---|---|
pigsty.inventory |
Core view: Generates Ansible dynamic inventory JSON |
pigsty.raw_config |
Raw configuration in JSON format |
pigsty.global_config |
Global config view, merges defaults and global vars |
pigsty.group_config |
Group config view, includes host list and group vars |
pigsty.host_config |
Host config view, merges group and host-level vars |
pigsty.pg_cluster |
PostgreSQL cluster view |
pigsty.pg_instance |
PostgreSQL instance view |
pigsty.pg_database |
PostgreSQL database definition view |
pigsty.pg_users |
PostgreSQL user definition view |
pigsty.pg_service |
PostgreSQL service definition view |
pigsty.pg_hba |
PostgreSQL HBA rules view |
pigsty.pg_remote |
Remote PostgreSQL instance view |
pigsty.inventory is the core view that converts database configuration data to the JSON format required by Ansible:
Pigsty provides three convenience scripts for managing CMDB:
| Script | Function |
|---|---|
bin/inventory_load |
Load YAML configuration file into PostgreSQL database |
bin/inventory_cmdb |
Switch configuration source to CMDB (dynamic inventory script) |
bin/inventory_conf |
Switch configuration source to static config file pigsty.yml |
Parse and import YAML configuration file into CMDB:
The script performs the following operations:
pigsty schemaglobal_var tablegroup tablegroup_var tablehost tablehost_var tableEnvironment Variables
PIGSTY_HOME: Pigsty installation directory, defaults to ~/pigstyMETADB_URL: Database connection URL, defaults to service=metaSwitch Ansible to use CMDB as the configuration source:
The script performs the following operations:
${PIGSTY_HOME}/inventory.shansible.cfg to set inventory to inventory.shThe generated inventory.sh contents:
Switch back to using static YAML configuration file:
The script modifies ansible.cfg to set inventory back to pigsty.yml.
After enabling CMDB, you can flexibly query configuration using SQL:
You can modify configuration directly via SQL:
Changes take effect immediately without reloading or restarting any service.
To switch back to static configuration file mode:
Export CMDB configuration to YAML format:
Or use the ansible-inventory command:
Track configuration changes using the mtime field:
CMDB uses standard PostgreSQL, making it easy to integrate with other systems:
Data Consistency: After modifying configuration, you need to re-run the corresponding Ansible playbooks to apply changes to the actual environment
Backup: Configuration data in CMDB is critical, ensure regular backups
Permissions: Configure appropriate database access permissions for CMDB to avoid accidental modifications
Transactions: When making batch configuration changes, perform them within a transaction for rollback on errors
Connection Pooling: The inventory.sh script creates a new connection on each execution; if Ansible runs frequently, consider using connection pooling
CMDB is Pigsty’s advanced configuration management solution, suitable for scenarios requiring large-scale cluster management, complex queries, external integration, or fine-grained access control. By storing configuration data in PostgreSQL, you can fully leverage the database’s powerful capabilities to manage infrastructure configuration.
| Feature | Description |
|---|---|
| Storage | PostgreSQL pigsty schema |
| Dynamic Inventory | inventory.sh script |
| Config Load | bin/inventory_load |
| Switch to CMDB | bin/inventory_cmdb |
| Switch to YAML | bin/inventory_conf |
| Core View | pigsty.inventory |
Pigsty’s PostgreSQL clusters come with out-of-the-box high availability, with core capabilities provided by Patroni, Etcd, and HAProxy.
When your PostgreSQL cluster has two or more instances, you automatically have self-healing database high availability without any additional configuration — as long as any instance in the cluster survives, the cluster can provide complete service. Clients only need to connect to any node in the cluster to get full service without worrying about primary-replica topology changes.
The default norm mode targets an RTO under 45 seconds. With asynchronous replication, pg_rpo=1MiB is Patroni’s sampled lag threshold for failover candidates, not a hard upper bound on actual data loss. Strict synchronous mode with crit.yml keeps acknowledged transactions at RPO = 0 during failover. These behaviors can be configured for your hardware and reliability requirements.
Pigsty includes built-in HAProxy load balancers for automatic traffic switching, providing DNS/VIP/LVS and other access methods for clients. Failover and switchover are almost transparent to the business side except for brief interruptions - applications don’t need to modify connection strings or restart. The minimal maintenance window requirements bring great flexibility and convenience: you can perform rolling maintenance and upgrades on the entire cluster without application coordination. The feature that hardware failures can wait until the next day to handle lets developers, operations, and DBAs sleep well during incidents.

Many large organizations and core institutions have been using Pigsty in production for extended periods. The largest deployment has 25K CPU cores and 220+ PostgreSQL ultra-large instances (64c / 512g / 3TB NVMe SSD). In this deployment case, dozens of hardware failures and various incidents occurred over five years, yet overall availability of over 99.999% was maintained.
What problems does High Availability solve?
What are the costs of High Availability?
Limitations of High Availability
Since replication happens in real-time, all changes are immediately applied to replicas. Therefore, streaming replication-based HA solutions cannot handle data deletion or modification caused by human errors and software defects. (e.g., DROP TABLE or DELETE data)
Such failures require using delayed clusters or performing point-in-time recovery using previous base backups and WAL archives.
| Configuration Strategy | RTO | RPO |
|---|---|---|
| Standalone + Nothing | Data permanently lost, unrecoverable | All data lost |
| Standalone + Base Backup | Depends on backup size and bandwidth (hours) | Lose data since last backup (hours to days) |
| Standalone + Base Backup + WAL Archive | Depends on backup size and bandwidth (hours) | Lose unarchived data (tens of MB) |
| Primary-Replica + Manual Failover | ~10 minutes | Lose data in replication lag (~100KB) |
| Primary-Replica + Auto Failover | Within 1 minute | Lose data in replication lag (~100KB) |
| Primary-Replica + Auto Failover + Sync Commit | Within 1 minute | No data loss |
In Pigsty, the high availability architecture works as follows:
When the primary fails, a new round of leader election is triggered. The healthiest replica in the cluster (highest LSN position, minimum data loss) wins and is promoted to the new primary. After the winning replica is promoted, read-write traffic is immediately routed to the new primary. The impact of primary failure is brief write service unavailability: write requests will be blocked or fail directly from primary failure until new primary promotion, with unavailability typically lasting 15 to 30 seconds, usually not exceeding 1 minute.
When a replica fails, read-only traffic is routed to other replicas. Only when all replicas fail will read-only traffic ultimately be handled by the primary. The impact of replica failure is partial read-only query interruption: queries currently running on that replica will abort due to connection reset and be immediately taken over by other available replicas.
Failure detection is performed jointly by Patroni and Etcd. The cluster leader holds a lease; if it fails to renew the lease within its TTL (30 seconds in the default norm mode), the lease expires, triggering a Failover and a new election.
Even without any failures, you can proactively change the cluster primary through Switchover. In this case, write queries on the primary will experience a brief interruption and be immediately routed to the new primary. This operation is typically used for rolling maintenance/upgrades of database servers.
RPO (Recovery Point Objective) defines the maximum amount of data loss allowed when the primary fails.
For scenarios where data integrity is critical, such as financial transactions, RPO = 0 is typically required, meaning no data loss is allowed.
However, stricter RPO targets come at a cost: higher write latency, reduced system throughput, and the risk that replica failures may cause primary unavailability. For typical scenarios, some data loss is acceptable in exchange for higher availability and performance.
In asynchronous replication scenarios, there is typically some replication lag between replicas and the primary (depending on network and throughput, normally in the range of 10KB-100KB / 100µs-10ms). This means when the primary fails, replicas may not have fully synchronized with the latest data. If a failover occurs, the new primary may lose some unreplicated data.
The pg_rpo parameter is written to Patroni’s maximum_lag_on_failover and defaults to 1048576 (1MiB). It is the sampled lag threshold that permits a replica to participate as a failover candidate, not a hard upper bound on actual data loss.
When the cluster primary fails, if any replica has replication lag within this threshold, Pigsty will automatically promote that replica to be the new primary. However, when all replicas exceed this threshold, Pigsty will refuse [automatic failover] to prevent data loss. Manual intervention is then required to decide whether to wait for the primary to recover (which may never happen) or accept the data loss and force-promote a replica.
Because the primary’s WAL position is not sampled continuously, the worst-case loss under asynchronous replication can also include WAL generated during the most recent ttl window (on average, roughly another loop_wait/2 of WAL). Configure this threshold with your workload’s write rate in mind. Increasing it improves the chance of automatic failover but also broadens candidate eligibility.
When you set pg_rpo = 0, Pigsty enables synchronous replication, ensuring the primary only returns write success after at least one replica has persisted the data.
This configuration ensures zero replication lag but introduces significant write latency and reduces overall throughput.
flowchart LR
A([Primary Failure]) --> B{Synchronous<br/>Replication?}
B -->|No| C{Lag < RPO?}
B -->|Yes| D{Sync Replica<br/>Available?}
C -->|Yes| E[Lossy Auto Failover<br/>Sampled candidate lag is within threshold]
C -->|No| F[Refuse Auto Failover<br/>Wait for Primary Recovery<br/>or Manual Intervention]
D -->|Yes| G[Lossless Auto Failover<br/>RPO = 0]
D -->|No| H{Strict Mode?}
H -->|No| C
H -->|Yes| F
style A fill:#dc3545,stroke:#b02a37,color:#fff
style E fill:#F0AD4E,stroke:#146c43,color:#fff
style G fill:#198754,stroke:#146c43,color:#fff
style F fill:#BE002F,stroke:#565e64,color:#fffPigsty provides three protection modes to help users make trade-offs under different RPO requirements, similar to Oracle Data Guard protection modes.
pg_rpo = 0, enables Patroni synchronous commit mode: synchronous_mode: truecrit.yml template, enables Patroni strict synchronous mode: synchronous_mode: true / synchronous_mode_strict: true| Name | Maximum Performance | Maximum Availability | Maximum Protection |
|---|---|---|---|
| Replication | Asynchronous | Synchronous | Strict Synchronous |
| Data Loss | Possible (replication lag) | Zero normally, minor when degraded | Zero |
| Write Latency | Lowest | Medium (+1 network RTT) | Medium (+1 network RTT) |
| Throughput | Highest | Reduced | Reduced |
| Replica Failure Impact | None | Auto degrade, service continues | Primary stops writes |
| RPO | Possible loss; 1MiB default candidate threshold | = 0 normally / possible loss after degradation | = 0 |
| Use Case | Typical business, performance first | Critical business, safety first | Financial core, compliance first |
| Configuration | Default config | pg_rpo = 0 |
pg_conf: crit.yml |
The three protection modes differ in how two core Patroni parameters are configured: synchronous_mode and synchronous_mode_strict:
synchronous_mode: Whether Patroni enables synchronous replication. If enabled, check if synchronous_mode_strict enables strict synchronous mode.synchronous_mode_strict = false: Default configuration, allows degradation to async mode when replicas fail, primary continues service (Maximum Availability)synchronous_mode_strict = true: Degradation forbidden, primary stops writes until sync replica recovers (Maximum Protection)| Mode | synchronous_mode |
synchronous_mode_strict |
Replication Mode | Replica Failure Behavior |
|---|---|---|---|---|
| Max Performance | false |
- | Async | No impact |
| Max Availability | true |
false |
Synchronous | Auto degrade to async |
| Max Protection | true |
true |
Strict Synchronous | Primary refuses writes |
Typically, you only need to set the pg_rpo parameter to 0 to enable the synchronous_mode switch, activating Maximum Availability mode.
If you use pg_conf = crit.yml template, it additionally enables the synchronous_mode_strict strict mode switch, activating Maximum Protection mode.
Additionally, you can enable watchdog to fence the primary directly during node/Patroni freeze scenarios instead of degrading, achieving behavior equivalent to Oracle Maximum Protection mode.
You can also directly configure these Patroni parameters as needed. Refer to Patroni and PostgreSQL documentation to achieve stronger data protection, such as:
synchronous_commit: 'remote_apply' to strictly ensure primary-replica read-write consistency. (Oracle Maximum Protection mode is equivalent to remote_write)Maximum Performance mode (asynchronous replication) is the default mode used by Pigsty and is sufficient for the vast majority of workloads.
It tolerates some loss during a failure in exchange for higher throughput and availability.
In this mode, pg_rpo adjusts the sampled lag threshold for failover candidates; actual worst-case loss also depends on write rate, ttl, and sampling timing.
Maximum Availability mode (synchronous replication) is suitable for scenarios with high data-integrity requirements. Acknowledged transactions have zero loss while a synchronous replica is healthy, but the cluster can degrade when all synchronous replicas are unavailable.
In this mode, a minimum of two-node PostgreSQL cluster (one primary, one replica) is required.
Set pg_rpo to 0 to enable this mode.
Maximum Protection mode (strict synchronous replication) is suitable for financial transactions, medical records, and other scenarios with extremely high data integrity requirements. We recommend using at least a three-node cluster (one primary, two replicas), because with only two nodes, if the replica fails, the primary will stop writes, causing service unavailability, which reduces overall system reliability. With three nodes, if only one replica fails, the primary can continue to serve.
Patroni failures can be classified into 10 categories by failure target, and further consolidated into five categories based on detection path, which are detailed in this section.
| # | Failure Scenario | Description | Final Path |
|---|---|---|---|
| 1 | PG process crash | crash, OOM killed | Active Detection |
| 2 | PG connection refused | max_connections | Active Detection |
| 3 | PG zombie | Process alive but unresponsive | Active Detection (timeout) |
| 4 | Patroni process crash | kill -9, OOM | Passive Detection |
| 5 | Patroni zombie | Process alive but stuck | Watchdog |
| 6 | Node down | Power outage, hardware failure | Passive Detection |
| 7 | Node zombie | IO hang, CPU starvation | Watchdog |
| 8 | Primary ↔ DCS network failure | Firewall, switch failure | Network Partition |
| 9 | Storage failure | Disk failure, disk full, mount failure | Active Detection or Watchdog |
| 10 | Manual switchover | Switchover/Failover | Manual Trigger |
However, for RTO calculation purposes, all failures ultimately converge to two paths. This section explores the upper bound, lower bound, and average RTO for these two scenarios.
flowchart LR
A([Primary Failure]) --> B{Patroni<br/>Detected?}
B -->|PG Crash| C[Attempt Local Restart]
B -->|Node Down| D[Wait TTL Expiration]
C -->|Success| E([Local Recovery])
C -->|Fail/Timeout| F[Release Leader Lock]
D --> F
F --> G[Replica Election]
G --> H[Execute Promote]
H --> I[HAProxy Detects]
I --> J([Service Restored])
style A fill:#dc3545,stroke:#b02a37,color:#fff
style E fill:#198754,stroke:#146c43,color:#fff
style J fill:#198754,stroke:#146c43,color:#fff
infographic list-row-simple-horizontal-arrow
data
desc Lease Expiration Stages
items
- label Lease Expiration
- label Replica Detect
- label Elect & Promote
- label Haproxy Up
theme light
palette antvtooltip: { trigger: axis, axisPointer: { type: shadow }, formatter: $fn:fmt }
legend: { top: 0, itemGap: 12, data: [Lease Expiration, Replica Detection, Lock Contest & Promote, Health Check] }
grid: { left: 64, right: 24, bottom: 32, top: 40 }
xAxis: { type: value, name: Seconds, nameLocation: end, max: 160, axisLine: { show: true }, axisTick: { show: true }, splitLine: { show: true, lineStyle: { type: dashed, opacity: 0.5 } }, minorTick: { show: true, splitNumber: 5 }, minorSplitLine: { show: true, lineStyle: { type: dotted, opacity: 0.2 } } }
yAxis: { type: category, axisLine: { show: true }, axisTick: { show: true }, splitLine: { show: false }, axisLabel: { fontSize: 10, fontFamily: monospace }, data: [wide-max, wide-avg, wide-min, "", safe-max, safe-avg, safe-min, "", norm-max, norm-avg, norm-min, "", fast-max, fast-avg, fast-min] }
series:
- { name: Lease Expire, type: bar, stack: main, barWidth: 20, z: 2, emphasis: { focus: series }, itemStyle: { color: "#e15759" }, data: [120, 110, 100, "-", 60, 55, 50, "-", 30, 27, 25, "-", 20, 17, 15] }
- { name: Replica Detect, type: bar, stack: main, z: 2, emphasis: { focus: series }, itemStyle: { color: "#edc949" }, data: [20, 10, 0, "-", 10, 5, 0, "-", 5, 3, 0, "-", 5, 3, 0] }
- { name: Elect & Promote, type: bar, stack: main, z: 2, emphasis: { focus: series }, itemStyle: { color: "#59a14f" }, data: [2, 1, 0, "-", 2, 1, 0, "-", 2, 1, 0, "-", 2, 1, 0] }
- { name: HAProxy Check, type: bar, stack: main, z: 2, emphasis: { focus: series }, itemStyle: { color: "#4e79a7" }, data: [8, 6, 4, "-", 6, 5, 3, "-", 4, 3, 2, "-", 2, 2, 1] }
- { name: Total RTO, type: bar, barGap: "-100%", barWidth: 20, z: 1, itemStyle: { color: "#888", opacity: 0 }, emphasis: { itemStyle: { opacity: 0 } }, data: [150, 127, 104, "-", 78, 66, 53, "-", 41, 34, 27, "-", 29, 23, 16] }
- { name: RTO Budget, type: bar, barGap: "-100%", barWidth: 20, z: 0, itemStyle: { color: "rgba(0,0,0,0.08)" }, emphasis: { itemStyle: { color: "rgba(0,0,0,0.12)" } }, data: [150, 150, 150, "-", 90, 90, 90, "-", 45, 45, 45, "-", 30, 30, 30] }| Phase | Best | Worst | Average | Description |
|---|---|---|---|---|
| Lease Expiration | ttl - loop |
ttl |
ttl - loop/2 |
Best: crash just before refresh Worst: crash right after refresh |
| Replica Detect | 0 |
loop |
loop / 2 |
Best: exactly at check point Worst: just missed check point |
| Election Promote | 0 |
2 |
1 |
Best: direct lock and promote Worst: API timeout + Promote |
| HAProxy Check | (rise-1) × fastinter |
(rise-1) × fastinter + inter |
(rise-1) × fastinter + inter/2 |
Best: state change before check Worst: state change right after check |
Key Difference Between Passive and Active Failover:
| Scenario | Patroni Status | Lease Handling | Primary Wait Time |
|---|---|---|---|
| Active Failover (PG crash) | Alive, healthy | Actively tries to restart PG, releases lease on timeout | primary_start_timeout |
| Passive Failover (Node crash) | Dies with node | Cannot actively release, must wait for TTL expiration | ttl |
In passive failover scenarios, Patroni dies along with the node and cannot actively release the Leader Key. The lease in DCS can only trigger cluster election after TTL naturally expires.
The Patroni primary refreshes the Leader Key every loop_wait cycle, resetting TTL to the configured value.
loop since last refresh), remaining TTL = ttl - loopttlttl - loop/2Replicas wake up on loop_wait cycles and check the Leader Key status in DCS.
0looploop/2When replicas detect Leader Key expiration, they start the election process. The replica that acquires the Leader Key executes pg_ctl promote to become the new primary.
pg_ctl promote to become primary (very fast, typically negligible)0.1s2s1s constant overheadHAProxy detects the new primary online, requiring rise consecutive successful health checks.
(rise-1) × fastinter(rise-1) × fastinter + inter(rise-1) × fastinter + inter/2Sum all phase times to get total RTO:
Best Case
Average Case
Worst Case
Substitute the four RTO model parameters into the formulas above:
Four Mode Calculation Results (unit: seconds, format: min / avg / max)
| Phase | fast | norm | safe | wide |
|---|---|---|---|---|
| Lease Expiration | 15 / 17 / 20 |
25 / 27 / 30 |
50 / 55 / 60 |
100 / 110 / 120 |
| Replica Detection | 0 / 3 / 5 |
0 / 3 / 5 |
0 / 5 / 10 |
0 / 10 / 20 |
| Lock Contest & Promote | 0 / 1 / 2 |
0 / 1 / 2 |
0 / 1 / 2 |
0 / 1 / 2 |
| Health Check | 1 / 2 / 2 |
2 / 3 / 4 |
3 / 5 / 6 |
4 / 6 / 8 |
| Total | 16 / 23 / 29 |
27 / 34 / 41 |
53 / 66 / 78 |
104 / 127 / 150 |
infographic list-row-simple-horizontal-arrow
data
desc When Patroni is healthy but PostgreSQL crashes
items
- label Crash Found
- label Restart Timeout
- label Replica Detect
- label Elect Promote
- label HAProxy Check
theme light
palette antvtooltip: { trigger: axis, axisPointer: { type: shadow }, formatter: $fn:fmt }
legend: { top: 0, itemGap: 12, data: [ Crash Found, Restart Timeout, Replica Detection, Elect Promote, HAProxy Check] }
grid: { left: 64, right: 24, bottom: 32, top: 40 }
xAxis: { type: value, name: Seconds, nameLocation: end, max: 160, axisLine: { show: true }, axisTick: { show: true }, splitLine: { show: true, lineStyle: { type: dashed, opacity: 0.5 } }, minorTick: { show: true, splitNumber: 5 }, minorSplitLine: { show: true, lineStyle: { type: dotted, opacity: 0.2 } } }
yAxis: { type: category, axisLine: { show: true }, axisTick: { show: true }, splitLine: { show: false }, axisLabel: { fontSize: 10, fontFamily: monospace }, data: [wide-max, wide-avg, wide-min, "", safe-max, safe-avg, safe-min, "", norm-max, norm-avg, norm-min, "", fast-max, fast-avg, fast-min] }
series:
- { name: Crash Found, type: bar, stack: main, barWidth: 20, z: 2, emphasis: { focus: series }, itemStyle: { color: "#b07aa1" }, data: [20, 10, 0, "-", 10, 5, 0, "-", 5, 3, 0, "-", 5, 3, 0] }
- { name: Restart Timeout, type: bar, stack: main, z: 2, emphasis: { focus: series }, itemStyle: { color: "#f28e2c" }, data: [95, 95, 0, "-", 45, 45, 0, "-", 25, 25, 0, "-", 15, 15, 0] }
- { name: Replica Detect, type: bar, stack: main, z: 2, emphasis: { focus: series }, itemStyle: { color: "#edc949" }, data: [20, 10, 0, "-", 10, 5, 0, "-", 5, 3, 0, "-", 5, 3, 0] }
- { name: Elect Promote, type: bar, stack: main, z: 2, emphasis: { focus: series }, itemStyle: { color: "#59a14f" }, data: [2, 1, 0, "-", 2, 1, 0, "-", 2, 1, 0, "-", 2, 1, 0] }
- { name: HAProxy Check, type: bar, stack: main, z: 2, emphasis: { focus: series }, itemStyle: { color: "#4e79a7" }, data: [8, 6, 4, "-", 6, 5, 3, "-", 4, 3, 2, "-", 2, 2, 1] }
- { name: RTO Total, type: bar, barGap: "-100%", barWidth: 20, z: 1, itemStyle: { color: "#888", opacity: 0 }, emphasis: { itemStyle: { opacity: 0 } }, data: [145, 122, 4, "-", 73, 61, 3, "-", 41, 35, 2, "-", 29, 24, 1] }
- { name: RTO Budget, type: bar, barGap: "-100%", barWidth: 20, z: 0, itemStyle: { color: "rgba(0,0,0,0.08)" }, emphasis: { itemStyle: { color: "rgba(0,0,0,0.12)" } }, data: [150, 150, 150, "-", 90, 90, 90, "-", 45, 45, 45, "-", 30, 30, 30] }| Item | Best | Worst | Average | Description |
|---|---|---|---|---|
| Crash Found | 0 |
loop |
loop/2 |
Best: PG crashes right before check Worst: PG crashes right after check |
| Restart Timeout | 0 |
start |
start |
Best: PG recovers instantly Worst: Wait full start timeout before releasing lease |
| Replica Detect | 0 |
loop |
loop/2 |
Best: Right at check point Worst: Just missed check point |
| Elect Promote | 0 |
2 |
1 |
Best: Acquire lock and promote directly Worst: API timeout + Promote |
| HAProxy Check | (rise-1) × fastinter |
(rise-1) × fastinter + inter |
(rise-1) × fastinter + inter/2 |
Best: State changes before check Worst: State changes right after check |
Key Difference Between Active and Passive Failure:
| Scenario | Patroni Status | Lease Handling | Main Wait Time |
|---|---|---|---|
| Active Failure (PG crash) | Alive, healthy | Actively tries to restart PG, releases lease after timeout | primary_start_timeout |
| Passive Failure (node down) | Dies with node | Cannot actively release, must wait for TTL expiry | ttl |
In active failure scenarios, Patroni remains alive and can actively detect PG crash and attempt restart. If restart succeeds, service self-heals; if timeout expires without recovery, Patroni actively releases the Leader Key, triggering cluster election.
Patroni checks PostgreSQL status every loop_wait cycle (via pg_isready or process check).
0looploop/2After Patroni detects PG crash, it attempts to restart PostgreSQL. This phase has two possible outcomes:
Path A: Self-healing Success (Best case)
0 (relative to Failover path)Path B: Failover Required (Average/Worst case)
primary_start_timeoutstartNote: Average case assumes failover is required. If PG can quickly self-heal, overall RTO will be significantly lower.
Standbys wake up on loop_wait cycle and check Leader Key status in DCS. When primary Patroni releases the Leader Key, standbys discover this and begin election.
0looploop/2After standbys discover Leader Key vacancy, election begins. The standby that acquires the Leader Key executes pg_ctl promote to become the new primary.
pg_ctl promote to become primary (very fast, typically negligible)0.1s2s1s constant overheadHAProxy detects new primary online, requires rise consecutive successful health checks.
(rise-1) × fastinter(rise-1) × fastinter + inter(rise-1) × fastinter + inter/2Sum all phase times to get total RTO:
Best Case (PG instant self-healing)
Average Case (Failover required)
Worst Case
Substituting the four RTO model parameters into the formulas above:
Calculation Results for Four Modes (unit: seconds, format: min / avg / max)
| Phase | fast | norm | safe | wide |
|---|---|---|---|---|
| Failure Detection | 0 / 3 / 5 |
0 / 3 / 5 |
0 / 5 / 10 |
0 / 10 / 20 |
| Restart Timeout | 0 / 15 / 15 |
0 / 25 / 25 |
0 / 45 / 45 |
0 / 95 / 95 |
| Standby Detection | 0 / 3 / 5 |
0 / 3 / 5 |
0 / 5 / 10 |
0 / 10 / 20 |
| Lock & Promote | 0 / 1 / 2 |
0 / 1 / 2 |
0 / 1 / 2 |
0 / 1 / 2 |
| Health Check | 1 / 2 / 2 |
2 / 3 / 4 |
3 / 5 / 6 |
4 / 6 / 8 |
| Total | 1 / 24 / 29 |
2 / 35 / 41 |
3 / 61 / 73 |
4 / 122 / 145 |
| Phase | Active Failure (PG crash) | Passive Failure (node down) | Description |
|---|---|---|---|
| Detection Mechanism | Patroni active detection | TTL passive expiry | Active detection discovers failure faster |
| Core Wait | start |
ttl |
start is usually less than ttl, but requires additional failure detection time |
| Lease Handling | Active release | Passive expiry | Active release is more timely |
| Self-healing Possible | Yes | No | Active detection can attempt local recovery |
RTO Comparison (Average case):
| Mode | Active Failure (PG crash) | Passive Failure (node down) | Difference |
|---|---|---|---|
| fast | 24s | 23s | +1s |
| norm | 35s | 34s | +1s |
| safe | 61s | 66s | -5s |
| wide | 122s | 127s | -5s |
Analysis: In
fastandnormmodes, active failure RTO is slightly higher than passive failure because it waits forprimary_start_timeout(start); but insafeandwidemodes, sincestart < ttl - loop, active failure is actually faster. However, active failure has the possibility of self-healing, with potentially extremely short RTO in best case scenarios.
infographic list-row-simple-horizontal-arrow
data
title Network Partition Failover Flow
desc Primary partitioned from DCS, Patroni proactively demotes to prevent split-brain, waits for TTL expiration before switchover
items
- label Primary Demote
desc Patroni demotes PG after retry timeout
icon mingcute/shield-fill
- label Lease Expiration
desc Leader Key TTL expires
icon mingcute/close-circle-fill
- label Replica Detection
desc Replica detects lease expiration, starts election
icon mingcute/key-2-fill
- label Lock & Promote
desc Replica acquires lock and promotes to new primary
icon mingcute/radar-fill
- label Health Check
desc HAProxy detects new primary online
icon mingcute/arrow-up-circle-fill
theme light
palette antvtooltip: { trigger: axis, axisPointer: { type: shadow }, formatter: $fn:fmt }
legend: { top: 0, itemGap: 12, data: [Primary Demote, Lease Expiration, Replica Detection, Lock & Promote, Health Check] }
grid: { left: 64, right: 24, bottom: 32, top: 40 }
xAxis: { type: value, name: sec, nameLocation: end, max: 160, axisLine: { show: true }, axisTick: { show: true }, splitLine: { show: true, lineStyle: { type: dashed, opacity: 0.5 } }, minorTick: { show: true, splitNumber: 5 }, minorSplitLine: { show: true, lineStyle: { type: dotted, opacity: 0.2 } } }
yAxis: { type: category, axisLine: { show: true }, axisTick: { show: true }, splitLine: { show: false }, axisLabel: { fontSize: 10, fontFamily: monospace }, data: [wide-max, wide-avg, wide-min, "", safe-max, safe-avg, safe-min, "", norm-max, norm-avg, norm-min, "", fast-max, fast-avg, fast-min] }
series:
- { name: Primary Demote, type: bar, stack: main, barWidth: 20, z: 2, emphasis: { focus: series }, itemStyle: { color: "#76b7b2" }, data: [50, 40, 30, "-", 30, 25, 20, "-", 15, 13, 10, "-", 10, 8, 5] }
- { name: Lease Expiration, type: bar, stack: main, z: 2, emphasis: { focus: series }, itemStyle: { color: "#e15759" }, data: [70, 70, 70, "-", 30, 30, 30, "-", 15, 15, 15, "-", 10, 10, 10] }
- { name: Replica Detection, type: bar, stack: main, z: 2, emphasis: { focus: series }, itemStyle: { color: "#edc949" }, data: [20, 10, 0, "-", 10, 5, 0, "-", 5, 3, 0, "-", 5, 3, 0] }
- { name: Lock & Promote, type: bar, stack: main, z: 2, emphasis: { focus: series }, itemStyle: { color: "#59a14f" }, data: [2, 1, 0, "-", 2, 1, 0, "-", 2, 1, 0, "-", 2, 1, 0] }
- { name: Health Check, type: bar, stack: main, z: 2, emphasis: { focus: series }, itemStyle: { color: "#4e79a7" }, data: [8, 6, 4, "-", 6, 5, 3, "-", 4, 3, 2, "-", 2, 2, 1] }
- { name: RTO Total, type: bar, barGap: "-100%", barWidth: 20, z: 1, itemStyle: { color: "#888", opacity: 0 }, emphasis: { itemStyle: { opacity: 0 } }, data: [150, 127, 104, "-", 78, 66, 53, "-", 41, 34, 27, "-", 29, 23, 16] }
- { name: RTO Budget, type: bar, barGap: "-100%", barWidth: 20, z: 0, itemStyle: { color: "rgba(0,0,0,0.08)" }, emphasis: { itemStyle: { color: "rgba(0,0,0,0.12)" } }, data: [150, 150, 150, "-", 90, 90, 90, "-", 45, 45, 45, "-", 30, 30, 30] }| Phase | Best | Worst | Average | Notes |
|---|---|---|---|---|
| Demote | retry |
loop + retry |
loop/2 + retry |
Patroni retries after detecting partition, demotes after timeout |
| Lease Expiration | ttl - loop - retry |
ttl - loop - retry |
ttl - loop - retry |
Remaining TTL time after demotion (approximately constant) |
| Replica Detection | 0 |
loop |
loop/2 |
Best: Right at detection point Worst: Just missed detection |
| Lock & Promote | 0 |
2 |
1 |
Best: Direct lock and promote Worst: API timeout + Promote |
| Health Check | (rise-1) × fastinter |
(rise-1) × fastinter + inter |
(rise-1) × fastinter + inter/2 |
Best: State changes before check Worst: State changes right after check |
Key difference between network partition and node crash:
| Scenario | Patroni State | PostgreSQL State | Lease Handling | Split-brain Risk |
|---|---|---|---|---|
| Node Crash (Expire) | Dies with node | Completely unavailable | Passive wait for TTL expiration | None |
| Network Partition (This scenario) | Alive but cannot access DCS | May still be running (needs active demotion) | Passive wait for TTL expiration | Yes, needs protection |
In network partition scenarios, the primary PostgreSQL may still be running and accepting writes, causing split-brain issues. Patroni solves this through active demotion: when unable to refresh Leader Key, proactively demotes PostgreSQL to read-only or shuts it down.
When primary Patroni is network-partitioned from DCS, it cannot refresh Leader Key and starts retrying.
loop_wait cycle to detectretry_timeoutKey design: Patroni requires constraint loop_wait + 2 × retry_timeout ≤ ttl to ensure primary demotes before TTL expires.
After primary demotion, Leader Key still exists in DCS, must wait for TTL to naturally expire.
Since the primary has demoted, waiting time during this phase is the remaining TTL time. Since partition detection and remaining TTL are negatively correlated (earlier partition means slower detection but longer remaining TTL), their sum is constant:
Note: Primary demotion + lease expiration total time still approximately equals ttl, same as expire failure.
Replica wakes up in loop_wait cycle and checks Leader Key status in DCS.
0looploop/2After replica discovers Leader Key expired, it starts the election process.
≈ 02s1sHAProxy detects new primary coming online, requires rise consecutive successful health checks.
(rise-1) × fastinter(rise-1) × fastinter + inter(rise-1) × fastinter + inter/2Sum all phase times to get total RTO.
Since primary demotion + lease expiration ≈ ttl, network partition RTO formula is same as expire failure:
Best Case
Average Case
Worst Case
Substituting the four RTO model parameters into the formulas:
Patroni constraint validation (loop + 2×retry ≤ ttl):
| Mode | loop | retry | TTL | loop + 2×retry | Meets constraint? |
|---|---|---|---|---|---|
| fast | 5 | 5 | 20s | 15s | ✓ Safe |
| norm | 5 | 10 | 30s | 25s | ✓ Safe |
| safe | 10 | 20 | 60s | 50s | ✓ Safe |
| wide | 20 | 30 | 120s | 80s | ✓ Safe |
Four mode calculation results (seconds, format: min / avg / max)
| Phase | fast | norm | safe | wide |
|---|---|---|---|---|
| Primary Demote | 5 / 8 / 10 |
10 / 13 / 15 |
20 / 25 / 30 |
30 / 40 / 50 |
| Lease Expiration | 10 |
15 |
30 |
70 |
| Replica Detection | 0 / 3 / 5 |
0 / 3 / 5 |
0 / 5 / 10 |
0 / 10 / 20 |
| Lock & Promote | 0 / 1 / 2 |
0 / 1 / 2 |
0 / 1 / 2 |
0 / 1 / 2 |
| Health Check | 1 / 2 / 2 |
2 / 3 / 4 |
3 / 5 / 6 |
4 / 6 / 8 |
| Total | 16 / 23 / 29 |
27 / 34 / 41 |
53 / 66 / 78 |
104 / 127 / 150 |
Conclusion: Network partition RTO is same as expire failure (node crash), as the bottleneck is TTL expiration time.
The biggest risk of network partition is split-brain: old primary may still be running and accepting writes. Patroni provides multiple protection mechanisms:
Patroni’s core protection mechanism: when unable to refresh Leader Key, proactively demotes PostgreSQL.
If Patroni process hangs and cannot execute demotion, Linux watchdog will force system restart.
Can configure fencing scripts to forcibly isolate old primary (e.g., disable network interface, stop service, etc.).
This is the most common network partition scenario, the main focus of this article.
| Failure Type | Primary State | Lease Handling | RTO | Split-brain Risk |
|---|---|---|---|---|
| Expire Failure | Node crash | Passive wait TTL expiration | 16s ~ 150s | None |
| Crash Failure | PG crash, Patroni alive | Release after restart timeout | 1s ~ 111s | None |
| Network Partition | Alive but isolated from DCS | Passive wait TTL expiration | 16s ~ 150s | Yes, needs protection |
| Manual Switchover | Normal or failed | Direct release/acquire | 1s ~ 11s | None |
Key Insight: Network partition RTO is same as expire failure, but requires additional split-brain protection mechanisms.
Ensuring loop_wait + 2 × retry_timeout ≤ ttl constraint is the key design to prevent split-brain.
RTO (Recovery Time Objective) defines the maximum time required for the system to restore write capability when the primary fails.
For critical transaction systems where availability is paramount, the shortest possible RTO is typically required, such as under one minute.
However, shorter RTO comes at a cost: increased false failover risk. Network jitter may be misinterpreted as a failure, leading to unnecessary failovers. For cross-datacenter/cross-region deployments, RTO requirements are typically relaxed (e.g., 1-2 minutes) to reduce false failover risk.
The upper limit of unavailability during failover is controlled by the pg_rto parameter. Pigsty provides four preset RTO modes:
fast, norm, safe, wide, each optimized for different network conditions and deployment scenarios. The default is norm mode (~45 seconds).
When the primary fails, the entire recovery process involves multiple phases: Patroni detects the failure, DCS lock expires, new primary election, promote execution, HAProxy detects the new primary. Reducing RTO means shortening the timeout for each phase, which makes the cluster more sensitive to network jitter, thereby increasing false failover risk.
You need to choose the appropriate mode based on actual network conditions, balancing recovery speed and false failover risk. The worse the network quality, the more conservative mode you should choose; the better the network quality, the more aggressive mode you can choose.
flowchart LR
A([Primary Failure]) --> B{Patroni<br/>Detected?}
B -->|PG Crash| C[Attempt Local Restart]
B -->|Node Down| D[Wait TTL Expiration]
C -->|Success| E([Local Recovery])
C -->|Fail/Timeout| F[Release Leader Lock]
D --> F
F --> G[Replica Election]
G --> H[Execute Promote]
H --> I[HAProxy Detects]
I --> J([Service Restored])
style A fill:#dc3545,stroke:#b02a37,color:#fff
style E fill:#198754,stroke:#146c43,color:#fff
style J fill:#198754,stroke:#146c43,color:#fffPigsty provides four RTO modes to help users make trade-offs under different network conditions.
| Name | fast | norm | safe | wide |
|---|---|---|---|---|
| Use Case | Same rack | Same datacenter (default) | Same region, cross-DC | Cross-region/continent |
| Network | < 1ms, very stable | 1-5ms, normal | 10-50ms, cross-DC | 100-200ms, public network |
| Target RTO | 30s | 45s | 90s | 150s |
| False Failover Risk | Higher | Medium | Lower | Very Low |
| Configuration | pg_rto: fast |
pg_rto: norm |
pg_rto: safe |
pg_rto: wide |
Patroni / PG HA has two key failure paths: active failure detection (Patroni detects a PG crash and attempts restart) and passive lease expiration (node down waits for TTL expiration to trigger election).
tooltip: { trigger: axis, axisPointer: { type: shadow }, formatter: $fn:fmt }
legend: { top: 0, itemGap: 10, data: [Lease Expiration, Failure Detection, Restart Timeout, Replica Detection, Lock & Promote, Health Check] }
grid: { left: 110, right: 24, bottom: 32, top: 40 }
xAxis: { type: value, name: Seconds, nameLocation: end, max: 160, axisLine: { show: true }, axisTick: { show: true }, splitLine: { show: true, lineStyle: { type: dashed, opacity: 0.5 } }, minorTick: { show: true, splitNumber: 5 }, minorSplitLine: { show: true, lineStyle: { type: dotted, opacity: 0.2 } } }
yAxis: { type: category, axisLine: { show: true }, axisTick: { show: true }, splitLine: { show: false }, axisLabel: { fontSize: 9, fontFamily: monospace }, data: [wide-passive-max, wide-passive-avg, wide-passive-min, wide-active-max, wide-active-avg, wide-active-min, "", safe-passive-max, safe-passive-avg, safe-passive-min, safe-active-max, safe-active-avg, safe-active-min, "", norm-passive-max, norm-passive-avg, norm-passive-min, norm-active-max, norm-active-avg, norm-active-min, "", fast-passive-max, fast-passive-avg, fast-passive-min, fast-active-max, fast-active-avg, fast-active-min] }
series:
- { name: Lease Expiration, type: bar, stack: main, barWidth: 16, z: 2, emphasis: { focus: series }, itemStyle: { color: "#e15759" }, data: [120, 110, 100, "-", "-", "-", "-", 60, 55, 50, "-", "-", "-", "-", 30, 27, 25, "-", "-", "-", "-", 20, 17, 15, "-", "-", "-"] }
- { name: Failure Detection, type: bar, stack: main, z: 2, emphasis: { focus: series }, itemStyle: { color: "#b07aa1" }, data: ["-", "-", "-", 20, 10, 0, "-", "-", "-", "-", 10, 5, 0, "-", "-", "-", "-", 5, 3, 0, "-", "-", "-", "-", 5, 3, 0] }
- { name: Restart Timeout, type: bar, stack: main, z: 2, emphasis: { focus: series }, itemStyle: { color: "#f28e2c" }, data: ["-", "-", "-", 95, 95, 0, "-", "-", "-", "-", 45, 45, 0, "-", "-", "-", "-", 25, 25, 0, "-", "-", "-", "-", 15, 15, 0] }
- { name: Replica Detection, type: bar, stack: main, z: 2, emphasis: { focus: series }, itemStyle: { color: "#edc949" }, data: [20, 10, 0, 20, 10, 0, "-", 10, 5, 0, 10, 5, 0, "-", 5, 3, 0, 5, 3, 0, "-", 5, 3, 0, 5, 3, 0] }
- { name: Lock & Promote, type: bar, stack: main, z: 2, emphasis: { focus: series }, itemStyle: { color: "#59a14f" }, data: [2, 1, 0, 2, 1, 0, "-", 2, 1, 0, 2, 1, 0, "-", 2, 1, 0, 2, 1, 0, "-", 2, 1, 0, 2, 1, 0] }
- { name: Health Check, type: bar, stack: main, z: 2, emphasis: { focus: series }, itemStyle: { color: "#4e79a7" }, data: [8, 6, 4, 8, 6, 4, "-", 6, 5, 3, 6, 5, 3, "-", 4, 3, 2, 4, 3, 2, "-", 2, 2, 1, 2, 2, 1] }
- { name: RTO Total, type: bar, barGap: "-100%", barWidth: 16, z: 1, itemStyle: { color: "#888", opacity: 0 }, emphasis: { itemStyle: { opacity: 0 } }, data: [150, 127, 104, 145, 122, 4, "-", 78, 66, 53, 73, 61, 3, "-", 41, 34, 27, 41, 35, 2, "-", 29, 23, 16, 29, 24, 1] }
- { name: RTO Budget, type: bar, barGap: "-100%", barWidth: 16, z: 0, itemStyle: { color: "rgba(0,0,0,0.08)" }, emphasis: { itemStyle: { color: "rgba(0,0,0,0.12)" } }, data: [150, 150, 150, 150, 150, 150, "-", 90, 90, 90, 90, 90, 90, "-", 45, 45, 45, 45, 45, 45, "-", 30, 30, 30, 30, 30, 30] }The four RTO modes differ in how the following 10 Patroni and HAProxy HA-related parameters are configured.
| Component | Parameter | fast | norm | safe | wide | Description |
|---|---|---|---|---|---|---|
patroni |
ttl |
20 | 30 | 60 | 120 | Leader lock TTL (seconds) |
loop_wait |
5 | 5 | 10 | 20 | HA loop check interval (seconds) | |
retry_timeout |
5 | 10 | 20 | 30 | DCS operation retry timeout (seconds) | |
primary_start_timeout |
15 | 25 | 45 | 95 | Primary restart wait time (seconds) | |
safety_margin |
5 | 5 | 10 | 15 | Watchdog safety margin (seconds) | |
haproxy |
inter |
1s | 2s | 3s | 4s | Normal state check interval |
fastinter |
500ms | 1s | 1500ms | 2s | State transition check interval | |
downinter |
1s | 2s | 3s | 4s | DOWN state check interval | |
rise |
3 | 3 | 3 | 3 | Consecutive successes to mark UP | |
fall |
3 | 3 | 3 | 3 | Consecutive failures to mark DOWN |
ttl: Leader lock TTL. Primary must renew within this time, otherwise lock expires and triggers election. Directly determines passive failure detection delay.loop_wait: Patroni main loop interval. Each loop performs one health check and state sync, affects failure discovery timeliness.retry_timeout: DCS operation retry timeout. During network partition, Patroni retries continuously within this period; after timeout, primary actively demotes to prevent split-brain.primary_start_timeout: Wait time for Patroni to attempt local restart after PG crash. After timeout, releases Leader lock and triggers failover.safety_margin: Watchdog safety margin. Ensures sufficient time to trigger system restart during failures, avoiding split-brain.inter: Health check interval in normal state, used when service status is stable.fastinter: Check interval during state transition, uses shorter interval to accelerate confirmation when state change detected.downinter: Check interval in DOWN state, uses this interval to probe recovery after service marked DOWN.rise: Consecutive successes required to mark UP. After new primary comes online, must pass rise consecutive checks before receiving traffic.fall: Consecutive failures required to mark DOWN. Service must fail fall consecutive times before being marked DOWN.Patroni core constraint: Ensures primary can complete demotion before TTL expires, preventing split-brain.
fast mode is suitable for scenarios with extremely high RTO requirements, but requires sufficiently good network quality (latency < 1ms, very low packet loss). Recommended only for same-rack or same-switch deployments, and should be thoroughly tested in production before enabling.
norm mode (default) is Pigsty’s default configuration, sufficient for the vast majority of same-datacenter deployments. In the model used by this page, the passive and active paths average about 34 and 35 seconds, while still providing a reasonable tolerance window against false failovers caused by network jitter.
safe mode is suitable for same-city cross-datacenter deployments with higher network latency or occasional jitter. The longer tolerance window effectively prevents false failovers from network jitter, making it the recommended configuration for cross-datacenter disaster recovery.
wide mode is suitable for cross-region or even cross-continent deployments with high network latency and possible public-network-level packet loss. In such scenarios, stability is more important than recovery speed, so an extremely wide tolerance window ensures very low false failover rate.
| Mode | Target RTO | Passive RTO | Active RTO | Scenario |
|---|---|---|---|---|
fast |
30 |
16 / 23 / 29 |
1 / 24 / 29 |
Same switch, high-quality network |
norm |
45 |
27 / 34 / 41 |
2 / 35 / 41 |
Default, same DC, standard network |
safe |
90 |
53 / 66 / 78 |
3 / 61 / 73 |
Same-city active-active / cross-DC DR |
wide |
150 |
104 / 127 / 150 |
4 / 122 / 145 |
Geo-DR / cross-country |
default |
326 |
22 / 34 / 46 |
2 / 314 / 326 |
Patroni default params |
Typically you only need to set pg_rto to the mode name, and Pigsty will automatically configure Patroni and HAProxy parameters.
The current template looks up pg_rto with pg_rto in pg_rto_plan; a numeric or unknown key falls back directly to norm. Do not treat that fallback as a supported “RTO in seconds” configuration.
The mode configuration actually loads the corresponding parameter set from pg_rto_plan. You can modify or override this configuration to implement custom RTO strategies.
Split read and write operations, route traffic correctly, and deliver PostgreSQL cluster capabilities reliably.
Service is an abstraction: it represents the form in which database clusters expose their capabilities externally, encapsulating underlying cluster details.
Services are crucial for stable access in production environments, showing their value during automatic failover in high availability clusters. Personal users typically don’t need to worry about this concept.
The concept of “service” is for production environments. Personal users with single-node clusters can skip the complexity and directly use instance names or IP addresses to access the database.
For example, Pigsty’s default single-node pg-meta.meta database can be connected directly using three different users:
In real-world production environments, we use primary-replica database clusters based on replication. Within a cluster, one and only one instance serves as the leader (primary) that can accept writes. Other instances (replicas) continuously fetch change logs from the cluster leader to stay synchronized. Replicas can also handle read-only requests, significantly offloading the primary in read-heavy, write-light scenarios. Therefore, distinguishing write requests from read-only requests is a common practice.
Additionally, for production environments with high-frequency, short-lived connections, we pool requests through connection pool middleware (Pgbouncer) to reduce connection and backend process creation overhead. However, for scenarios like ETL and change execution, we need to bypass the connection pool and directly access the database. Meanwhile, high-availability clusters may undergo failover during failures, causing cluster leadership changes. Therefore, high-availability database solutions require write traffic to automatically adapt to cluster leadership changes. These varying access needs (read-write separation, pooled vs. direct connections, failover auto-adaptation) ultimately lead to the abstraction of the Service concept.
Typically, database clusters must provide this most basic service:
For production database clusters, at least these two services should be provided:
Additionally, depending on specific business scenarios, there may be other services, such as:
Pigsty’s service delivery boundary stops at the cluster’s HAProxy. Users can access these load balancers through various means.
The typical approach is to use DNS or VIP access, binding them to all or any number of load balancers in the cluster.

You can use different host & port combinations, which provide PostgreSQL service in different ways.
Host
| Type | Sample | Description |
|---|---|---|
| Cluster Domain Name | pg-test |
Resolved by dnsmasq on INFRA nodes; with pg_dns_target: auto, points to the VIP when enabled, otherwise to the primary IP |
| Cluster VIP Address | 10.10.10.3 |
When pg_vip_enabled is enabled, an L2 VIP managed by vip-manager and bound to the primary node |
| Instance Hostname | pg-test-1 |
Access via any instance hostname (resolved by dnsmasq @ infra nodes) |
| Instance IP Address | 10.10.10.11 |
Access any instance’s IP address |
Port
Pigsty uses different ports to distinguish pg services
| Port | Service | Type | Description |
|---|---|---|---|
| 5432 | postgres | Database | Direct access to postgres server |
| 6432 | pgbouncer | Middleware | Access postgres through connection pool middleware |
| 5433 | primary | Service | Access primary pgbouncer (or postgres) |
| 5434 | replica | Service | Access replica pgbouncer (or postgres) |
| 5436 | default | Service | Access primary postgres |
| 5438 | offline | Service | Access offline postgres |
Combinations
If data, a table, or even a database is deleted accidentally, Point-in-Time Recovery (PITR) can return the cluster to an earlier state.
This capability, once treated as specialist DBA work, is enabled by Pigsty’s standard PostgreSQL configuration.
High availability can fail over to another instance when hardware fails. It has a natural blind spot, however: replication is not backup.
Streaming replication faithfully sends every primary change to every replica within milliseconds, including a DELETE without a WHERE clause or a DROP TABLE issued against the wrong database. Failover handles a broken machine; when the data itself is wrong, every replica can contain the same error.
Database disasters therefore fall into two broad classes. Redundancy handles physical service failure through multiple copies and automatic failover. Logical errors require history: a base backup plus continuous WAL archives from which PostgreSQL can reconstruct a state before the mistake.
| Threat | High Availability | Delayed Cluster | PITR |
|---|---|---|---|
| Hardware or instance failure | ✔ Automatic failover | ✘ | ✔, with a longer RTO |
| Accidental DML, table drop, or database drop | ✘ The error is replicated | ✔ Within the delay | ✔ At any recoverable point |
| Defective software corrupts data over time | ✘ The error is replicated | ✔ Within the delay | ✔ Try different recovery targets |
| Entire cluster or site is lost | ✘ | ✘ | ✔ Only if the repository survives that failure domain |
These mechanisms complement one another: HA restores service quickly, a delayed cluster provides a short undo window, and PITR is the final historical recovery path.
A database can be viewed as a state machine. A base backup is a complete physical snapshot at one point, while WAL (Write-Ahead Log) records every subsequent state change. With a snapshot and an unbroken WAL history starting from it, PostgreSQL can replay the database to any target covered by that history. The backup determines how far back recovery can start; the latest archived WAL determines how close to the present it can reach.
Base backup + WAL archive = point-in-time recovery
Pigsty orchestrates both inputs. Cluster initialization attempts an initial full backup by default, and the primary continuously sends completed WAL segments to the selected repository. See How PITR Works for the complete model of backups, archives, targets, and timelines.
PITR is enabled in Pigsty’s standard PostgreSQL configuration. Each cluster is prepared with a backup repository, WAL archiving, and recovery tooling powered by pgBackRest. The policy remains declarative and can be customized with a few parameters:
The default local method stores backups under /pg/backup and retains two full backups. With one successful full backup per day, the resulting window is roughly 24–48 hours. Selecting the remote minio preset places the repository in Silo or compatible S3 storage, enables AES-256-CBC repository encryption, and uses time-based retention. With a 14-day retention setting and weekly full backups, the steady-state recovery window is roughly 14–21 days. Treat both ranges as policy estimates: actual coverage starts at the oldest usable backup and ends at the latest WAL that reached the repository.
Recovery is declarative too: specify a target, then let the playbook stop the cluster, restore files, replay WAL, and rebuild HA. An operator must still verify the recovered business state.
This follows Pigsty’s declarative configuration model: backup policy is part of the cluster definition, and a recovery target is another declared parameter.
PITR materially improves data integrity and availability:
| Standalone strategy | Event | RTO | RPO |
|---|---|---|---|
| No backup | Host and local data are lost | Permanent loss | All data |
| Base backups only | Host and local data are lost | Backup size and bandwidth, often hours | Changes since the latest backup |
| Base backups + WAL archives | Host and local data are lost | Backup size, replay distance, and bandwidth | WAL not yet present in the surviving repository |
The costs fall mainly into three areas:
PITR by itself does not replace HA. A production design normally combines HA for physical failures with PITR for logical errors and site-level recovery.
pg_pitr parameter, pgsql-pitr.yml, and pig pitrFor the operational runbooks, see PGSQL Backup and Recovery.
If a database is a state machine, WAL (Write-Ahead Log) is its ordered change history. PostgreSQL records each modification in WAL before applying it to data files. Save a physical snapshot at one point, preserve all later WAL, and PostgreSQL can replay that history to a selected consistent state.
PITR is therefore the combination of three simple elements: a snapshot (base backup), history (WAL archive), and a target (where replay should stop).
A base backup is a physical snapshot of the whole PostgreSQL cluster and supplies a starting point for recovery. Pigsty uses pgBackRest to create and manage three backup types:
| Type | Contents | Recovery characteristics |
|---|---|---|
| Full | All database-cluster files | Self-contained, shortest chain, largest backup |
| Differential | Changes since the latest full backup | Restore uses the full plus the differential |
| Incremental | Changes since the latest backup of any type | Smallest backup, restore depends on its complete chain |
The wrapper pg-backup [full|diff|incr] triggers a backup. With no argument it requests incr; pgBackRest creates a full backup instead when no valid full exists. pg_crontab declares recurring jobs and installs them in the postgres user’s crontab.
Backup frequency affects recovery time: the newer the usable backup, the less WAL must be replayed to reach a given target. See PITR Tradeoffs.
A snapshot reaches only its own state. WAL archiving preserves every later change needed to advance beyond it. Pigsty’s standard Patroni templates enable archiving and ask PostgreSQL to hand each completed WAL segment to pgBackRest:
Two implementation details matter:
archive_timeout: 300: on a low-write cluster, PostgreSQL can force a segment switch after five minutes so a partially filled segment does not wait indefinitely. This normally keeps the right edge of the recovery window within minutes when WAL is being generated; it is not a promise that every commit is already remote./pg/spool with archive-async=y to batch transfers. Pigsty sets archive-push-queue-max=4GiB; if repository failure lets the queue cross that bound, pgBackRest can drop the queued WAL to protect local disk. That creates an archive gap, so a new full backup is required to establish a fresh recoverable chain.Expiration is automatic. When old backups expire under the repository policy, pgBackRest also expires archived WAL that no remaining backup needs, unless archive retention is overridden explicitly.
The backup and its continuous WAL history form a recovery window:
The window moves forward as new backups arrive and old chains expire. Pigsty’s local preset keeps two full backups; with one successful full per day, coverage is roughly one to two days. The minio preset uses retention_full_type: time with retention_full: 14; with weekly full backups, the oldest retained chain normally yields roughly 14–21 days of steady-state coverage. These are estimates, not SLAs: missed backups, archive gaps, explicit archive-retention overrides, or repository loss change the actual window. Verify it with pig pb info and restore drills.
See PITR Tradeoffs and Backup Policy.
PostgreSQL supports several ways to locate a state inside the recovery window. Pigsty exposes six target types through pg_pitr:
pg_pitr type |
Meaning | Typical use |
|---|---|---|
default |
Replay through all WAL available from the repository | Restore the newest archived state after total loss |
time |
Stop at a timestamp | Recover from accidental DML or DDL |
xid |
Stop at a transaction ID | Exclude a precisely identified bad transaction |
lsn |
Stop at a WAL location | Low-level exact targeting |
name |
Stop at a restore point created with pg_create_restore_point() |
Planned change checkpoint |
immediate |
Stop as soon as the selected backup becomes consistent | Validate or expose the selected backup state quickly |
The set field is different: it chooses which backup set pgBackRest restores as the starting snapshot; it is not itself a replay stop target.
Targets are inclusive by default: the transaction at the target is retained. To stop immediately before a known bad target, set exclusive: true, which maps to recovery_target_inclusive = false.
Transactions remain atomic. Committed transactions before the effective target survive; transactions not committed at that point are rolled back. Recovery produces a consistent database state rather than half of a transaction.
Restoring to the past and accepting new writes creates a fork in history. PostgreSQL uses a timeline to distinguish each branch. PITR promotion, replica promotion, and failover can all create a new timeline; new WAL does not overwrite the old timeline’s files.
gitGraph
commit id: "Full backup"
commit id: "Normal writes"
commit id: "Bad change"
commit id: "More writes"
branch Timeline-2
checkout Timeline-2
commit id: "PITR before bad change"
commit id: "New writes"Keeping the old history allows another attempt if the first target was wrong. The timeline field can select a timeline; Pigsty’s recovery declaration defaults to latest.
Continue with PITR Architecture to see how these concepts map to Pigsty components and configuration.
The PITR principle is compact; the engineering is not. WAL archiving must not stall production writes, object-storage backups need encryption, backup jobs must follow the primary after failover, shared repositories must isolate clusters, and large numbers of small objects can limit throughput.
Pigsty uses pgBackRest as its backup engine and ships production-oriented defaults for those concerns. This page describes the engine, repository abstraction, archive path, scheduler, and primary-aware execution model.
Pigsty uses pgBackRest for three responsibilities: create base backups with backup, receive WAL with archive-push, and restore data with restore plus archive-get.
Relevant capabilities include:
pgBackRest separates cluster histories using a stanza. Pigsty maps the stanza name directly to pg_cluster, allowing multiple clusters to share one storage service without sharing a backup identity:
Two parameters define repository selection. pgbackrest_method chooses one repository name, and pgbackrest_repo is a dictionary of candidate definitions. Pigsty v4.5.0 renders only the selected pgbackrest_repo[pgbackrest_method] entry as pgBackRest repo1; listing both local and minio does not enable two active repositories.
The presets intentionally differ. local favors simplicity and fast local restore; it is unencrypted, unbundled, and retained by full-backup count. minio targets a remote Silo or compatible S3 repository, enabling encryption, bundles, block incremental backup, and time-based retention.
Rendering is mechanical: underscores in the chosen repository’s keys become hyphens and each key gets a repo1- prefix in /etc/pgbackrest/pgbackrest.conf. A custom cloud repository can therefore use pgBackRest options directly:
See Backup Repository for Silo, external S3-compatible storage, versioning, object locking, TLS, and credential details.
When pgbackrest_enabled is true, as it is by default, the Patroni templates configure:
Base backups enter the system in two ways:
pgbackrest_init_backup is true. The task ignores backup failure and writes /etc/pgbackrest/initial.done only after success, so the marker means “completed,” not merely “attempted.”pg_crontab installs jobs in the database superuser’s crontab. Its role default is an empty list; standard example configurations usually add a daily 01:00 full backup.pg-backup [full|diff|incr] is a small wrapper around pgbackrest backup. With no argument it requests an incremental backup, which pgBackRest promotes to a full backup if no usable full exists.
pgBackRest and the same scheduled job are installed on every PostgreSQL node, but pg-backup checks /pg/bin/pg-role and only proceeds on the current primary. Replicas fail fast rather than writing a competing backup.
That design decouples the backup schedule from the HA topology:
With a non-local repository, Pigsty also adds pgBackRest after basebackup in Patroni’s create_replica_methods. Patroni tries basebackup first; if that method fails, it can restore a replica from the repository with pgbackrest --delta restore, shifting the copy load away from the primary.
The shipped pgBackRest template favors light production overhead and aggressive restore throughput:
| Setting | v4.5.0 behavior | Rationale |
|---|---|---|
| Compression | compress-type=zst |
Balance compression ratio and throughput |
| Backup/archive workers | One quarter of CPU, clamped to 2–4 | Limit competition with the database |
| Restore workers | All detected CPU, capped at 8 | Minimize restore time |
| Asynchronous archive | archive-async=y, spool under /pg/spool |
Batch transfer without synchronous object-store latency |
| Archive queue limit | archive-push-queue-max=4GiB |
Bound local spool growth |
| Fast backup start | start-fast=y |
Request an immediate checkpoint |
| Incremental restore | delta=y |
Reuse destination files that already match |
The 4 GiB queue is a safety tradeoff: if the repository remains unavailable and the queue exceeds the limit, pgBackRest can discard queued archive files. PostgreSQL continues running, but the WAL archive becomes incomplete and a new full backup is needed to establish a new recovery chain. See How PITR Works.
When both backup and exporter settings are enabled, pgbackrest_exporter runs on each PostgreSQL node and exposes metrics on port 9854. The monitoring stack uses those metrics for backup age, type, size, duration, and error visibility.
Useful diagnostic entry points include:
| Entry | Purpose |
|---|---|
pb info |
Shell helper for pgbackrest info using the configured stanza |
/pg/log/pgbackrest/ |
pgBackRest backup, archive, and restore logs |
| `pg-backup full | diff |
See Backup Administration for operational checks, then PITR Tradeoffs for policy design.
A backup is an insurance policy. Its premium is storage, network traffic, and operational work; its benefit is how much data can be recovered and how quickly service can return. There is no universal free policy: more history normally needs more capacity, while a shorter RTO normally needs newer backups and tested procedures.
Designing a policy means answering three questions: where is the repository, how long is history retained, and how often are backups taken?
Repository location is the most important decision because it defines which disasters the backup survives.
A local repository (pgbackrest_method: local) stores backups on the primary’s local filesystem. It is simple, fast, and has no remote service dependency. But data and backup normally share one host failure domain: loss of the machine, disk, or filesystem can destroy both. Local backup protects well against logical errors, but not total host loss unless /pg/backup is deliberately placed on independent storage.
An object-storage repository (pgbackrest_method: minio or a custom S3 definition) sends backups to Silo or S3. It becomes an independent disaster-recovery copy only when deployed outside the database host or site failure domain. Pigsty’s minio preset also enables AES-256-CBC repository encryption, bundling, and block incremental backup. Recovery throughput then depends on the network and storage service, and that service adds operational responsibility.
| Scenario | Recommended repository | Reason |
|---|---|---|
| Development, test, demo | local |
Minimal dependencies; rebuild is acceptable |
| Production | Dedicated Silo or compatible S3 storage | Independent failure domain and encrypted repository |
| Cloud deployment | Managed S3-compatible or cloud object storage supported by pgBackRest | Independent storage and lower operational burden |
| Ransomware/compliance | Versioned storage plus correctly configured object lock/retention | Prevent privileged database-host access from deleting protected versions |
The backup repository is itself sensitive business data. Change the default access keys and cipher_pass, restrict access, protect credentials separately from the database hosts, and verify any object-lock policy. See Backup Repository.
Longer retained history generally consumes more storage, but compression, deduplication, block incremental backup, database change rate, and the mix of full/differential/incremental backups determine the actual amount. Measure real backup and WAL growth instead of relying on a fixed multiplier.
For an illustrative 100 GB database changing by 10 GB per day, before compression:
local preset policy): about 200 GB of full backups plus WAL, commonly giving roughly a one-to-two-day window when every job succeeds.minio preset policy): the oldest surviving weekly chain commonly produces roughly 14–21 days of coverage. Capacity must include multiple full backups, their incrementals, archived WAL, and transient retention-plus-one behavior during expiration.The precise window is not the configuration number alone. It runs from the oldest usable backup chain to the newest WAL present in the surviving repository. pgBackRest’s time retention removes an old full only when another qualifying full can satisfy the period, and related incrementals and WAL follow the retained full chains. Check pig pb info, monitor archive health, and prove coverage with a restore.
Choose a window long enough to cover the delay between an error occurring and being detected. A dropped table may be noticed in minutes; slow corruption or a month-end reconciliation failure can take weeks to surface.
Restore time has two main components: restore a backup chain, then replay WAL to the target. Backup size and storage throughput shape the first; the distance between the chosen backup and target shapes the second.
WAL replay is largely serial. On a write-heavy database, restoring from a weekly full immediately before the next full can require nearly a week of replay. Daily incremental backups reduce that replay distance while transferring only changes since the previous backup. They still depend on a valid chain, so monitor and test the entire chain rather than only the newest file.
A useful rule is: within the available backup window and production load budget, take backups often enough that measured restore time meets the RTO.
Pigsty provides two candidate repository definitions, but pgbackrest_method selects one for the generated repo1 configuration.
Standard policy: local repository and daily full backup. It is simple and restores through local I/O, making it suitable for development or environments where host-level disaster recovery is provided separately:
Production policy: remote Silo/S3 repository, weekly full, daily incremental. It separates the repository failure domain and uses the encrypted minio preset:
Do not describe the default pgbackrest_repo dictionary as a “dual-repository” setup: it contains alternative definitions, and the template renders only pgbackrest_repo[pgbackrest_method] as repo1. A real multi-repository pgBackRest design requires explicit advanced configuration and an independently tested backup, expiration, and restore workflow; the two Pigsty presets alone do not create it.
Use Backup Policy for capacity modelling and schedule details.
Monitoring a successful backup job is necessary but insufficient. Add clone restore drills to routine operations so you can answer:
A clone recovery leaves the source cluster online but overwrites the designated destination cluster, so verify the exact target and use disposable infrastructure. See Declarative Recovery for the recovery interface.
The value of a backup system is realized at restore time, often during an incident when every minute matters. A traditional PITR procedure requires a long sequence of coupled manual steps: pause HA, stop PostgreSQL, prepare recovery settings, restore the backup, replay WAL, validate the target, rebuild metadata, and start the cluster again.
Pigsty applies the same approach used by declarative configuration to recovery: declare the recovery target, then let the orchestration tools stop the cluster, restore the data, replay WAL, and return control to the operator.
Describe the target with the pg_pitr parameter and execute it with pgsql-pitr.yml.
The most common form restores a cluster to a specific time:
The six recovery target types and the rest of the recovery behavior are expressed through fields in this parameter:
See Restore Operations for the complete field reference and examples.
pgsql-pitr.yml turns the manual recovery workflow into six stages and supports Ansible tags for staged execution:
| Stage | Action |
|---|---|
| Print the source cluster, target, and restore command; this stage reports the plan and does not prompt for confirmation | |
| pause | Run patronictl pause so Patroni does not intervene during maintenance |
| stop | Stop Patroni and PostgreSQL on replicas, then on the primary |
| pitr | Render recovery settings, run an incremental pgBackRest restore, start PostgreSQL to replay WAL, wait for consistency, and print control data |
| etcd | Remove stale cluster metadata from etcd so old and new timelines are not mixed |
| start | Start Patroni again, resume HA management, and rebuild replicas |
Several details are important:
delta, so it rewrites only files that differ from the backup. For large databases, this can reduce RTO substantially.pg_controldata; an operator must still verify that the recovered business state is correct.backup: true, the original data directory is moved to /pg/data-backup before recovery. A later run with backup: true removes an existing /pg/data-backup, so this is not a versioned snapshot store.-t down, -t pitr, and -t up separately when you want an operator checkpoint between phases. Completion of the pitr phase means PostgreSQL reached a consistent recovery state; for a time, XID, LSN, or named target, also confirm WAL replay reached that target.The action field controls what happens at the target: promote opens a new timeline, pause waits at the target for inspection, and shutdown stops PostgreSQL there.
A targeted recovery defaults to pause when action is omitted. To preserve a manual gate for pause or shutdown, run the stages separately; a one-shot recovery should choose promote explicitly.
The playbook performs the mechanical workflow, but it cannot decide whether the recovered data is correct.
pig
The pig CLI provides single-instance PITR orchestration directly on a database node, without requiring the management node or an Ansible environment:
pig pitr validates the target, stanza, and available backups; stops Patroni and PostgreSQL; performs the restore; optionally starts PostgreSQL; and prints post-recovery instructions.
For a Patroni-managed data directory, Patroni remains stopped afterward. Validate the data, then use pig pt start to return the instance to HA management.
This single-node workflow does not clear etcd, rebuild replicas, or automatically rejoin the cluster, and it refuses destructive forced shutdown unless --force-stop is supplied explicitly.
The lower-level pig pb commands wrap pgBackRest: pb info lists backups, pb backup creates a backup, and pb restore performs a raw restore.
There is a deliberate safety boundary: pig pb restore refuses to run while Patroni still manages the instance, because Patroni could restart PostgreSQL during the restore.
Use pig pitr or pgsql-pitr.yml for Patroni-managed instances.
The same mechanism supports two different workflows:
| Dimension | In-place recovery | Clone recovery |
|---|---|---|
| Method | Roll the production cluster back | Restore a source backup into a different cluster |
| Downtime | Required during recovery | The source production cluster remains online |
| Effect | Discards all writes after the target | Does not affect the source; the destination is overwritten and can be retried |
| Best for | Whole-cluster corruption or disaster recovery | Recovering deleted objects, audit work, and recovery drills |
For a clone recovery, the cluster field names the source backup stanza.
This example restores the historical state of pg-meta into pg-test without stopping the source cluster:
Exporting an accidentally deleted table from the clone and importing it into production is generally safer than rolling the entire production cluster back. See Clone a Database Cluster for the complete workflow and cleanup steps.
Recovery completion is not the end of the incident. Include these steps in the closeout checklist:
pg-backup full so a recoverable window exists on the new timeline.archive: false, restore normal archiving as described in Post-Recovery.The tools execute the procedure; operators still decide the target, whether to restore in place or into a clone, and whether the recovered data is correct. Continue with PITR Scenarios for that decision framework.
During an incident, the most expensive resource is often decision time. Pigsty can orchestrate the mechanical recovery steps, but an operator must still answer three questions: what is the target, should recovery be in place or into a clone, and how will the result be validated?
Read and rehearse this framework before an incident.
| Scenario | Typical problem | Recommended workflow | Target |
|---|---|---|---|
| Accidental DML | DELETE or UPDATE affects the wrong rows |
Clone, validate, then copy back data | time / xid |
| Dropped table, schema, or database | DROP or an incorrect migration |
Clone, validate, then copy back objects | time / name |
| Defective release or batch corruption | Software writes incorrect data for a period | Clone and compare before choosing repair or cutover | time / xid |
| Audit, investigation, or forensics | Inspect historical state | Clone and hold at the target for inspection | time / lsn |
| Whole-cluster or site loss | Hosts or storage are gone or encrypted | Recover in place on replacement infrastructure | default / time |
Two principles apply throughout:
flowchart TD
A["Data error detected"] --> B["Contain the source of bad writes"]
B --> C{"Can production still serve?"}
C -->|Yes| D["Clone recovery<br/>validate and copy back or cut over"]
C -->|No| E["In-place recovery<br/>or rebuild on new infrastructure"]
D --> F["Validate, take a new backup, review the incident"]
E --> FA DELETE without WHERE, an incorrect UPDATE, or a defective batch job is the most common PITR use case.
First locate the error using application logs, PostgreSQL logs, metrics, or audit records. A timestamp is usually sufficient. If the exact transaction ID is known, xid plus exclusive: true can stop immediately before that transaction.
Validate the recovered rows, then copy only the required data back with pg_dump, COPY, or an application-specific reconciliation procedure. If a configured delayed cluster is still inside its delay window, reading from it may be faster than PITR.
The same approach applies to DROP TABLE, DROP DATABASE, or a migration executed in the wrong environment, with an even stronger preference for a clone. Rolling the entire production cluster back to recover one object also discards every legitimate write after the target.
Restore a separate destination to before the DDL, validate the object, export it with pg_dump, and import it into production. For planned high-risk changes, create a named restore point with pg_create_restore_point() beforehand; a name target then removes timestamp ambiguity.
When a faulty release corrupts data for hours, the challenge is usually identifying the last clean state and the full impact. A clone provides a clean comparison set. Restore repeatedly to candidate times, compare it with production, and decide whether to copy back corrected rows or cut over to a recovered cluster.
This decision needs application-owner validation: a successful PostgreSQL restore proves consistency at a target, not that the target represents correct business state.
Questions such as “what was this balance at month end?” require historical state. Restore into a separate destination, stop at a time, LSN, XID, or named restore point, and inspect without altering the source.
action: pause is the targeted-restore default and holds recovery at the target for inspection; it does not itself configure read-only access or create a separate cluster. The inventory limit and cluster source field determine the destination workflow. Run -t down, -t pitr, and -t up separately when you need an operator gate before promotion, and enforce read-only access explicitly if the investigation requires it. immediate means “stop at the first consistent point,” not “choose a historical timestamp.”
If every database host is destroyed or encrypted, HA cannot help. Recovery requires a repository and the other control-plane assets to have survived outside that failure domain. That survivor can be Silo/S3, another protected host or filesystem, or another tested pgBackRest backend; a remote object store is recommended but the essential property is independent failure-domain survival.
Rebuild hosts, restore the declarative inventory, credentials, and PKI, point the cluster at the surviving repository, then restore through the end of archived WAL:
Inventory and backup data are necessary but not sufficient. Preserve installation media or package repositories, repository credentials and encryption passwords, CA material, custom files, DNS dependencies, and an independently accessible runbook. Keep secrets encrypted and separate from both the database hosts and ordinary source control.
The first end-to-end execution of any of these workflows should not occur during a production incident. Use a disposable destination to rehearse clone recovery regularly and after material architecture changes. Measure three outcomes:
See Restore Operations and Clone a Database Cluster for the task-level runbooks.
Pigsty’s monitoring system has three pillars—metrics, logs, and alerting—and is available out of the box. Logs and alerts are also important inputs for audit and traceability. It can monitor clusters managed by Pigsty, existing PostgreSQL clusters, and external RDS services.
Pigsty monitoring covers these core targets:
| Component | Purpose |
|---|---|
| Grafana | Visualization dashboards, unified entry point, alert views |
| VictoriaMetrics | Time-series metric ingestion, storage, and query |
| VictoriaLogs | Structured log ingestion, indexing, and search |
| VMAlert + Alertmanager | Alert rule evaluation and notification delivery |
| Exporter / Agent | Database/system metric exposure and log forwarding |
Pigsty supports three monitoring onboarding modes:
| Mode | Use Case | Entry |
|---|---|---|
FULL |
Database is deployed and managed directly by Pigsty | PGSQL Monitoring System |
MANAGED |
Existing PostgreSQL cluster with SSH-manageable nodes | Monitor Existing Cluster |
RDS |
Cloud database accessible only by connection string | Monitor RDS |
The database is usually the most sensitive component in an information system: it stores the most valuable data, so attacks and failures can have the most serious consequences. Database security is not a feature that can be enabled with one switch. It is the combined answer to a series of questions: Who can connect? What can they do after connecting? Can traffic be intercepted? Are operations recorded? Can damaged, lost, or deleted data be recovered?
Pigsty turns these answers into an out-of-the-box security baseline and manages it through declarative configuration: HBA rules, roles and privileges, certificates, encryption, backups, and audit policies are declared as parameters in the inventory, then rendered and applied by idempotent playbooks.
This Security as Code approach is itself an important security practice. Policies can be versioned, reviewed, and traced, while one inventory provides a consistent baseline across many instances. When an auditor asks who can access a database, you can start from a readable YAML declaration, then verify the generated HBA rules and database grants against the running system.
In traditional operations, security settings are often scattered across the environment: pg_hba.conf on one server, a GRANT statement executed manually by a DBA, or a firewall rule opened temporarily during an incident.
Over time, documentation and actual state can drift, making it difficult to determine which rule set each instance is using.
Pigsty takes a different approach: security policy is part of the cluster definition and lives alongside other cluster properties.
Users, privileges, and HBA rules are described declaratively, and playbooks apply them idempotently to every cluster instance.
New instances inherit the same policy, and Git history records security configuration changes. Manual GRANT statements, runtime parameter changes, and edits to node files can still cause drift, so production environments should compare declared and actual state regularly.
Reasonable defaults reduce omissions. The following capabilities are enabled in the default Pigsty configuration:
| Capability | Default Behavior | Related Parameter |
|---|---|---|
| Password hashing | New or updated PostgreSQL passwords use SCRAM-SHA-256 | pg_pwd_enc |
| Data checksums | Page checksums are enabled during cluster initialization to detect silent corruption | pg_checksum |
| Server-side TLS | PostgreSQL server certificates are installed and ssl is enabled, so TLS connections are accepted |
— |
| Local CA | A self-signed CA is created automatically for managed component certificates | ca_create |
| etcd encryption and authentication | TLS for client and peer traffic, plus RBAC password authentication | etcd_root_password |
| MINIO object storage HTTPS | Silo backup traffic uses HTTPS by default | minio_https |
| Nginx HTTPS | Web ingress listens on both ports 80 and 443 by default | nginx_sslmode |
| HBA rules | Layered access: local ident, intranet password authentication, and SSL required for public administrator access | pg_default_hba_rules |
| Roles and privileges | A four-tier role model and default privilege templates provide a least-privilege baseline | pg_default_roles |
| Backup and recovery | pgBackRest is enabled by default, with two full backups retained in the local repository | pgbackrest_enabled |
| Firewall | Zone mode trusts intranet CIDRs and exposes only required ports to public networks | node_firewall_mode |
| Restricted sudo | Sudo access for the database OS user is limited to the required command set | pg_dbsu_sudo |
The default configuration targets deployments on a trusted intranet. Some controls require explicit enablement because they impose performance or compatibility costs, or require decisions from the operator:
./configure -g to randomize the credentials it recognizes, then check the pgBackRest encryption passphrase, Silo users in ha/safe, and all custom values.patroni_ssl_enabled, pgbouncer_sslmode); enable it explicitly with the certificates already issued.passwordcheck) and the audit extension (pgaudit) are disabled by default. Confirm package availability, then configure preloading and policy before use.permissive. Demo configurations also expose port 5432 through the firewall; remove that exception in production.minio repository preset uses AES-256 encryption by default, but its default encryption passphrase must be changed.The ha/safe hardening template combines TLS, certificate authentication, password checks, and backup encryption.
Together with the consistency-first CRIT parameter template, it provides a practical starting point. Public credentials, audit extensions, and the failure model still require explicit review.
See the Security Model for the complete upgrade path.
| Section | Question Answered |
|---|---|
| Security Model | Where is the root of trust? How many defensive layers exist? How should the baseline be hardened? |
| Authentication | Who can connect? How is identity proven? How are HBA rules declared and applied? |
| Access Control | What can a connected user do? How does least privilege become the default? |
| Encrypted Communication | How is traffic encrypted? Who issues, distributes, and rotates certificates? |
| Data Security | How is data kept intact, recoverable, confidential, and traceable? |
| Compliance | How do security capabilities map to MLPS and SOC 2 controls? |
Beyond the conceptual model, these pages provide operational security guidance:
ha/safe Template: complete hardening configuration referenceBefore examining individual security features, answer two more fundamental questions: Where is the root of trust? and How many defensive layers exist? The first determines what deserves the strongest protection. The second determines what remains when one layer fails.
Pigsty is an Ansible-based declarative deployment system. Like other control-plane systems, its admin node is the control plane and the node that requires the strongest protection.
| Role | Assets and Privileges |
|---|---|
| Admin node | The pigsty.yml inventory, which normally contains system and application credentials; the CA private key; SSH administration access to every node |
| INFRA nodes | Monitoring and alerts, DNS, Nginx ingress, and software repositories |
| Database nodes | Database instances, local dbsu, and restricted sudo |
| Clients | Database credentials or client certificates; access through service ports, HBA, and authentication |
These roles hold different capabilities; they do not form a simple linear hierarchy. Three assets are especially important:
pigsty.yml inventory contains component passwords and credentials. Strictly control access to the admin node and to the configuration repository when Git is used.files/pki/ca/ca.key, is the trust anchor for the deployment. Anyone holding it can issue an arbitrary trusted certificate. The file uses mode 0600 inside a 0700 directory; keep an offline backup.Pigsty’s security policy states this boundary explicitly: an attack that requires admin-node access, or possession of both pigsty.yml and the CA private key, is not treated as a product vulnerability.
These are high-trust control-plane assets by design and must be protected accordingly.
Defense in depth does not ask one mechanism to solve every problem. It combines controls so that one failure does not remove all protection. Pigsty’s security capabilities can be summarized as seven layers:
| # | Layer | Mechanisms | Details |
|---|---|---|---|
| 1 | Network boundary | Firewall zones, constrained listen addresses, centralized ingress | This page |
| 2 | Transport encryption | Local CA and TLS between components | Encrypted Communication |
| 3 | Authentication | HBA rules, SCRAM passwords, client certificates | Authentication |
| 4 | Access control | Role model, default privileges, database isolation | Access Control |
| 5 | Host security | SELinux, restricted sudo, dedicated OS users | This page |
| 6 | Data security | Checksums, backup and encryption, PITR, deletion safeguards | Data Security |
| 7 | Audit trail | DDL and connection logs, audit extensions, centralized logs | Data Security |
Layers 2, 3, 4, 6, and 7 have dedicated chapters. The following sections cover the network and host layers.
Pigsty enables a firewall during node provisioning (node_firewall_mode defaults to zone), using firewalld or ufw according to the operating system.
Intranet CIDRs (10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16, defined by node_firewall_intranet) enter the trusted zone.
Public networks can reach only ports declared in node_firewall_public_port, which defaults to 22 for SSH and 80/443 for web traffic.
The default demo inventory,
pigsty.yml, also exposes port5432for local evaluation. Remove it in production. If direct database access is required, restrict sources to explicit CIDRs with security groups, host firewalls, and HBA.
PostgreSQL listens on all addresses by default (pg_listen: 0.0.0.0). The effective access boundary is the combination of listen addresses, firewall rules, and HBA. Stricter environments can constrain the listener:
The default firewall does not expose Grafana, VictoriaMetrics, or other web infrastructure directly to public networks. External web access normally enters through the Nginx portal. Database traffic enters through HAProxy service ports. Fewer entry points are easier to harden and audit.
The central host-level rule is: each OS user receives only the privileges required for its job.
postgres (pg_dbsu) has no password by default and can enter the database only through local ident authentication.
pg_dbsu_sudo defaults to limit, allowing passwordless systemctl operations for database services and log viewing rather than unrestricted root access.node_admin_username, default dba) is used by operators and playbooks and receives passwordless sudo (nopass) by default.
Security-sensitive environments can set node_admin_sudo to all, which requires a sudo password, or limit, which restricts the command set.node_selinux_mode defaults SELinux to permissive: violations are logged but not blocked, providing a baseline before moving to enforcing.Pigsty does not manage the SSH server configuration. Disabling password login, restricting remote root login, and similar operating-system hardening belong in your host security baseline.
Security does not have to jump to its final state in one step. Pigsty provides an upgrade path in which each level builds on the previous one:
Level 1: default baseline. Out-of-the-box controls include SCRAM passwords, data checksums, a local CA and component certificates, layered HBA, a four-tier role model, default backups, and firewall zones. This level suits development, testing, and evaluation on a trusted intranet. Production still requires credential review, network-boundary review, and client verification.
Level 2: randomized credentials. Default passwords are documented publicly and must be changed in every network-exposed deployment. Add -g when generating configuration to randomize built-in parameters and example credentials recognized by the configuration wizard:
This option does not replace the pgBackRest cipher_pass, every Silo example credential in ha/safe, or user-defined values. See the Default Credentials Checklist for the complete scope.
Level 3: policy hardening with the ha/safe template. conf/ha/safe.yml combines several controls into a starting point for further customization:
ssl, public administrator access uses a client certificate, PgBouncer uses require, and the Patroni API uses HTTPS. Local ident and selected localhost password rules remain.passwordcheck is preloaded explicitly, and built-in users declare expire_in. Example passwords in the template still require review and replacement.${ip},${vip},${lo}, and public connection-pool access by monitoring and administration accounts is denied explicitly.minio repository preset with AES-256-CBC. pgBR.${pg_cluster} is a predictable example value and must be replaced.passwordcheck, credcheck, pgaudit, pgsodium, anonymizer, and related extensions are installed. Installation does not preload, create, or configure an extension.Level 4: database hardening with the crit.yml parameter template. The safe template selects the CRIT parameter template for consistency-first workloads. Compared with the general oltp template, it:
pg_checksum;synchronous_mode_strict), blocking writes that require synchronous acknowledgment when no synchronous replica is available;automatic, which activates only when a usable device exists.Strict synchronous mode targets preservation of acknowledged transactions, but still depends on synchronous_commit, synchronous replica state, and failover eligibility. Validate RPO with failure exercises on the target topology.
You can also select individual controls instead of adopting the complete template:
PostgreSQL uses pg_hba.conf for Host-Based Authentication: who may connect, from where, to which database, and how they must prove their identity.
The mechanism is powerful, but expensive to maintain manually across a cluster. Primary and replica instances may require different rules, and every instance stores its own configuration in the data directory. Without a common declaration and refresh process, rules can drift between instances.
Pigsty applies the same declarative configuration model here: HBA rules are part of the inventory and are rendered and distributed consistently by playbooks.
Cluster HBA policy combines two parameter groups: the global defaults in pg_default_hba_rules and cluster-specific additions in pg_hba_rules.
The PgBouncer connection pool has two independent counterparts: pgb_default_hba_rules and pgb_hba_rules.
A rule can use either of two forms. The recommended alias form keeps one semantic rule on one line:
The raw form supplies a literal pg_hba.conf line for cases the aliases cannot express.
In addition to user, address, database, and authentication method, each rule has two control fields:
order: render order. HBA uses first-match semantics, so order is priority. By convention, 0-99 is reserved for high-priority user rules, 100-999 for defaults, and rules without order come last.role: instance-role filter. common and default apply to every instance; primary, replica, offline, standby, and delayed apply only to matching instances.
A role: offline rule is also rendered on instances marked with pg_offline_query. The same declaration therefore produces the appropriate rules for each instance role without maintaining primary and replica files manually.After editing the declaration, apply it with the wrapper script. The rules are rendered again and reloaded:
pg_hba_rules appends rules; it does not automatically narrow broader defaults. To establish a stricter boundary, review pg_default_hba_rules as well, then inspect the generated pg_hba.conf on every instance.
The alias form gives common cases semantic names. Values in addr expand into concrete address blocks:
| Alias | Expands To | Meaning |
|---|---|---|
local |
Unix socket | Local socket only |
localhost |
Unix socket, 127.0.0.1/32, and ::1/128 |
Local host |
admin |
<admin_ip>/32 |
Admin node |
infra |
/32 address of each INFRA node |
Infrastructure nodes |
cluster |
/32 address of every cluster member |
Cluster-internal traffic |
intra |
10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 |
Intranet CIDRs, customizable with node_firewall_intranet |
world |
0.0.0.0/0 and ::/0 |
Any address |
| CIDR | Unchanged | Custom network |
Values in auth select the authentication method and whether TLS is mandatory:
| Alias | Authentication Method | Notes |
|---|---|---|
deny |
reject |
Explicit rejection |
trust |
trust |
Unconditional access; use with care |
pwd |
scram-sha-256 or md5 |
Follows pg_pwd_enc; SCRAM by default |
sha |
scram-sha-256 |
Force SCRAM |
md5 |
md5 |
Compatibility for legacy clients |
ssl |
hostssl with password authentication |
Password authentication over mandatory TLS |
ssl-sha |
hostssl with scram-sha-256 |
Mandatory TLS and SCRAM |
cert |
hostssl with cert |
Client certificate authentication |
ident, os |
ident (peer in PgBouncer) |
OS user mapping |
peer |
peer |
Local OS user |
The user field supports four placeholders, replaced with actual user names during rendering: ${dbsu} (superuser), ${repl} (replication user), ${monitor} (monitoring user), and ${admin} (administration user).
A +role prefix matches all members of that role.
Do not confuse transport enforcement with server verification: auth: ssl requires TLS but does not require the client to verify the server identity. Security-sensitive clients should also use sslmode=verify-full with a trusted CA; see Encrypted Communication.
Pigsty’s default HBA policy follows a simple rule: the farther the source, the stronger the requirement. These are the PostgreSQL defaults from the source configuration:
Layer by layer:
postgres can enter only through a local Unix socket with ident. No password is required, but remote login is impossible. This is why dbsu has no password by default.PgBouncer defaults are more restrictive: public access for monitoring and administration accounts is explicitly denied, while application users are limited to localhost and intranet sources.
The default +dbrole_offline rule does not set role and therefore applies to every instance. To restrict offline users to pg_role: offline or instances with pg_offline_query: true, add role: offline explicitly to the corresponding HBA rule.
This default policy favors usability: application accounts can connect from the intranet with password authentication.
The ha/safe template changes the main TCP rules to ssl and requires administrators outside the intranet to present a client certificate (cert); local ident and selected localhost password rules remain.
Pigsty uses PostgreSQL’s recommended scram-sha-256 password storage by default (pg_pwd_enc). Downgrade to md5 only for legacy client compatibility.
Before executing ALTER USER ... PASSWORD, the password workflow temporarily disables statement logging (SET log_statement TO 'none') to keep passwords out of PostgreSQL logs.
Plaintext passwords still appear in the inventory, and rendered user SQL is written to /pg/tmp/pg-user-<name>.sql with mode 0640. The related Ansible tasks do not use no_log consistently. Restrict access to the admin node, configuration repository, and automation output, and avoid --diff on tasks containing credentials.
Password strength is not enforced by default. If required, preload passwordcheck or the more configurable credcheck:
The ha/safe template sets this pg_libs value explicitly. Selecting the CRIT parameter template alone does not load passwordcheck.
Declare account lifetime with expire_in (days after creation) or expire_at (absolute date), then combine it with the organization’s rotation process:
Passwords can be phished, reused, or guessed. For privileged accounts such as administrators, use auth: cert in HBA to require client certificate authentication.
The client must present a certificate signed by the local CA whose CN matches the database user name. When the HBA rule accepts only cert, a leaked password alone cannot authenticate.
Issue client certificates with the built-in cert.yml playbook:
The certificate and key are stored in files/pki/misc/<cn>.crt and files/pki/misc/<cn>.key. Deliver the private key through a controlled channel. The client should still use verify-full to authenticate the database server; see Encrypted Communication.
The database is not the only authenticated entry point.
The PgBouncer connection pool uses an independent HBA policy and user list. pgbouncer_auth_query is disabled by default, so only users declared with pgbouncer: true are written to userlist.txt and can authenticate through the pool. Re-evaluate the login scope before enabling dynamic authentication queries.
The Patroni REST API carries high-availability control operations such as restart, switchover, and configuration reload. Write operations require HTTP Basic authentication (patroni_username and patroni_password) and are restricted by source-address allowlists.
When patroni_ssl_enabled is enabled, the API uses HTTPS throughout.
Credentials for Grafana, the HAProxy administration interface, the object-storage backend selected by the MINIO module, etcd, and other components are also declared in the inventory. See the Default Credentials Checklist for the full list and update guidance.
Authentication answers “Who are you?” Authorization answers “What may you do?”
Privilege failures rarely result from a lack of mechanisms—PostgreSQL GRANT and REVOKE are sufficiently precise. The usual problem is the absence of conventions that are applied by default:
an application account is made the owner at launch, temporary superuser access is not revoked after troubleshooting, or grants are missed when new tables are created and cause failures in production.
Pigsty provides an out-of-the-box access control model as a starting point: four role tiers, default privileges, and database isolation. It reduces per-database manual grants, but operators must still assign roles according to business boundaries and review effective privileges regularly.
Pigsty creates four business roles by default. They cannot log in and are used as privilege groups:
| Role | Attribute | Inherits | Purpose |
|---|---|---|---|
dbrole_readonly |
NOLOGIN |
— | Global read-only access |
dbrole_readwrite |
NOLOGIN |
dbrole_readonly |
Global DML access; the default choice for application accounts |
dbrole_admin |
NOLOGIN |
dbrole_readwrite, pg_monitor |
Object creation and DDL for administration and release workflows |
dbrole_offline |
NOLOGIN |
— | Independent read-only role that can be restricted to offline instances through HBA |
Pigsty also creates four system users, each with a specific responsibility:
| User | Attribute | Purpose |
|---|---|---|
postgres |
SUPERUSER |
Database superuser; no password and local ident login only |
replicator |
REPLICATION |
Streaming replication and backup, with pg_monitor and read-only privileges |
dbuser_dba |
SUPERUSER |
Routine administration user that inherits dbrole_admin |
dbuser_monitor |
— | Monitoring user with only pg_monitor and read-only privileges |
Application accounts join role groups through the roles field and inherit their privileges:
The role system is itself declarative (pg_default_roles) and can be customized.
This parameter is a complete list. Preserve all required system users and default roles when changing it, and check references from HBA rules, default privileges, and scripts at the same time.
Roles answer “Who receives a privilege?” The other half of the problem is: How do newly created objects receive the correct privileges automatically?
PostgreSQL provides ALTER DEFAULT PRIVILEGES. Pigsty declares these rules through pg_default_privileges:
The read-only role receives query and function execution privileges, the read-write role adds DML, and the administrator role adds the supporting privileges required for object management.
Default privileges have an often-missed prerequisite: they apply only to objects created by identities for which those defaults were configured. Pigsty configures default privileges for:
pg_dbsu, which defaults to postgres;pg_admin_username, which defaults to dbuser_dba;dbrole_admin;pg_databases.Application DDL should normally run as the declared database owner. Platform administration and release workflows can use dbuser_dba or first execute SET ROLE dbrole_admin. Objects created directly by other users do not enter this default privilege model unless ALTER DEFAULT PRIVILEGES is also configured for those users.
This is PostgreSQL behavior, not a Pigsty limitation: default privileges follow the object creator; they do not automatically propagate from the database or the session login name.
PostgreSQL grants CONNECT on databases to PUBLIC by default. If HBA also permits a connection, a login role may enter a database it does not own. This default is particularly important to tighten when several applications share a cluster.
Set revokeconn in a database definition to revoke public connection access:
When enabled, CONNECT is revoked from PUBLIC and granted explicitly to the replication, monitoring, and administration users and to the database owner.
The owner receives GRANT OPTION and can decide who else may connect. Without additional grants or inherited roles, the app_a account cannot connect to app_b.
Cluster initialization also revokes CREATE from PUBLIC on the database and the public schema:
Ordinary users can no longer create objects freely in public databases or schemas, reducing risks from unsafe search_path settings and object shadowing.
PostgreSQL 15 tightened the default CREATE privilege on the public schema; Pigsty applies the same boundary consistently across all supported major versions.
dbrole_offline provides an independent set of read-only privileges for ETL, reporting, and ad hoc queries. The role controls object privileges only; it does not automatically restrict which instance a user may connect to.
In the current default HBA rules, the intranet rule for +dbrole_offline does not set role and therefore applies to every instance. To restrict it to a dedicated pg_role: offline instance, or to a regular replica marked with pg_offline_query: true, modify that rule in the complete pg_default_hba_rules list:
Defining pg_default_hba_rules replaces the entire default list; the example rule cannot be used alone. Expensive queries are limited to offline instances only when HBA filters by instance role and the user does not inherit another role allowed by broader rules. Resource isolation should also use a dedicated service endpoint, connection limits, and query resource controls.
Least privilege also applies at the host level:
postgres superuser has no password and can log in only through local ident. Its sudo access defaults to a restricted set of database service and log commands (pg_dbsu_sudo: limit).dbuser_monitor holds pg_monitor, the read-only role, and privileges on the dedicated monitor schema; it cannot write business tables by default.replicator receives only the directory function privileges required for backup and recovery instead of broad superuser access.TLS can provide three separate protections: transport encryption, server authentication, and client authentication. Each must be configured independently. Enabling server-side TLS does not mean the client verifies the server identity, nor does it mean the server requires a client certificate.
The main operational cost of TLS is not the encryption algorithm but certificate issuance, distribution, trust, and rotation. Without centralized management, internal services often encrypt traffic while skipping certificate verification—or remain on plaintext connections.
Pigsty brings PKI under declarative management. During deployment it creates a local self-signed CA, issues certificates for managed components, and distributes trust so TLS is ready for use after installation.
During the first deployment, Pigsty checks for a CA on the admin node and creates one when required:
| File | Description | Permissions |
|---|---|---|
files/pki/ca/ca.key |
CA private key and root of trust for the deployment; protect it carefully | 0600, with directory mode 0700 |
files/pki/ca/ca.crt |
CA root certificate; safe to distribute | 0644 |
ca_create controls CA behavior. An existing private key and certificate are reused unchanged; if the certificate is missing but the private key exists, that key is used to issue a replacement certificate.
ca_create: false only prevents creation of a missing CA private key. Deployment stops if ca.key is absent, preventing an unexpected trust root. Always back up and restore ca.key and ca.crt together.ca_cn sets the CA certificate CN, which defaults to pigsty-ca. The key is RSA 4096.cert_validity: 7300d).
The browser-facing Nginx certificate is an exception and currently defaults to 397 days.Long default lifetimes reduce the initial maintenance burden for private infrastructure; they do not remove the need for production rotation. Organizations with an established certificate policy should shorten lifetimes and monitor expiration.
Issuing a certificate is only half of PKI. Every node must trust it. When a node is managed, Pigsty distributes the CA certificate to /etc/pki/ca.crt and links it into the operating system trust store:
/etc/pki/ca-trust/source/anchors/ and run update-ca-trust/usr/local/share/ca-certificates/ and run update-ca-certificatesClients that use the OS trust store, such as curl, can then verify certificates signed by the Pigsty CA.
The CA certificate is also published as ca.crt at the site root of the Nginx portal for browsers and external clients.
PostgreSQL libpq clients require special attention: by default they look for ~/.postgresql/root.crt and use sslmode=prefer, so they do not directly use the operating system trust store to verify the server identity.
Security-sensitive PostgreSQL clients should use sslmode=verify-full and specify the Pigsty CA:
verify-full validates both the certificate chain and the connection host name. The DNS name or IP address used by the client must therefore appear in the server certificate SAN. External clients must install ca.crt or specify it with sslrootcert.
The local CA issues certificates for the following components and places them under one trust chain:
| Component | Certificate Identity (CN) | Deployment Path | Encryption State |
|---|---|---|---|
| PostgreSQL | <cluster>-<sequence> |
/pg/cert/server.{crt,key} |
Server-side SSL enabled by default; HBA determines whether it is mandatory |
| PgBouncer | Reuses the PostgreSQL certificate | /pg/cert/ |
TLS disabled by default (pgbouncer_sslmode) |
| Patroni | Reuses the PostgreSQL certificate | /pg/cert/ |
API HTTPS disabled by default (patroni_ssl_enabled) |
| etcd | <instance-name> |
/etc/etcd/server.{crt,key} |
TLS for client and peer traffic |
| Silo | <node-name> |
~minio/.minio/certs/ |
Silo HTTPS is enabled by default (minio_https) |
| Kafka | <cluster>-<sequence> |
/etc/kafka/pki/kafka.pem |
SASL_SSL/SSL with kafka_security: scram; defaults to plaintext |
| MySQL | <instance-name> |
/etc/mysql/pki/server.{crt,key} |
Secure transport enforced; clients and group replication verify the certificate chain |
| Nginx | pigsty, with portal domains in SAN |
/etc/nginx/conf.d/cert/ |
HTTPS enabled by default (nginx_sslmode) |
| INFRA node | <node-name> |
/etc/pki/infra.{crt,key} |
Available to infrastructure components |
The encryption-state column reflects deliberate defaults:
ha/safe template.Keep three states distinct: server-side SSL support does not force clients to use SSL, and neither state proves that the client verifies the server identity.
HBA rules enforce encryption with auth: ssl or cert. Client sslmode and trust settings control server verification. The default rules require TLS only for administrator connections from arbitrary sources. The safe template changes the main TCP rules to ssl or cert while retaining local ident and selected localhost password rules.
The built-in cert.yml playbook issues client certificates. The certificate CN represents the database user name for HBA cert authentication:
Results are stored in files/pki/misc/<cn>.key and files/pki/misc/<cn>.crt. Deliver private keys through a controlled channel and make them readable only by the corresponding user. The client certificate lets the server authenticate the client; the client must still use verify-full to authenticate the database server.
If the organization already operates a PKI, Pigsty can issue certificates from that CA, or from an intermediate signed by the enterprise root. Place the certificate and private key at the expected paths; playbooks do not regenerate a CA when one already exists:
Also set ca_create: false. Deployment will then fail explicitly if the private key is missing instead of creating an unexpected trust root. This setting does not stop the role from reissuing the CA certificate when the private key exists but the certificate is missing, so verify and restore both files together.
pigsty.yml, it is one of the highest-trust assets in the deployment; see Trust Boundaries. Keep an offline backup.files/pki/<component>/ on the admin node; node certificates are deployment copies. Deleting only a node copy restores the same certificate rather than issuing a new one. To rotate, update or remove the corresponding source on the admin node, rerun the relevant playbook, then reload or roll the component as required.Network boundaries, authentication, and access control reduce the likelihood of an incident. When hardware fails, credentials leak, or an operator makes a mistake, data-layer controls must limit the impact and support recovery.
Data security answers four questions: Is the data intact? Can it be recovered? If copied, does it remain confidential? Can you determine what happened?
Bad disk sectors, memory bit flips, and storage firmware defects can cause silent data corruption: the data is damaged without an immediate error.
Pigsty enables page checksums by default (pg_checksum: true).
The cluster is initialized with data-checksums, so PostgreSQL calculates a checksum when writing a page and verifies it when reading.
Page checksums primarily detect corruption in storage media, the I/O path, or pages after they were written. They do not detect every memory error, logical error, or incorrect application write, and they do not replace backups.
The CRIT parameter template goes further: checksums are mandatory regardless of the parameter, and strict synchronous replication (synchronous_mode_strict) blocks writes that require synchronous acknowledgment when no synchronous replica is available.
This mode targets preservation of acknowledged transactions, but it still assumes clients have not reduced synchronous_commit, a synchronous replica participates in the commit, and failover selects only a node containing the required WAL. Validate RPO through failure exercises on the target topology.
Replicas primarily handle node failures; backups handle accidental deletion, logical errors, cluster corruption, and broader disasters. High availability can shorten an interruption after primary failure, but replication also copies an accidental deletion to every replica. Backups are therefore indispensable.
Pigsty enables pgBackRest by default (pgbackrest_enabled).
Base backups plus continuous WAL archiving provide Point-in-Time Recovery (PITR), allowing recovery to a target time within the retained backup and WAL window.
Select the backup repository with pgbackrest_method:
| Repository | Location | Default Retention | Encryption |
|---|---|---|---|
local (default) |
Local /pg/backup directory |
Latest 2 full backups | None |
minio |
Silo or external S3-compatible object storage | 14 days | AES-256-CBC |
Two additional controls reduce damage from accidental deletion:
pg_delay: 1h replica for a critical cluster. Before an erroneous operation is replayed, pause replication and extract the required data. A delayed replica eventually catches up and does not replace a backup.pg_safeguard or etcd_safeguard is enabled, the corresponding removal playbook refuses to run, reducing the risk of accidental cluster removal.Having a backup is not the same as being able to restore. Recovery exercises should be routine; see Backup and Recovery for mechanisms and procedures.
Protect data at rest at three layers:
Backup encryption. pgbackrest_method: minio denotes an S3-compatible repository. It can be provided by Silo deployed through the MINIO module, or independently managed MinIO, RustFS, and external S3 services. The preset uses AES-256-CBC by default, but the public pgBackRest passphrase must be changed in production.
The ha/safe template derives an example passphrase from the cluster name:
pgBR.${pg_cluster} is predictable, and configure -g does not replace it. Use a unique random passphrase in production and store it separately from the backup. Losing the passphrase makes the backup unrecoverable.
The local backup repository is not encrypted by default. Encryption reduces disclosure if backup files or media are copied separately, but offers limited protection when the key and backup remain on the same host.
Transport encryption. Backup uploads to Silo or external S3 services use HTTPS. PostgreSQL client and replication traffic can require SSL through HBA. Clients should also verify the server certificate; see Encrypted Communication.
Encryption at rest. Upstream PostgreSQL currently has no general built-in transparent data encryption (TDE). Pigsty provides two practical options:
use the pg_tde extension with Percona Distribution for PostgreSQL for table-level transparent encryption (see the pgtde configuration template);
or use security extensions such as pgsodium, pgcrypto, and anonymizer for column-level encryption and masking. The safe template installs this extension category.
Full-disk encryption such as LUKS or dm-crypt protects against stolen media at the operating-system layer and complements database-level controls.
After an incident, you must be able to answer who did what and when. Pigsty provides layered logging:
Default baseline: all DDL is logged (log_statement: ddl), and statements taking longer than 100 ms are logged (log_min_duration_statement: 100).
PostgreSQL 18 and later also record connection authorization events.
CRIT template: connection and disconnection events are recorded with log_connections and log_disconnections. PostgreSQL 18 can distinguish connection receipt, authentication, and authorization stages.
pgaudit extension: for fine-grained statement auditing such as object reads and writes or role-based audit classes, install pgaudit and add it to pg_libs for preloading.
The safe template installs the extension, but loading and audit policy must be declared explicitly.
When INFRA logging is enabled and Vector is configured, PostgreSQL logs are sent to VictoriaLogs for centralized storage. The default retention is 15 days and can be adjusted for compliance. Logs and metrics support search, alerts, and incident reconstruction, but incident classification, response, and evidence preservation still require an operational process.
Compliance is not a product you can buy. It is a state that must be demonstrated continuously through three elements:
This page begins with a pre-launch hardening checklist and then maps Pigsty security capabilities to common compliance frameworks. The mappings support architecture and gap analysis; they are not an MLPS assessment conclusion, a SOC 2 audit opinion, or legal advice.
Pigsty default credentials are public in the documentation and source code. They are intended only for demonstrations and local development. Change every applicable default before any production or network-exposed deployment goes live:
| Scope | Example Default | configure -g |
|---|---|---|
| Grafana administrator and viewer | pigsty, DBUser.Viewer |
Yes |
| HAProxy administration interface | pigsty |
Yes |
| PostgreSQL administration, monitoring, and replication users | DBUser.DBA, DBUser.Monitor, DBUser.Replicator |
Yes |
| Patroni REST API | Patroni.API |
Yes |
| etcd root | Etcd.Root |
Yes |
| MINIO module object-storage root | S3User.MinIO |
Yes |
| Object-storage backup and example application users | S3User.Backup, S3User.Meta, S3User.Data |
Yes |
| Example database users | DBUser.Meta, DBUser.Supa, Vibe.Coding |
Yes |
| pgBackRest encryption passphrase | cipher_pass: pgBackRest |
No |
Silo users and pgBR.${pg_cluster} in ha/safe |
Template example values | No |
| User-defined credentials | Custom values | No |
Use -g while generating configuration to randomize built-in parameters and example strings recognized by the configuration wizard:
The wizard prints generated passwords to the terminal, so protect terminal history and automation logs as sensitive data. After generation, inspect the configuration and replace pgBackRest cipher_pass, MINIO module example values in ha/safe that were not covered, and all custom credentials.
Before deployment:
5432sslmode=verify-full and a trusted CAexpire_inha/safe template and the CRIT parameter template
After deployment:
configure -g and uncovered backup, object-storage, and custom credentials have all been changed/pg/data/pg_hba.conf against the declaration and intended boundaryCONNECT grants, and compare them with the inventory
Periodically:
pg_users declarations with effective grants, and remove expired or departed-user accounts
Declarative configuration provides a stable starting point for audit evidence. Retain runtime state as well to show that the configuration was applied and remains effective.
| Evidence | Source |
|---|---|
| Security baseline and change history | The pigsty.yml inventory and Git history |
| Access-control matrix | pg_default_roles, pg_users, and pg_hba_rules declarations |
| Effective authentication policy | Rendered pg_hba.conf on each instance, compared with declarations to detect drift |
| Effective users and privileges | PostgreSQL catalogs, database ACLs, \du+, and \ddp+ |
| Operation and connection logs | PostgreSQL DDL, slow-query, and connection logs retained in VictoriaLogs |
| Backup records | pgBackRest information and monitoring dashboards |
| Security incidents and alerts | Monitoring alert history |
| Certificate inventory | files/pki/ and deployed component certificates |
The following maps database-related Pigsty capabilities to controls in the “secure computing environment” section of GB/T 22239-2019 Level 3:
| Control | Pigsty Capability | Additional Requirement |
|---|---|---|
| Unique identity | Independent accounts and SCRAM-SHA-256 password storage | Real-name account management process |
| Password complexity and rotation | passwordcheck, credcheck, and expire_in |
Enable extensions and establish a rotation process |
| Login failure handling | Can be implemented with credcheck and related extensions |
Enable and configure as required |
| Access control and least privilege | Four-tier roles, default privileges, and database isolation | Privilege approval workflow |
| Security audit | DDL, connection, and slow-query logs; pgaudit; centralized retention |
CRIT or manual connection logging; required retention period |
| Communication confidentiality | Local CA and TLS; HBA-enforced ssl or cert |
Enforce TLS, client verify-full, and certificate rotation |
| Data integrity | Page checksums by default and strict synchronous replication with CRIT | Storage protection, defined failure model, and exercises |
| Data confidentiality | AES-encrypted backup plus TDE and column-encryption options | Enable as required |
| Backup and recovery | pgBackRest, PITR, and a remote S3-compatible repository | Recovery exercise process |
| Residual information protection | — | Media destruction and erasure process |
MLPS also covers physical security, communication networks, and management systems beyond the scope of a database distribution. Pigsty can support database-related technical controls in a secure computing environment; facilities, network devices, and governance must be addressed in the overall system.
Database-related controls in the SOC 2 Trust Services Criteria (TSC) include:
| Criterion | Pigsty Capability | Additional Requirement |
|---|---|---|
| CC6.1 Logical access security | HBA, RBAC, default privileges, and database isolation | Privilege design, approval, and periodic review |
| CC6.2 User registration and authorization | Declarative users, roles, and expiration | Joiner, mover, leaver, and identity-verification process |
| CC6.3 Access changes and revocation | pg_users, role changes, REVOKE, and expiration |
Tickets, approval evidence, and timely revocation |
| CC6.6 External boundary threats | Firewalls, listen addresses, HBA, and restricted management ingress | Network architecture, boundary devices, and continuous validation |
| CC6.7 Information transmission and movement | TLS, client verification, and backup encryption | Policies for exports, media, and third-party transfer |
| CC7.2 System monitoring | Victoria observability stack with extensive metrics and alerts | Alert-response process |
| CC7.3 Incident traceability | Centralized logs and audit extensions | Log-review process |
| A1.2 Availability and recovery | High Availability and PITR | Exercise records and RTO/RPO objectives |
Compliance reviews increasingly cover the software supply chain. Pigsty provides the following distribution and response controls:
Package integrity: RPM and DEB packages in the Pigsty repositories (repo.pigsty.io and repo.pigsty.cc) are GPG-signed.
The public-key fingerprint is 9592 A7BC 7A68 2E73 3337 6E09 E793 5D8D B9BD 8B20 (B9BD8B20) and can be verified before trust is established. Repository definitions written during deployment and the local repository on the INFRA node do not enforce signature verification for every package by default; review package-manager repository trust and signature settings in production.
Vulnerability response: report security issues privately through GitHub private vulnerability reporting or email, as documented in SECURITY.md. The project targets acknowledgment within three business days and an initial assessment within seven days.
Version support: security fixes ship with the latest stable release. Staying current is the standard way to receive them. Users who must remain on a version for longer can obtain extended support through subscription services.
ha/safe Template: hardening configuration examplePigsty runs on Linux, supporting amd64/x86_64 and arm64/aarch64 arch, plus 3 major distros: EL, Debian, Ubuntu.
Pigsty runs bare-metal without containers. Supports actively maintained mainstream releases across the 3 major distro families and both archs.
Recommended OS versions: Rocky Linux 9.8 / 10.2, Debian 12.15 / 13.6, Ubuntu 22.04.5 / 24.04.4 / 26.04.0.
| Distro | Arch | OS Code | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|---|---|
| RHEL / Rocky / Alma 10 | x86_64 | el10.x86_64 |
|||||
| RHEL / Rocky / Alma 10 | aarch64 | el10.aarch64 |
|||||
| RHEL / Rocky / Alma 9 | x86_64 | el9.x86_64 |
|||||
| RHEL / Rocky / Alma 9 | aarch64 | el9.aarch64 |
|||||
Ubuntu 26.04 (resolute) |
x86_64 | u26.x86_64 |
|||||
Ubuntu 26.04 (resolute) |
aarch64 | u26.aarch64 |
|||||
Ubuntu 24.04 (noble) |
x86_64 | u24.x86_64 |
|||||
Ubuntu 24.04 (noble) |
aarch64 | u24.aarch64 |
|||||
Ubuntu 22.04 (jammy) |
x86_64 | u22.x86_64 |
|||||
Ubuntu 22.04 (jammy) |
aarch64 | u22.aarch64 |
|||||
Debian 13 (trixie) |
x86_64 | d13.x86_64 |
|||||
Debian 13 (trixie) |
aarch64 | d13.aarch64 |
|||||
Debian 12 (bookworm) |
x86_64 | d12.x86_64 |
|||||
Debian 12 (bookworm) |
aarch64 | d12.aarch64 |
These seven minor releases are the current validation baselines. The extension repository retains dual-architecture EL8 compatibility, so the complete package matrix covers 16 Linux platforms. EL8 is in its retirement transition and is no longer a recommended deployment baseline.
Pigsty supports RHEL / Rocky / Alma / Anolis / CentOS 8, 9, 10.
| EL Distro | Arch | OS Code | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|---|---|
| RHEL10 / Rocky10 / Alma10 | x86_64 | el10.x86_64 |
|||||
| RHEL10 / Rocky10 / Alma10 | aarch64 | el10.aarch64 |
|||||
| RHEL9 / Rocky9 / Alma9 | x86_64 | el9.x86_64 |
|||||
| RHEL9 / Rocky9 / Alma9 | aarch64 | el9.aarch64 |
|||||
| RHEL8 / Rocky8 / Alma8 | x86_64 | el8.x86_64 |
|||||
| RHEL8 / Rocky8 / Alma8 | aarch64 | el8.aarch64 |
|||||
| RHEL7 / CentOS7 | x86_64 | el7.x86_64 |
|||||
| RHEL7 / CentOS7 | aarch64 | - |
Rocky Linux 9.8 / 10.2 balances stability and fresh software. Recommended for EL users.
EL8 goes EOL in 2029. Plan upgrade ASAP. EL10 support is ready, EL8 will be dropped in next release.
RHEL 7 EOL since Jun 2024. PGDG stopped providing binary packages for PG 16/17/18 on EL7.
For extended support on legacy OS, consider Enterprise Subscription.
Pigsty supports Ubuntu 26.04 / 24.04 / 22.04:
| Ubuntu Distro | Arch | OS Code | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|---|---|
Ubuntu 26.04 (resolute) |
x86_64 | u26.x86_64 |
|||||
Ubuntu 26.04 (resolute) |
aarch64 | u26.aarch64 |
|||||
Ubuntu 24.04 (noble) |
x86_64 | u24.x86_64 |
|||||
Ubuntu 24.04 (noble) |
aarch64 | u24.aarch64 |
|||||
Ubuntu 22.04 (jammy) |
x86_64 | u22.x86_64 |
|||||
Ubuntu 22.04 (jammy) |
aarch64 | u22.aarch64 |
Ubuntu 26.04 provides the newest LTS baseline, while Ubuntu 24.04 remains the conservative default for Ubuntu users.
Pigsty supports Debian 12 / 13, latest Debian 13.6 recommended:
| Debian Distro | Arch | OS Code | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|---|---|
Debian 13 (trixie) |
x86_64 | d13.x86_64 |
|||||
Debian 13 (trixie) |
aarch64 | d13.aarch64 |
|||||
Debian 12 (bookworm) |
x86_64 | d12.x86_64 |
|||||
Debian 12 (bookworm) |
aarch64 | d12.aarch64 |
|||||
Debian 11 (bullseye) |
x86_64 | d11.x86_64 (historical) |
|||||
Debian 11 (bullseye) |
aarch64 | - |
Debian 11 EOL since Jul 2024. For extended support on legacy OS, consider Enterprise Subscription.
For local VM deployment, use these Vagrant base images (same as used in Pigsty dev):
cloud-image/rocky-8: Rocky 8.10cloud-image/rocky-9: Rocky 9.8cloud-image/rocky-10: Rocky 10.2cloud-image/debian-12: Debian 12.15cloud-image/debian-13: Debian 13.6cloud-image/ubuntu-22.04: Ubuntu 22.04.5cloud-image/ubuntu-24.04: Ubuntu 24.04.4cloud-image/ubuntu-26.04: Ubuntu 26.04.0For cloud deployment, use these Terraform base image prefixes (Aliyun example):
| x86_64 | Aliyun Image Prefix |
|---|---|
| Rocky 8.10 | rockylinux_8_10_x64 |
| Rocky 9.8 | rockylinux_9_8_x64 |
| Rocky 10.2 | rockylinux_10_2_x64 |
| Ubuntu 22.04.5 | ubuntu_22_04_x64_20G |
| Ubuntu 24.04.4 | ubuntu_24_04_x64_20G |
| Ubuntu 26.04.0 | ubuntu_26_04_x64_20G |
| Debian 12.15 | debian_12_15_x64 |
| Debian 13.6 | debian_13_6_x64 |
| aarch64 | Aliyun Image Prefix |
|---|---|
| Rocky 8.10 | rockylinux_8_10_arm64 |
| Rocky 9.8 | rockylinux_9_8_arm64 |
| Rocky 10.2 | rockylinux_10_2_arm64 |
| Ubuntu 22.04.5 | ubuntu_22_04_arm64_20G |
| Ubuntu 24.04.4 | ubuntu_24_04_arm64_20G |
| Ubuntu 26.04.0 | ubuntu_26_04_arm64_20G |
| Debian 12.15 | debian_12_15_arm64 |
| Debian 13.6 | debian_13_6_arm64 |
| Module | Category | Status | Docs Path | Summary |
|---|---|---|---|---|
PGSQL |
Core | GA | /docs/pgsql |
High-availability PostgreSQL clusters with built-in backup, monitoring, SOP, and extension ecosystem. |
INFRA |
Core | GA | /docs/infra |
Local software repository + VictoriaMetrics/Logs/Traces + Grafana infrastructure stack. |
NODE |
Core | GA | /docs/node |
Node initialization and convergence: system tuning, admin, HAProxy, Vector, Keepalived, etc. |
ETCD |
Core | GA | /docs/etcd |
DCS for PostgreSQL HA (service discovery, config, leader-election metadata). |
MINIO |
Extension | GA | /docs/minio |
Deploys Silo S3-compatible object storage, suitable for PostgreSQL backups. |
REDIS |
Extension | GA | /docs/redis |
Redis by default, or Valkey, in standalone, Sentinel, or native-cluster mode with monitoring. |
DOCKER |
Extension | GA | /docs/docker |
Docker daemon and the runtime capability for containerized apps. |
JUICE |
Extension | BETA | /docs/juice |
JuiceFS distributed file system using PostgreSQL as metadata engine. |
VIBE |
Extension | BETA | /docs/vibe |
Browser-based dev environment with Code-Server, JupyterLab, Node.js, Claude Code, and Codex CLI. |
KAFKA |
Extension | BETA | /docs/kafka |
Apache Kafka 4.x dynamic KRaft cluster deployment, security baseline, and monitoring. |
Pigsty provides four core modules that are important for delivering complete highly available PostgreSQL services:
PGSQL: Self-healing PostgreSQL clusters with HA, PITR, IaC, SOP, monitoring, and 575 extensions.INFRA: Local software repository, VictoriaMetrics, VictoriaLogs, VictoriaTraces, Grafana, Alertmanager, Blackbox Exporter…NODE: Node convergence for hostname, timezone, NTP, SSH, sudo, HAProxy, Vector, and Keepalived.ETCD: Distributed key-value store used as DCS for HA PostgreSQL clusters: consensus leader election/config management/service discovery.Although these four modules are usually installed together, separate use is still feasible. In practice, only the NODE module is usually mandatory.
Pigsty provides six extension modules. They are not mandatory for core functionality, but can enhance PostgreSQL capabilities:
MINIO: An S3-compatible object-storage module that deploys Silo and provides PostgreSQL backup integration and monitoring.REDIS: Redis server with standalone/sentinel/cluster production deployment and full monitoring support.DOCKER: Docker daemon service for one-click deployment of stateless software templates on Pigsty.JUICE: JuiceFS distributed filesystem module using PostgreSQL as metadata engine, providing shared POSIX storage.VIBE: Browser-based development environment with Code-Server, JupyterLab, Node.js, Claude Code, and Codex CLI.KAFKA: Apache Kafka 4.x dynamic KRaft clusters with TLS/SCRAM/ACL security baseline, declarative topics/users, and full monitoring.The modules below are closely related to the PostgreSQL ecosystem. They are optional ecosystem capabilities and are not counted in the 10 official modules above:
SUPABASE, DUCKDB: peripheral ecosystem integration.MSSQL, IVORY, POLAR, CITUS, CLOUDBERRY, PGEDGE: kernel replacement, distributed, and MPP forms.MYSQL-compatible kernel (OpenHalo), ORIOLE, PGTDE, AGENS: protocol compatibility, storage engine, transparent encryption, and graph database kernels. Here, MYSQL means the pg_mode=mysql PostgreSQL-compatible kernel, not a native MySQL service.GREENPLUM, NEON: historical docs retained, no longer default public capabilities.MYSQL pilot: the current mysql.yml, mysql-rm.yml, and roles/mysql* manage a fixed native MySQL 8.4 platform with either one node or a three-node single-primary InnoDB Cluster. It remains a PILOT and is not counted among the 10 official modules above.KUBE, VICTORIA, JUPYTER: other pilot modules, currently not open for public use.Pigsty’s home directory is located at ~/pigsty by default. The file structure within this directory is as follows:
~/pigsty Source Tree
/infra is a runtime symlink to /data/infra, which keeps observability data and generated configuration together:
Pigsty’s self-signed CA is located in files/pki/ under the Pigsty home directory.
You must keep the CA key file secure: files/pki/ca/ca.key. This key is generated by the ca role during deploy.yml or infra.yml execution.
Nodes managed by Pigsty will have the following certificate files installed:
All infra nodes will have the following certificates:
When your admin node fails, the files/pki directory and pigsty.yml file should be available on the backup admin node. You can use rsync to achieve this:
The infra role creates infra_data (default: /data/infra) and creates a symlink /infra -> /data/infra.
/data/infra permissions are root:infra 0771; subdirectories default to *:infra 0750 unless overridden:
This structure is created by: roles/infra/tasks/dir.yml, roles/infra/tasks/victoria.yml, roles/infra/tasks/register.yml, roles/infra/tasks/dns.yml, and roles/infra/tasks/env.yml.
The node data directory is specified by node_data, defaulting to /data, owned by root:root with mode 0755.
Most core components place their default data directories here. Some pilot modules use fixed paths of their own; native MySQL 8.4 currently uses /var/lib/mysql.
Pigsty starts HAProxy with its own systemd unit and manages the main configuration separately from service fragments:
To append startup arguments in /etc/default/haproxy, use EXTRAOPTS and retain the default -S /run/haproxy-master.sock. The systemd unit already loads configuration with explicit -f arguments, so do not add another -f to EXTRAOPTS.
Monitoring config has moved from the legacy /etc/prometheus layout to the /infra runtime layout.
The main template is roles/infra/templates/victoria/prometheus.yml, rendered to /infra/prometheus.yml.
files/victoria/bin/* and files/victoria/rules/* are synced to /infra/bin/ and /infra/rules/, while each module registers FileSD targets under /infra/targets/*.
Pigsty-rendered INFRA units are consistently stored in /etc/systemd/system/, including vmetrics, vlogs, vtraces, vmalert, alertmanager, blackbox_exporter, nginx_exporter, and dnsmasq. Distribution package unit directories are not write targets for these roles.
The following parameters and internal variables are related to PostgreSQL directory layout:
pg_dbsu_home: Postgres default user home directory, default: /var/lib/pgsqlpg_bin_dir: Postgres binary directory, default: /usr/pgsql/bin/pg_fs_main: Postgres primary data directory, default: /data/postgrespg_fs_backup: Postgres backup disk mount point, default: /data/backups (optional; can also be a subdirectory on primary disk)pg_data: Internal variable, fixed to the Postgres data-directory symlink /pg/datapg_cluster_dir: Derived variable, {{ pg_fs_main }}/{{ pg_cluster }}-{{ pg_version }}pg_backup_dir: Derived variable, {{ pg_fs_backup }}/{{ pg_cluster }}-{{ pg_version }}Data File Structure
Binary File Structure
On EL-compatible distributions (using yum), PostgreSQL default installation location is:
Pigsty creates a symlink named /usr/pgsql pointing to the actual version specified by the pg_version parameter, for example:
Therefore, the default pg_bin_dir is /usr/pgsql/bin/, and this path is added to the system PATH environment variable, defined in: /etc/profile.d/pgsql.sh.
On Ubuntu/Debian, the default PostgreSQL Deb package installation location is:
Pigsty-rendered PostgreSQL runtime units are likewise stored in /etc/systemd/system/. They primarily include patroni.service, postgres.service, pgbouncer.service, pg_exporter.service, pgbackrest_exporter.service, pgbouncer_exporter.service, and vip-manager.service when VIP is enabled.
Pgbouncer runs under the same user as {{ pg_dbsu }} (default postgres), with configs in /etc/pgbouncer.
pgbouncer.ini: main pool configuration (postgres:postgres 0640)database.txt: pooled database definitions (postgres:postgres 0600)useropts.txt: per-user connection options (postgres:postgres 0600)userlist.txt: password file maintained by /pg/bin/pgb-userpgb_hba.conf: access control file (postgres:postgres 0600)The MINIO module currently deploys only Silo, while retaining minio_* parameter and directory names for compatibility:
Silo certificates are stored in /home/minio/.minio/certs/. The module name, role parameters, data directory, and FileSD path retain the compatible MINIO / minio_* naming.
Pigsty manages Redis or Valkey with the same directory layout and instance naming.
Service units call binaries according to redis_type (/bin/* is compatible with /usr/bin/* on most distributions):
For a Redis instance named redis-test-1-6379, the related resources are as follows:
Pigsty-rendered Redis/Valkey instance and exporter units are consistently stored in /etc/systemd/system/, and instance units use Type=notify. Package-provided units may still live in distribution directories, but those are not role write targets.
This is the parameter navigation page for Pigsty v4.x, without repeating full explanations for each parameter.
For parameter details, please read each module’s param page.
Cross-checked against the current source and parameter reference pages, the 10 official modules expose 373 public parameters. Native MySQL 8.4 remains a pilot module; its 13 public parameters are listed separately and are not included in the official-module total.
| Module | Groups | Count | Description |
|---|---|---|---|
PGSQL |
9 | 124 | PostgreSQL HA cluster configuration |
INFRA |
10 | 73 | Software repository and Victoria-based observability infra |
NODE |
11 | 73 | Node initialization, system tuning, and ops baseline |
ETCD |
2 | 13 | ETCD cluster and removal safeguard parameters |
MINIO |
2 | 22 | Silo deployment, observability, and removal parameters |
REDIS |
2 | 22 | Redis/Valkey deployment and removal parameters |
DOCKER |
1 | 8 | Docker engine parameters |
JUICE |
1 | 2 | JuiceFS instance and cache parameters |
VIBE |
1 | 18 | Code/Jupyter/Node.js/Claude/Codex configuration |
KAFKA |
2 | 18 | Kafka deployment and removal safeguard parameters |
Pilot module: native MYSQL 8.4 currently exposes 13 public parameters: 11 for deployment and 2 for protected removal. Fixed ports, paths, software versions, and timers are not public parameters.
| Module | Major Groups |
|---|---|
PGSQL |
PG_ID, PG_BUSINESS, PG_INSTALL, PG_BOOTSTRAP, PG_PROVISION, PG_BACKUP, PG_ACCESS, PG_MONITOR, PG_REMOVE |
INFRA |
META, CA, INFRA_ID, REPO, INFRA_PACKAGE, NGINX, DNS, VICTORIA, PROMETHEUS, GRAFANA |
NODE |
NODE_ID, NODE_DNS, NODE_PACKAGE, NODE_TUNE, NODE_SEC, NODE_ADMIN, NODE_TIME, NODE_VIPHAPROXY, NODE_EXPORTER, VECTOR |
ETCD |
ETCD, ETCD_REMOVE |
MINIO |
MINIO, MINIO_REMOVE |
REDIS |
REDIS, REDIS_REMOVE |
DOCKER |
DOCKER |
JUICE |
JUICE |
VIBE |
VIBE |
KAFKA |
KAFKA, KAFKA_REMOVE |
This page summarizes Pigsty v4.x playbook entries and usage guidance by module. For detailed task tags, open each module’s playbook page.
| Module | Count | Playbooks |
|---|---|---|
INFRA |
3 | deploy.yml infra.yml infra-rm.yml |
NODE |
2 | node.yml node-rm.yml |
ETCD |
2 | etcd.yml etcd-rm.yml |
PGSQL |
7 | pgsql.yml pgsql-rm.yml pgsql-user.yml pgsql-db.yml pgsql-monitor.yml pgsql-migration.yml pgsql-pitr.yml |
REDIS |
2 | redis.yml redis-rm.yml |
MINIO |
2 | minio.yml minio-rm.yml |
DOCKER |
1 | docker.yml |
JUICE |
1 | juice.yml |
VIBE |
1 | vibe.yml |
KAFKA |
2 | kafka.yml kafka-rm.yml |
MYSQL (pilot) |
2 | mysql.yml mysql-rm.yml |
| Playbook | Module | Purpose |
|---|---|---|
deploy.yml |
INFRA |
One-pass deployment for the core chain (Infra/Node/Etcd/PGSQL, enabling MINIO by config) |
infra.yml |
INFRA |
Initialize infrastructure nodes |
infra-rm.yml |
INFRA |
Remove infrastructure components |
node.yml |
NODE |
Node onboarding and baseline convergence |
node-rm.yml |
NODE |
Node offboarding |
etcd.yml |
ETCD |
ETCD install/scale-out |
etcd-rm.yml |
ETCD |
ETCD remove/scale-in |
pgsql.yml |
PGSQL |
Initialize PostgreSQL cluster or add instance |
pgsql-rm.yml |
PGSQL |
Remove PostgreSQL cluster/instance |
pgsql-user.yml |
PGSQL |
Add business users |
pgsql-db.yml |
PGSQL |
Add business databases |
pgsql-monitor.yml |
PGSQL |
Register remote PostgreSQL for monitoring |
pgsql-migration.yml |
PGSQL |
Generate migration runbook and scripts |
pgsql-pitr.yml |
PGSQL |
Point-in-time recovery (PITR) |
redis.yml |
REDIS |
Deploy Redis |
redis-rm.yml |
REDIS |
Remove Redis |
minio.yml |
MINIO |
Deploy Silo |
minio-rm.yml |
MINIO |
Remove Silo, its configuration, and optional data |
docker.yml |
DOCKER |
Deploy Docker engine |
juice.yml |
JUICE |
Deploy/remove JuiceFS instances |
vibe.yml |
VIBE |
Deploy VIBE dev environment |
kafka.yml |
KAFKA |
Create or converge a complete dynamic KRaft cluster |
kafka-rm.yml |
KAFKA |
Remove a Kafka cluster, or safely retire a single member |
mysql.yml |
MYSQL |
Converge a native MySQL 8.4 single node or three-node InnoDB Cluster (pilot) |
mysql-rm.yml |
MYSQL |
Stop or retire a native MySQL instance or cluster while preserving local state (pilot) |
The following playbooks are cross-module helpers.
| Playbook | Description |
|---|---|
cache.yml |
Build offline installation package cache |
cert.yml |
Issue certificates using Pigsty CA |
app.yml |
Install Docker Compose app templates |
slim.yml |
Minimal component installation scenario |
Several modules provide deletion safeguards through *_safeguard parameters:
pg_safeguardetcd_safeguardminio_safeguardredis_safeguardkafka_safeguardmysql_safeguard and an exact-match mysql_rm_confirm jointly protect native MySQL retirementThe PGSQL, ETCD, MINIO, REDIS, and KAFKA role defaults are explicitly false; set them to true for initialized production clusters. Native MySQL is the exception: mysql_safeguard defaults to true, and even after disabling it you must provide a mysql_rm_confirm value that exactly matches the target instance or cluster.
When safeguard is true, corresponding *-rm.yml playbooks abort immediately. You can force override via CLI:
Use -l to limit execution targets:
For large-scale rollout, validate on one cluster first, then deploy in batches.
Most playbooks are idempotent and safe to rerun, with caveats:
infra.yml does not clean data by default; all clean parameters (vmetrics_clean, vlogs_clean, vtraces_clean, grafana_clean, nginx_clean) default to falsetrue*-rm.yml deletion playbooks requires extra cautionUse -t to run only selected task subsets:
For ordinary convergence, -l must cover every declared member of the selected Kafka cluster; only kafka-rm.yml accepts a single member, for retirement.
mysql-rm.yml stops the service, writes a retirement marker, and deregisters monitoring, but does not delete data directories, backups, configuration, certificates, packages, or InnoDB Cluster metadata.
This page lists default ports used by Pigsty module components. Adjust as needed or use as a reference for fine-grained firewall configuration.
| Module | Component | Port | Parameter | Status |
|---|---|---|---|---|
NODE |
node_exporter |
9100 |
node_exporter_port |
Enabled |
NODE |
haproxy |
9101 |
haproxy_exporter_port |
Enabled |
NODE |
vector |
9598 |
vector_port |
Enabled |
NODE |
keepalived_exporter |
9650 |
vip_exporter_port |
Optional |
NODE |
chronyd |
123 |
- | Enabled |
DOCKER |
docker |
9323 |
docker_exporter_port |
Optional |
INFRA |
nginx |
80 |
nginx_port |
Enabled |
INFRA |
nginx |
443 |
nginx_ssl_port |
Enabled |
INFRA |
nginx_exporter |
9113 |
nginx_exporter_port |
Enabled |
INFRA |
grafana |
3000 |
grafana_port |
Enabled |
INFRA |
victoriaMetrics |
8428 |
vmetrics_port |
Enabled |
INFRA |
victoriaLogs |
9428 |
vlogs_port |
Enabled |
INFRA |
victoriaTraces |
10428 |
vtraces_port |
Enabled |
INFRA |
vmalert |
8880 |
vmalert_port |
Enabled |
INFRA |
alertmanager |
9059 |
alertmanager_port |
Enabled |
INFRA |
blackbox_exporter |
9115 |
blackbox_port |
Enabled |
INFRA |
dnsmasq |
53 |
dns_port |
Enabled |
ETCD |
etcd |
2379 |
etcd_port |
Enabled |
ETCD |
etcd |
2380 |
etcd_peer_port |
Enabled |
MINIO |
Silo S3 API | 9000 |
minio_port |
Optional |
MINIO |
Silo admin port | 9001 |
minio_admin_port |
Optional |
REDIS |
Redis / Valkey | 6379 |
redis_instances |
Optional |
REDIS |
redis_exporter |
9121 |
redis_exporter_port |
Optional |
VIBE |
code-server |
8443 |
code_port |
Optional |
VIBE |
jupyterlab |
8888 |
jupyter_port |
Optional |
KAFKA |
broker |
9092 |
kafka_port |
🧪 BETA |
KAFKA |
KRaft controller |
9093 |
kafka_controller_port |
🧪 BETA |
KAFKA |
kafka_exporter |
9308 |
kafka_exporter_port |
🧪 BETA |
KAFKA |
JMX exporter |
9404 |
kafka_jmx_exporter_port |
🧪 BETA |
MYSQL |
mysqld |
3306 |
Fixed value (the current pilot exposes no port parameter) | 🧪 PILOT |
MYSQL |
MySQL X Protocol |
33060 |
Fixed value; loopback-only on a single node, member-facing in a 3-node topology | 🧪 PILOT |
MYSQL |
Group Replication |
33061 |
Fixed value; three-node InnoDB Cluster only | 🧪 PILOT |
MYSQL |
MySQL Router RW |
6446 |
Fixed value; three-node InnoDB Cluster only | 🧪 PILOT |
MYSQL |
MySQL Router RO |
6447 |
Fixed value; three-node InnoDB Cluster only | 🧪 PILOT |
MYSQL |
mysqld_exporter |
9104 |
Fixed value; controlled by mysql_exporter_enabled |
🧪 PILOT |
PGSQL |
postgres |
5432 |
pg_port |
Enabled |
PGSQL |
pgbouncer |
6432 |
pgbouncer_port |
Enabled |
PGSQL |
patroni |
8008 |
patroni_port |
Enabled |
PGSQL |
pg_exporter |
9630 |
pg_exporter_port |
Enabled |
PGSQL |
pgbouncer_exporter |
9631 |
pgbouncer_exporter_port |
Enabled |
PGSQL |
pgbackrest_exporter |
9854 |
pgbackrest_exporter_port |
Enabled |
PGSQL |
{{ pg_cluster }}-primary |
5433 |
pg_default_services |
Enabled |
PGSQL |
{{ pg_cluster }}-replica |
5434 |
pg_default_services |
Enabled |
PGSQL |
{{ pg_cluster }}-default |
5436 |
pg_default_services |
Enabled |
PGSQL |
{{ pg_cluster }}-offline |
5438 |
pg_default_services |
Enabled |
PGSQL |
{{ pg_cluster }}-<service> |
543x |
pg_services |
Optional |
The native MySQL pilot reuses port 3306 for MySQL Shell AdminAPI. XtraBackup is invoked by a local systemd timer and has no listening port, while the role explicitly disables the MySQL Router REST management interface. The table lists only network endpoints currently managed by the role.
If you use firewall zone mode, expose only minimum required ports via node_firewall_public_port:
22, 80, 443 (recommended)5432Avoid exposing internal component ports directly to the public internet: etcd (2379/2380), patroni (8008), exporters (9xxx), object-storage S3/admin endpoints (9000/9001), redis (6379), ferretdb (27017/27018), Kafka (9092/9093), MySQL Group Replication (33061), etc.
“PostgreSQL In Great STYle”: Postgres, Infras, Graphics, Service, Toolbox, it’s all Yours.
—— Battery-included, local-first PostgreSQL distribution, open-source RDS alternative

Pigsty is a better local open-source RDS for PostgreSQL alternative:
PostgreSQL integrates ecosystem tools and best practices:
Get production-grade PostgreSQL database services locally immediately!
PostgreSQL is a near-perfect database kernel, but it needs more tools and systems to become a good enough database service (RDS). Pigsty helps PostgreSQL make this leap. Pigsty solves various challenges you’ll encounter when using PostgreSQL: kernel extension installation, connection pooling, load balancing, service access, high availability / automatic failover, log collection, metrics monitoring, alerting, backup recovery, PITR, access control, parameter tuning, security encryption, certificate issuance, NTP, DNS, parameter tuning, configuration management, CMDB, management playbooks… You no longer need to worry about these details!
Pigsty supports PostgreSQL 14 ~ 18 mainline kernels and other compatible forks, running on EL / Debian / Ubuntu and compatible OS distributions, available on x86_64 and ARM64 chip architectures, without container support required. Besides database kernels and many out-of-the-box extension plugins, Pigsty also provides complete infrastructure and runtime required for database services, as well as local sandbox / production environment / cloud IaaS auto-deployment solutions.
Pigsty can bootstrap an entire environment from bare metal with one click, reaching the last mile of software delivery. Ordinary developers and operations engineers can quickly get started and manage databases part-time, building enterprise-grade RDS services without database experts!
Hyper-converged multi-modal, use PostgreSQL for everything, one PG to replace all databases!
PostgreSQL’s soul lies in its rich extension ecosystem, and Pigsty uniquely deeply integrates 575 extensions from the PostgreSQL ecosystem, providing you with an out-of-the-box hyper-converged multi-modal database!
Extensions can create synergistic effects, producing 1+1 far greater than 2 results. You can use PostGIS for geospatial data, TimescaleDB for time-series/event stream data analysis, and Citus to upgrade it in-place to a distributed geospatial-temporal database; You can use PGVector to store and search AI embeddings, ParadeDB for ElasticSearch-level full-text search, and simultaneously use precise SQL, full-text search, and fuzzy vector for hybrid search. You can also achieve dedicated OLAP database/data lakehouse analytical performance through pg_duckdb, pg_mooncake and other analytical extensions.
Using PostgreSQL as a single component to replace MySQL, Kafka, ElasticSearch, MongoDB, and big data analytics stacks has become a best practice — a single database choice can significantly reduce system complexity, greatly improve development efficiency and agility, achieving remarkable software/hardware and development/operations cost reduction and efficiency improvement.
Flexible composition, free extension, multi-database support, monitor existing RDS/hosts/databases
Components in Pigsty are abstracted as independently deployable modules, which can be freely combined to address varying requirements. The INFRA module comes with a complete modern monitoring stack, while the NODE module tunes nodes to desired state and brings them under management.
Installing the PGSQL module on multiple nodes automatically forms a high-availability database cluster based on primary-replica replication, while the ETCD module provides consensus and metadata storage for database high availability.
Beyond these four core modules, Pigsty also provides a series of optional feature modules: The MINIO module can deploy Silo to provide local object storage and serve as a centralized database backup repository.
The REDIS module can provide auxiliary services for databases in standalone primary-replica, sentinel, or native cluster modes. The DOCKER module can be used to spin up stateless application software.
Additionally, Pigsty provides PG-compatible / derivative kernel support. You can use Babelfish for MS SQL Server compatibility, IvorySQL for Oracle compatibility,
OpenHaloDB for MySQL compatibility, and OrioleDB for ultimate OLTP performance.
Furthermore, you can use PostgreSQL Mongo mode for MongoDB compatibility, Supabase for Firebase compatibility, and PolarDB to meet domestic compliance requirements.
Message queues are covered by the KAFKA module, which deploys Kafka 4.x dynamic KRaft clusters.
More professional/pilot modules will be continuously introduced to Pigsty, such as GPSQL, DUCKDB, TIGERBEETLE, KUBERNETES, CONSUL, GREENPLUM, CLOUDBERRY, MYSQL, …
Using modern open-source observability stack, providing unparalleled monitoring best practices!
Pigsty provides best practices for monitoring based on the open-source Grafana / Prometheus modern observability stack: Grafana for visualization, VictoriaMetrics for metrics collection, VictoriaLogs for log collection and querying, Alertmanager for alert notifications. Blackbox Exporter for checking service availability. The entire system is also designed for one-click deployment as the out-of-the-box INFRA module.
Pigsty automatically monitors every managed component: host nodes, HAProxy load balancers, PostgreSQL databases, PgBouncer connection pools, Etcd metadata stores, Redis-compatible caches, Silo object storage, and the monitoring infrastructure itself. Grafana dashboards and preset alert rules provide immediate operational visibility. The same stack can also monitor applications, existing database instances, and cloud RDS services.
Whether for failure analysis or slow query optimization, capacity assessment or resource planning, Pigsty provides comprehensive data support, truly achieving data-driven operations. In Pigsty, over three thousand types of monitoring metrics are used to describe all aspects of the entire system, and are further processed, aggregated, analyzed, refined, and presented in intuitive visualization modes. From global overview dashboards to CRUD details of individual objects (tables, indexes, functions) in a database instance, everything is visible at a glance. You can drill down, roll up, or jump horizontally freely, browsing current system status and historical trends, and predicting future evolution.
Additionally, Pigsty’s monitoring system module can be used independently — to monitor existing host nodes and database instances, or cloud RDS services. With just one connection string and one command, you can get the ultimate PostgreSQL observability experience.
Visit the Screenshot Gallery and Online Demo for more details.
Out-of-the-box high availability and point-in-time recovery capabilities ensure your database is rock-solid!
For table/database drops caused by software defects or human error, Pigsty provides out-of-the-box PITR point-in-time recovery capability, enabled by default without additional configuration. As long as storage space allows, base backups and WAL archiving based on pgBackRest let you quickly return to any point within the recovery window. You can use local directories/disks, Silo deployed by the MINIO module, or external S3-compatible object-storage services to retain longer recovery windows, according to your budget.
Pigsty provides a high-availability self-healing architecture based on Patroni, etcd, and HAProxy. When the node, network, quorum, and synchronous-replica assumptions hold, it can fail over the primary automatically. Actual RTO and RPO depend on replication mode, failure type, timeout settings, and client reconnection behavior.
Pigsty includes built-in HAProxy load balancers for automatic traffic switching, providing DNS/VIP/LVS and other access methods for clients. Failover and active switchover are almost imperceptible to the business side except for brief interruptions, and applications don’t need to modify connection strings or restart. The minimal maintenance window requirements bring great flexibility and convenience: you can perform rolling maintenance and upgrades on the entire cluster without application coordination. The feature that hardware failures can wait until the next day to handle lets developers, operations, and DBAs sleep well. Many large organizations and core institutions have been using Pigsty in production for extended periods. The largest deployment has 25K CPU cores and 200+ PostgreSQL ultra-large instances; in this deployment case, dozens of hardware failures and various incidents occurred over six to seven years, DBAs changed several times, but still maintained availability higher than 99.999%.
Infra as Code, Database as Code, declarative APIs encapsulate database management complexity.
Pigsty provides services through declarative interfaces, elevating system controllability to a new level: users tell Pigsty “what kind of database cluster I want” through configuration inventories, without worrying about how to do it. In effect, this is similar to CRDs and Operators in K8S, but Pigsty can be used for databases and infrastructure on any node: whether containers, virtual machines, or physical machines.
Whether creating/destroying clusters, adding/removing replicas, or creating new databases/users/services/extensions/whitelist rules, you only need to modify the configuration inventory and run the idempotent playbooks provided by Pigsty, and Pigsty adjusts the system to your desired state. Users don’t need to worry about configuration details — Pigsty automatically tunes based on machine hardware configuration. You only need to care about basics like cluster name, how many instances on which machines, what configuration template to use: transaction/analytics/critical/tiny — developers can also self-serve. But if you’re willing to dive into the rabbit hole, Pigsty also provides rich and fine-grained control parameters to meet the demanding customization needs of the most meticulous DBAs.
Beyond that, Pigsty’s own installation and deployment is also one-click foolproof, with all dependencies pre-packaged, requiring no internet access during installation. The machine resources needed for installation can also be automatically obtained through Vagrant or Terraform templates, allowing you to spin up a complete Pigsty deployment from scratch on a local laptop or cloud VM in about ten minutes. The local sandbox environment can run on a 1-core 2GB micro VM, providing the same functional simulation as production environments, usable for development, testing, demos, and learning.
Pigsty provides the security foundations required for database deployment: layered HBA, built-in roles and default privileges, SCRAM-SHA-256, page checksums, a local CA, component certificates, backup, PITR, centralized logs, and firewall configuration.
The defaults target development, testing, and demonstrations on a trusted intranet. Production deployments must replace public credentials, review network boundaries, enforce TLS where required, configure server-certificate verification, and establish backup recovery, privilege review, and incident-response processes.
Security and Compliance documents each mechanism’s default state and boundary. Security Considerations provides production hardening guidance, and Compliance maps relevant controls to MLPS and SOC 2. Whether a deployment meets a specific requirement depends on scope, organizational process, continuous evidence, and the auditor’s conclusion.
Use preset Docker templates to spin up massive software using PostgreSQL with one click!
In various data-intensive applications, the database is often the trickiest part. For example, the core difference between GitLab Enterprise and Community Edition is the underlying PostgreSQL database monitoring and high availability. If you already have a good enough local PG RDS, you can refuse to pay for software’s homemade database components.
Pigsty provides the Docker module and many out-of-the-box Compose templates. You can use Pigsty-managed high-availability PostgreSQL (as well as Redis and Silo) as backend storage, spinning up these software in stateless mode with one click: GitLab, Gitea, Wiki.js, NocoDB, Odoo, Jira, Confluence, Harbor, Mastodon, Discourse, KeyCloak, Mattermost, etc. If your application needs a reliable PostgreSQL database, Pigsty is perhaps the simplest way to get one.
Pigsty also provides application development toolsets closely related to PostgreSQL: PGAdmin4, PGWeb, ByteBase, PostgREST, Kong, as well as EdgeDB, FerretDB, Supabase — these “upper-layer databases” using PostgreSQL as storage. More wonderfully, you can build interactive data applications quickly in a low-code manner based on the Grafana and Postgres built into Pigsty, and even use Pigsty’s built-in ECharts panels to create more expressive interactive visualization works.
Pigsty provides a powerful runtime for your AI applications. Your agents can leverage PostgreSQL and the powerful capabilities of the observability world in this environment to quickly build data-driven intelligent agents.
Pigsty is free software open-sourced under Apache-2.0, watered by the passion of PostgreSQL-loving community members
Pigsty is completely open-source and free software, allowing you to run enterprise-grade PostgreSQL database services at nearly pure hardware cost without database experts. For comparison, database vendors’ “enterprise database services” and public cloud vendors’ RDS charge premiums several to over ten times the underlying hardware resources as “service fees.”
Many users choose the cloud precisely because they can’t handle databases themselves; many users use RDS because there’s no other choice. We will break cloud vendors’ monopoly, providing users with a cloud-neutral, better open-source RDS alternative: Pigsty follows PostgreSQL upstream closely, with no vendor lock-in, no annoying “licensing fees,” no node count limits, and no data collection. All your core assets — data — can be “autonomously controlled,” in your own hands.
Pigsty itself aims to replace tedious manual database operations with database autopilot software, but even the best software can’t solve all problems. There will always be some rare, low-frequency edge cases requiring expert intervention. This is why we also provide professional subscription services to provide safety nets for enterprise users who need them. Subscription consulting fees of tens of thousands are less than one-thirtieth of a top DBA’s annual salary, completely eliminating your concerns and putting costs where they really matter. For community users, we also contribute with love, providing free support and daily Q&A.
tooltip: { trigger: axis, formatter: $fn:ttfmt }
legend: { top: 4, itemGap: 16, data: [Oracle, Open-Source PG, Cloud RDS, Pigsty over IaaS, Pigsty over IDC ] }
grid: { left: 96, right: 36, bottom: 70, top: 50 }
xAxis:
type: category
name: CPU Cores
nameLocation: middle
nameGap: 36
boundaryGap: false
data: [2, 4, 8, 12, 16, 24, 32, 52, 64, 104, 128, 196, 256, 384, 512]
yAxis:
type: log
logBase: 10
min: 10
name: Monthly Cost (CNY)
axisLabel: { formatter: $fn:yfmt }
splitLine: { show: true, lineStyle: { type: dashed, opacity: 0.5 } }
series:
- { name: Oracle, type: line, symbolSize: 7, lineStyle: { width: 3 }, itemStyle: { color: "#d62728" }, data: [45000, 65000, 105000, 145000, 185000, 265000, 345000, 545000, 665000, 1065000, 1305000, 1985000, 2585000, 3865000, 5145000] }
- { name: Cloud RDS, type: line, symbolSize: 6, lineStyle: { width: 2 }, itemStyle: { color: "#ff7f0e" }, data: [800, 1600, 3200, 4800, 6400, 9600, 12800, 20800, 25600, 41600, 51200, 78400, 102400, 153600, 204800] }
- { name: Pigsty over IaaS, type: line, symbolSize: 6, lineStyle: { width: 2 }, itemStyle: { color: "#2ca02c" }, data: [360, 720, 1440, 2160, 2880, 4320, 5760, 9360, 11520, 18720, 23040, 35280, 46080, 69120, 92160] }
- { name: Pigsty over IDC, type: line, symbolSize: 6, lineStyle: { width: 2 }, itemStyle: { color: "#9467bd" }, data: [38, 76, 152, 228, 304, 456, 608, 988, 1216, 1976, 2432, 3724, 4864, 7296, 9728] }
The Pigsty project began in 2018-2019, originating from Tantan. Tantan is an internet dating app — China’s Tinder, now acquired by Momo. Tantan was a Nordic-style startup with a Swedish engineering founding team.
Tantan had excellent technical taste, using PostgreSQL and Go as its core technology stack. The entire Tantan system architecture was modeled after Instagram, designed entirely around the PostgreSQL database. Up to several million daily active users, millions of TPS, and hundreds of TB of data, the data component used only PostgreSQL. Almost all business logic was implemented using PG stored procedures — even including 100ms recommendation algorithms! It was arguably the most complex PostgreSQL-at-scale use case in China at the time.
This atypical development model of deeply using PostgreSQL features placed extremely high demands on the capabilities of engineers and DBAs. And Pigsty is the open-source project we forged in this real-world large-scale, high-standard database cluster scenario — embodying our experience and best practices as top PostgreSQL experts.
In the beginning, Pigsty did not have the vision, goals, and scope it has today. It started as a PostgreSQL monitoring system for our own use. We surveyed all available solutions — open-source, commercial, cloud-based, datadog, pgwatch, etc. — and none could meet our observability needs. So I decided to build one myself based on Grafana and Prometheus. This became Pigsty’s predecessor and prototype. Pigsty as a monitoring system was quite impressive, helping us solve countless management problems.
Subsequently, developers wanted such a monitoring system on their local development machines, so we used Ansible to write provisioning playbooks, transforming this system from a one-time construction task into reusable, replicable software. New versions allowed users to use Vagrant and Terraform, using Infrastructure as Code to quickly spin up local DevBox development machines or production environment servers, automatically completing PostgreSQL and monitoring system deployment.
Next, we redesigned the production environment PostgreSQL architecture, introducing Patroni and pgBackRest to solve database high availability and point-in-time recovery issues. We developed a zero-downtime migration solution based on logical replication, rolling upgrading two hundred production database clusters to the latest major version through blue-green deployment. And we incorporated these capabilities into Pigsty.
Pigsty is software we built for ourselves. The biggest benefit of “eating our own dog food” is that we are both developers and users — as client users, we know exactly what we need, do not cut corners, and never worry about automating ourselves out of jobs.
We solved problem after problem, depositing the solutions into Pigsty. Pigsty’s positioning also gradually evolved from a monitoring system into an out-of-the-box PostgreSQL database distribution. We then decided to open-source Pigsty and began a series of technical sharing and publicity, and external users from various industries began using Pigsty and providing feedback.
In 2022, the Pigsty project received seed funding from Miracle Plus, initiated by Dr. Qi Lu, allowing me to work on this full-time.
As an open-source project, Pigsty has developed quite well. In these years of full-time work, Pigsty’s GitHub stars grew from a few hundred to 5,213 as of 2026-07-11; it made the HN front page, and growth began snowballing. In November 2025, Pigsty won the Magneto Award at the PostgreSQL Ecosystem Conference. In 2026, Pigsty’s subproject PGEXT.CLOUD was selected for a PGCon.Dev 2026 talk. Pigsty became the first Chinese open-source project to appear on the stage of this core PostgreSQL ecosystem conference.
Previously, Pigsty could only run on CentOS 7, but now it covers all mainstream Linux distributions (EL, Debian, Ubuntu) across 16 operating system platforms. Supported PG major versions cover 14-18, and we maintain and integrate 575 extension plugins in the PG ecosystem. Among these, I personally maintain over half (360+) of the extension plugins, providing out-of-the-box RPM/DEB packages. Including Pigsty itself, “based on open source, giving back to open source,” this is our way of contributing to the PG ecosystem.
Pigsty’s positioning has also continuously evolved from a PostgreSQL database distribution to an open-source cloud database. It truly benchmarks against cloud vendors’ entire cloud database brands.
Public cloud vendors like AWS, Azure, GCP, and Aliyun have provided many conveniences for startups, but they are closed-source and force users to rent infrastructure at exorbitant fees.
We believe that excellent database services, like excellent database kernels, should be accessible to every user, rather than requiring expensive rental from cyber lords.
Cloud computing’s agility and elasticity value proposition is strong, but it should be free, open-source, inclusive, and local-first — We believe the cloud computing universe needs a solution representing open-source values that returns infrastructure control to users without sacrificing the benefits of the cloud.
Therefore, we are also leading a movement and battle to exit the cloud, as rebels against public clouds, to reshape the industry’s values.
I hope that in the future world, everyone will have the de facto right to freely use excellent services, rather than being confined to a few cyber lord public cloud giants’ territories as cyber tenants or even cyber serfs.
This is exactly what Pigsty aims to do — a better, free and open-source RDS alternative. Allowing users to spin up database services better than cloud RDS anywhere (including cloud servers) with one click.
Pigsty is a complete complement to PostgreSQL, and a spicy mockery of cloud databases. It literally means “pigsty,” but it’s also an acronym for Postgres In Great STYle, meaning “PostgreSQL in its full glory.”
Pigsty itself is completely open-source and free software, so you can build a PostgreSQL service that scores 90 without database experts. We sustain operations by providing premium consulting services to take you from 90 to 100, with warranty, Q&A, and a safety net.
A well-built system may run for years without needing a “safety net,” but database problems, once they occur, are never small. Often, expert experience can turn decay into magic, and we provide such premium consulting — we believe this is a more just, reasonable, and sustainable model.
I am Feng Ruohang, the author of Pigsty. Almost all of Pigsty’s code is developed by me alone.
Individual heroism still exists in the software field. Only unique individuals can create unique works — I hope Pigsty becomes such a work.
If you’re interested in me, here’s my personal homepage: https://vonng.com/
“Modb Interview with Feng Ruohang” (Chinese)
“Post-90s, Quit to Start Business, Says Will Crush Cloud Databases” (Chinese)
2026-07-10: Pigsty v4.4.0 officially released: PG19 beta support and 531 extensions
2026-05-01: Pigsty v4.3.0 officially released: 510 extensions, Ubuntu 26 support
2026-03-06: Pigsty v4.2.1 released! Drop PG13, 464 extensions
2026-02-28: Pigsty v4.2 is officially released! Seven kernel updates shipped together
2026-02-12: Pigsty v4.1 is officially released! First distribution batch with PostgreSQL 18.2 support
2026-02-04: Extension for Everyone selected as a PGCon.Dev 2026 talk!
2026-02-03: Pigsty v4.0 Released! Entering the Agent era!
2026-01-30: PIG v1.0 Released! Launched together with the PGEXT.CLOUD extension catalog
2025-12-02: Pigsty v3.7.0 Released! PG18 becomes default, 437 extensions, EL10/Debian13 support
2025-11-29: Pigsty won the PostgreSQL Magneto Award!
2025-08-15: Pigsty v3.6.1 Released! Routine PG minor update, PGDG China regional mirrors
2025-08-04: Pigsty v3.6.0 Released! PostgreSQL meta-distribution
2025-06-16: Pigsty v3.5.0 Released! PG18 beta support, 421 extensions, monitoring upgrade, code refactor
2025-04-21: Pigsty v3.4 Released! MySQL compatibility
2025-03-07: Pigsty v3.3.0 Released! 404 extensions
2025-01: Pigsty v3.2.x release series (v3.2.0 ~ v3.2.2)
PostgreSQL Package Manager pig Released!
2024-11: Pigsty v3.1.0 Released! PG17 default, self-hosted Supabase, ARM/Ubuntu24 support
2024-08 ~ 2024-10: Pigsty v3.0.x release series (v3.0.0 ~ v3.0.4)
2024-08: Pigsty supplementary repository provides 254 additional ready-to-use binary RPM/DEB extensions!
2024-05: Pigsty v2.7 Released!
2024-02: Pigsty v2.6 Released!
| Date | Type | Event | Topic |
|---|---|---|---|
| 2025-11-29 | Award&Talk | The 8th Conf of PG Ecosystem (Hangzhou) | PostgreSQL Magneto Award, A World-Grade Postgres Meta Distribution |
| 2025-05-16 | Lightning | PGConf.Dev 2025, Montreal | Extension Delivery: Make your PGEXT accessible to users |
| 2025-05-12 | Keynote | PGEXT.DAY, PGCon.Dev 2025 | The Missing Package Manager and Extension Repo for PostgreSQL Ecosystem |
| 2025-04-19 | Workshop | PostgreSQL Database Technology Summit | Using Pigsty to Deploy PG Ecosystem Partners: Dify, Odoo, Supabase |
| 2025-04-11 | Live Host | OSCHINA Data Intelligence Talk | Is the Viral MCP Hype or Revolutionary? |
| 2025-01-15 | Live Stream | Open Source Veterans & Newcomers Episode 4 | PostgreSQL Extensions Devouring DB World? PG Package Manager pig & Self-hosted RDS |
| 2025-01-09 | Award | OSCHINA 2024 Outstanding Contribution Expert | Outstanding Contribution Expert Award |
| 2025-01-06 | Panel | China PostgreSQL Database Ecosystem Conference | PostgreSQL Extensions are Devouring the Database World |
| 2024-11-23 | Podcast | Tech Hotpot Podcast | From the Linux Foundation: Why the Recent Focus on ‘Chokepoints’? |
| 2024-08-21 | Interview | Blue Tech Wave | Interview with Feng Ruohang: Simplifying PG Management |
| 2024-08-15 | Tech Summit | GOTC Global Open Source Technology Summit | PostgreSQL AI/ML/RAG Extension Ecosystem and Best Practices |
| 2024-07-12 | Keynote | 13th PG China Technical Conference | The Future of Database World: Extensions, Service, and Postgres |
| 2024-05-31 | Unconference | PGCon.Dev 2024 Global PG Developer Conference | Built-in Prometheus Metrics Exporter |
| 2024-05-28 | Seminar | PGCon.Dev 2024 Extension Summit | Extension in Core & Binary Packing |
| 2024-05-10 | Live Debate | Three-way Talk: Cloud Mudslide Series Episode 3 | Is Public Cloud a Scam? |
| 2024-04-17 | Live Debate | Three-way Talk: Cloud Mudslide Series Episode 2 | Are Cloud Databases a Tax on Intelligence? |
| 2024-04-16 | Panel | Cloudflare Immerse Shenzhen | Cyber Bodhisattva Panel Discussion |
| 2024-04-12 | Tech Summit | 2024 Data Technology Carnival | Pigsty: Solving PostgreSQL Operations Challenges |
| 2024-03-31 | Live Debate | Three-way Talk: Cloud Mudslide Series Episode 1 | Luo Selling Cloud While We’re Moving Off Cloud? |
| 2024-01-24 | Live Host | OSCHINA Open Source Talk Episode 9 | Will DBAs Be Eliminated by Cloud? |
| 2023-12-20 | Live Debate | Open Source Talk Episode 7 | To Cloud or Not: Cost Cutting or Value Creation? |
| 2023-11-24 | Tech Summit | Vector Databases in the LLM Era | Panel: New Future of Vector Databases in the AI Age |
| 2023-09-08 | Interview | Motianlun Feature Interview | Feng Ruohang: A Tech Enthusiast Who Makes Great Open Source Founders |
| 2023-08-16 | Tech Summit | DTCC 2023 | DBA Night: PostgreSQL vs MySQL Open Source License Issues |
| 2023-08-09 | Live Debate | Open Source Talk Episode 1 | MySQL vs PostgreSQL: Which is World’s No.1? |
| 2023-07-01 | Tech Summit | SACC 2023 | Workshop 8: FinOps Practice: Cloud Cost Management & Optimization |
| 2023-05-12 | Meetup | PostgreSQL China Wenzhou Meetup | PG With DB4AI: Vector Database PGVECTOR & AI4DB: Self-Driving Database Pigsty |
| 2023-04-08 | Tech Summit | Database Carnival 2023 | A Better Open Source RDS Alternative: Pigsty |
| 2023-04-01 | Tech Summit | PostgreSQL China Xi’an Meetup | PG High Availability & Disaster Recovery Best Practices |
| 2023-03-23 | Live Stream | Bytebase x Pigsty | Best Practices for Managing PostgreSQL: Bytebase x Pigsty |
| 2023-03-04 | Tech Summit | PostgreSQL China Conference | Challenging RDS, Pigsty v2.0 Release |
| 2023-02-01 | Tech Summit | DTCC 2022 | Open Source RDS Alternative: Battery-Included, Self-Driving Database Distro Pigsty |
| 2022-07-21 | Live Debate | Cloud Swallows Open Source | Can Open Source Strike Back Against Cloud? |
| 2022-07-04 | Interview | Creator’s Story | Post-90s Developer Quits to Start Up, Aiming to Challenge Cloud Databases |
| 2022-06-28 | Live Stream | Bass’s Roundtable | DBA’s Gospel: SQL Audit Best Practices |
| 2022-06-12 | Demo Day | MiraclePlus S22 Demo Day | User-Friendly Cost-Effective Database Distribution Pigsty |
| 2022-06-05 | Live Stream | PG Chinese Community Sharing | Pigsty v1.5 Quick Start, New Features & Production Cluster Setup |
Pigsty uses semantic versioning: <major>.<minor>.<patch>. Alpha/Beta/RC versions will have suffixes like -a1, -b1, -c1 appended to the version number.
Major version updates signify incompatible foundational changes and major new features; minor version updates typically indicate regular feature updates and small API changes; patch version updates mean bug fixes and package version updates.
Pigsty plans to release one major version update per year. Minor version updates usually follow PostgreSQL’s minor version update rhythm, catching up within a month at the latest after a new PostgreSQL version is released. Pigsty typically plans 4-6 minor versions per year. For complete release history, please refer to Release Notes.
Pigsty develops using the main trunk branch. Please always use Releases with version numbers.
Unless you know what you’re doing, do not use GitHub’s main branch. Always check out and use a specific version.
Here are our Active Issues and Roadmap.
For the extension support roadmap, you can find it here: https://pigsty.io/ext/e/roadmap
Our GitHub repository is: https://github.com/pgsty/pigsty. Please give us a ⭐️ star!
We welcome anyone to submit new Issues or create Pull Requests, propose feature suggestions, and contribute to Pigsty.
Please note that for issues related to Pigsty documentation, please submit Issues in the github.com/pgsty/pigsty.cc repository.
Press ⌘ with K on macOS, or Ctrl with K, to search the documentation, extension catalog, and blog directly.
Pigsty is built by its maintainers and community.
Chinese users are mainly active in WeChat groups. Currently, there are seven active groups. Groups 1-4 are full; for other groups, you need to add the assistant’s WeChat to be invited.
To join the WeChat community, search for “Pigsty小助手” (WeChat ID: pigsty-cc), note or send “加群” (join group), and the assistant will invite you to the group.

Telegram: https://t.me/joinchat/gV9zfZraNPM3YjFh
Discord: https://discord.gg/j5pG8qfKxU
You can also contact me via email: [email protected]
When you encounter problems using Pigsty, you can seek help from the community. The more information you provide, the more likely you are to get help from the community.
Please refer to the Community Help Guide and provide as much information as possible so that community members can help you solve the problem. Here is a reference template for asking for help:
What happened? (Required)
Pigsty version and OS version (Required)
Some cloud providers have customized standard OS distributions. You can tell us which cloud provider’s OS image you are using. If you have customized and modified the environment after installing the OS, or if there are specific security rules and firewall configurations in your LAN, please also inform us when asking questions.
Pigsty configuration file
Please don’t forget to redact any sensitive information: passwords, internal keys, sensitive configurations, etc.
What did you expect to happen?
Please describe what should happen under normal circumstances, and how the actual situation differs from expectations.
How to reproduce this issue?
Please tell us in as much detail as possible how to reproduce this issue.
Monitoring screenshots
If you are using the monitoring system provided by Pigsty, you can provide relevant screenshots.
Error logs
Please provide logs related to the error as much as possible. Please do not paste content like “Failed to start xxx service” that has no informational value.
You can query logs from Grafana / VictoriaLogs, or get logs from the following locations:
/var/log/messages (rhel) or /var/log/syslog (debian)/pg/log/postgres/*/pg/log/patroni/*/pg/log/pgbouncer/*/pg/log/pgbackrest/*Have you searched Issues/Website/FAQ?
In the FAQ, we provide answers to many common questions. Please check before asking.
You can also search for related issues from GitHub Issues and Discussions:
Is there any other information we need to know?
The more information and context you provide, the more likely we can help you solve the problem.
When you install Pigsty software, if you use offline package installation in a network-isolated environment, we will not receive any data about you.
If you choose online installation, when downloading related packages, our servers or cloud provider servers will automatically log the visiting machine’s IP address and/or hostname in the logs, along with the package names you downloaded.
We will not share this information with other organizations unless required by law. (Honestly, we’d have to be really bored to look at this stuff.)
Pigsty’s primary domain is: pigsty.io. For mainland China, please use the registered mirror site pigsty.cc.
When you visit our website, our servers will automatically log your IP address and/or hostname in Nginx logs.
We will only store information such as your email address, name, and location when you decide to send us such information by completing a survey or registering as a user on one of our websites.
We collect this information to help us improve website content, customize web page layouts, and contact people for technical and support purposes. We will not share your email address with other organizations unless required by law.
This website uses Google Analytics, a web analytics service provided by Google, Inc. (“Google”). Google Analytics uses “cookies,” which are text files placed on your computer to help the website analyze how users use the site.
The information generated by the cookie about your use of the website (including your IP address) will be transmitted to and stored by Google on servers in the United States. Google will use this information to evaluate your use of the website, compile reports on website activity for website operators, and provide other services related to website activity and internet usage. Google may also transfer this information to third parties if required by law or where such third parties process the information on Google’s behalf. Google will not associate your IP address with any other data held by Google. You may refuse the use of cookies by selecting the appropriate settings on your browser, however, please note that if you do this, you may not be able to use the full functionality of this website. By using this website, you consent to the processing of data about you by Google in the manner and for the purposes set out above.
If you have any questions or comments about this policy, or request deletion of personal data, you can contact us by sending an email to [email protected]
Pigsty core uses Apache-2.0; documentation uses CC BY 4.0.
Official License: https://github.com/pgsty/pigsty/blob/main/LICENSE
The Pigsty core is licensed under Apache License 2.0.
Apache-2.0 is a permissive open-source license. You may freely use, modify, and distribute the software for commercial purposes without opening your own source code or adopting the same license.
| What This License Grants | What This License Does NOT Grant | License Conditions |
|---|---|---|
| Commercial use | Trademark use | Include license and copyright notice |
| Modification | Liability & warranty | State changes |
| Distribution | ||
| Patent grant | ||
| Private use |
Pigsty documentation sites (pigsty.cc, pigsty.io, pgsty.com) use Creative Commons Attribution 4.0 International (CC BY 4.0).
CC BY 4.0 permits free sharing and adaptation with appropriate credit, a license link, and indication of changes.
| What This License Grants | What This License Does NOT Grant | License Conditions |
|---|---|---|
| Commercial use | Trademark use | Attribution |
| Modification | Liability & warranty | Indicate changes |
| Distribution | Patent grant | Provide license link |
| Private use |
Open-source software used or related to the Pigsty project.
For 575 PostgreSQL extension plugin licenses, refer to PostgreSQL Extension License List.
| Module | Software Name | License | Purpose & Description | Necessity |
|---|---|---|---|---|
| PGSQL | PostgreSQL | PostgreSQL License | PostgreSQL kernel | Required |
| PGSQL | patroni | MIT License | PostgreSQL high availability | Required |
| ETCD | etcd | Apache License 2.0 | HA consensus and distributed config storage | Required |
| INFRA | Ansible | GPLv3 | Executes playbooks and management commands | Required |
| INFRA | Nginx | BSD-2 | Exposes Web UI and serves local repo | Recommended |
| PGSQL | pgbackrest | MIT License | PITR backup/recovery management | Recommended |
| PGSQL | pgbouncer | ISC License | PostgreSQL connection pooling | Recommended |
| PGSQL | vip-manager | BSD 2-Clause License | Automatic L2 VIP binding to PG primary | Recommended |
| PGSQL | pg_exporter | Apache License 2.0 | PostgreSQL and PgBouncer monitoring | Recommended |
| NODE | node_exporter | Apache License 2.0 | Host node monitoring metrics | Recommended |
| NODE | haproxy | HAPROXY’s License (GPLv2) | Load balancing and service exposure | Recommended |
| INFRA | Grafana | AGPLv3 | Database visualization platform | Recommended |
| INFRA | VictoriaMetrics | Apache License 2.0 | TSDB, metric collection, alerting | Recommended |
| INFRA | VictoriaLogs | Apache License 2.0 | Centralized log collection, storage, query | Recommended |
| INFRA | DNSMASQ | GPLv2 / GPLv3 | DNS resolution and cluster name lookup | Recommended |
| MINIO | Silo | AGPLv3 | The only object-storage service supported by the current MINIO module | Optional |
| INFRA | Historical MinIO branch | AGPLv3 | Historical/repository package; not a v4.5 MINIO backend | Optional |
| INFRA | RustFS | Apache License 2.0 | Repository-retained package; not a v4.5 MINIO backend | Optional |
| NODE | keepalived | MIT License | VIP binding on node clusters | Optional |
| REDIS | Redis | BSD 3-Clause | Default cache engine, using the Redis 7.2 BSD branch | Optional |
| REDIS | Valkey | BSD 3-Clause | Cache engine selected with redis_type: valkey |
Optional |
| REDIS | Redis Exporter | MIT License | Redis monitoring | Optional |
| MONGO | FerretDB | Apache License 2.0 | MongoDB compatibility over PostgreSQL | Optional |
| DOCKER | docker-ce | Apache License 2.0 | Container management | Optional |
| CLOUD | SealOS | Apache License 2.0 | Fast K8S cluster deployment and packaging | Optional |
| DUCKDB | DuckDB | MIT | High-performance analytics | Optional |
| External | Vagrant | Business Source License 1.1 | Local test environment VMs | Optional |
| External | Terraform | Business Source License 1.1 | One-click cloud resource provisioning | Optional |
| External | Virtualbox | GPLv2 | Virtual machine management software | Optional |
Necessity Levels:
Pigsty is a free and open-source software, passionately developed by PostgreSQL community members, aiming to integrate the power of the PostgreSQL ecosystem and promote the widespread adoption of PostgreSQL. If our work has helped you, please consider sponsoring or supporting our project:
Pigsty is a project invested by Miracle Plus (formerly YC China) S22. We thank Miracle Plus and Dr. Qi Lu for their support of this project!
Special thanks to Vercel for sponsoring pigsty and hosting the Pigsty website.
Special thanks to JetBrains for sponsoring Pigsty with JetBrains Open Source License
According to Google Analytics PV and download statistics, Pigsty currently has approximately 100,000 users, with half from mainland China and half from other regions globally. They span across multiple industries including internet, cloud computing, finance, autonomous driving, manufacturing, tech innovation, ISV, and defense. If you are using Pigsty and are willing to share your case and Logo with us, please contact us - we offer one free consultation session as a token of appreciation.
Tantan: 200+ physical machines for PostgreSQL and Redis services
Bilibili: Supporting PostgreSQL innovative business
Bitdeer: Providing PG DBaaS
Oracle OCI: Using Pigsty to deliver PostgreSQL clusters
AirWallex: Monitoring 200+ GCP PostgreSQL databases
Media Storm: Self-hosted PG RDS / Victoria Metrics
Momenta: Autonomous driving, managing self-hosted PostgreSQL clusters
Huafon Group: Using Pigsty to deliver PostgreSQL clusters as chemical industry time-series data warehouse
Beijing Lingwu Technology: Migrating PostgreSQL from cloud to self-hosted
Motphys: Self-hosted PostgreSQL supporting GitLab
Sailong Biotech: Self-hosted Supabase
Hangzhou Lingma Technology: Self-hosted PostgreSQL
Inner Mongolia Haode Tianmu Technology Co., Ltd.
Shanghai Yuanfang
DSG
Pigsty aims to unite the power of the PostgreSQL ecosystem and help users make the most of the world’s most popular database, PostgreSQL, with self-driving database management software.
While Pigsty itself has already resolved many issues in PostgreSQL usage, achieving truly enterprise-grade service quality requires expert support and comprehensive coverage from the original provider. We deeply understand the importance of professional commercial support for enterprise customers. Therefore, Pigsty Enterprise Edition provides a series of value-added services on top of the open-source version, helping users better utilize PostgreSQL and Pigsty for customers to choose according to their needs.
If you have any of the following needs, please consider Pigsty subscription service:
In addition to the Open Source Edition, Pigsty offers two different subscription service tiers: Professional Edition and Enterprise Edition, which you can choose based on your actual situation and needs.
Note on
https://pigsty.io/price: Thehttps://pigsty.io/pricepage is a simplified global pricing landing page (USD pricing, includes theStandardtier and node-cap presets). This page is the detailed subscription reference (CNY pricing, delivery scope, and OS/PG compatibility matrix). For technical compatibility boundaries, this page and Supported Linux prevail.
No scale limit, no warranty
License: Apache-2.0
PG Support: 18 (default), 14–18 available
Architecture Support: x86_64, Arm64
OS Support: Latest minor versions of three families
Features: Core Modules
SLA: No SLA commitment
Community support Q&A:
Support: No person-day support option
Repository: Global Cloudflare hosted repository
Best for self-sufficient open source veterans.
Default choice for regular users
License: Commercial License
PG Support: 14–18
Architecture Support: x86_64, Arm64
OS Support: Mainstream OS major/minor versions
Features: All Modules (except domestic innovation kernels)
SLA: Response within business hours
Expert consulting services:
Support: 1 person-day included per year
Delivery: Standard offline software package
Repository: China mainland mirror sites
The default choice for regular users.
Critical scenarios with strict SLA
License: Commercial License
PG Support: 14–18+ (legacy versions on request)
Architecture Support: x86_64, Arm64
OS Support: Customized on demand
Features: All Modules
SLA: 7 x 24 (< 1h)
Enterprise-level expert consulting services:
Support: 2 person-days included per year
Repository: China mainland mirror sites
Delivery: Customized offline software package
Domestic Innovation: PolarDB-O support
For critical scenarios with a strict SLA.
Pigsty Open Source Edition uses the Apache-2.0 license, provides complete core functionality, requires no fees, but does not guarantee any warranty service. If you find defects in Pigsty, we welcome you to submit an Issue on Github.
Pigsty Open Source supports seven currently validated baselines: EL 9.8 / 10.2, Debian 12.15 / 13.6, and Ubuntu 22.04.5 / 24.04.4 / 26.04.0, across both x86_64 and aarch64.
The historical v4.4.0 Community Edition artifacts comprise six dual-architecture offline bundles built on EL 10.1, Debian 13.6, and Ubuntu 24.04.4. Those build baselines are not the same as the currently recommended operating systems; see the offline installation guide.
Using the Pigsty open source version allows junior development/operations engineers to have 70%+ of the capabilities of professional DBAs. Even without database experts, they can easily set up a highly available, high-performance, easy-to-maintain, secure and reliable PostgreSQL database cluster.
| Code | OS Distribution Version | x86_64 |
aarch64 |
PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|---|---|---|
| EL10 | RHEL 10 / Rocky10 / Alma10 | el10.x86_64 |
el10.aarch64 |
|||||
| EL9 | RHEL 9 / Rocky9 / Alma9 | el9.x86_64 |
el9.aarch64 |
|||||
| U26 | Ubuntu 26.04 (resolute) |
u26.x86_64 |
u26.aarch64 |
|||||
| U24 | Ubuntu 24.04 (noble) |
u24.x86_64 |
u24.aarch64 |
|||||
| U22 | Ubuntu 22.04 (jammy) |
u22.x86_64 |
u22.aarch64 |
|||||
| D13 | Debian 13 (trixie) |
d13.x86_64 |
d13.aarch64 |
|||||
| D12 | Debian 12 (bookworm) |
d12.x86_64 |
d12.aarch64 |
= Primary support, = Optional support
Pigsty Professional Edition subscription provides complete functional modules and warranty for Pigsty itself. For defects in PostgreSQL itself and extension plugins, we will make our best efforts to provide feedback and fixes through the PostgreSQL global developer community.
Pigsty Professional Edition is built on the open source version, fully compatible with all open source features, and provides additional modules plus broader database/OS compatibility options: we provide build options for all minor versions of eight mainstream Linux releases (EL8/9/10, Debian 12/13, Ubuntu 22/24/26).
Pigsty Professional Edition includes support for PostgreSQL 14 - 18, and tracks upstream PostgreSQL minor updates continuously (for active majors, typically day-zero or near-day availability), ensuring smooth rolling upgrades to newer majors and minors.
Pigsty Professional Edition subscription allows you to use China mainland mirror site software repositories, accessible without VPN/proxy; we will also customize offline software installation packages for your exact operating system major/minor version, ensuring normal installation and delivery in air-gapped environments, achieving autonomous and controllable deployment.
Pigsty Professional Edition subscription provides standard expert consulting services, including complex issue analysis, DBA Q&A support, backup compliance advice, etc. We commit to responding to your issues within business hours (5x8), and provide 1 person-day support per year, with optional person-day add-on options.
Pigsty Professional Edition uses a commercial license, providing additional modules, technical support, and warranty services.
Pigsty Professional Edition starting price is ¥150,000 / year, equivalent to the annual fee for 9 vCPU AWS high-availability RDS PostgreSQL, or a junior operations engineer with a monthly salary of 10,000 yuan.
| Code | OS Distribution Version | x86_64 |
aarch64 |
PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|---|---|---|
| EL10 | RHEL 10 / Rocky10 / Alma10 | el10.x86_64 |
el10.aarch64 |
|||||
| EL9 | RHEL 9 / Rocky9 / Alma9 | el9.x86_64 |
el9.aarch64 |
|||||
| EL8 | RHEL 8 / Rocky8 / Alma8 / Anolis8 | el8.x86_64 |
el8.aarch64 |
|||||
| U26 | Ubuntu 26.04 (resolute) |
u26.x86_64 |
u26.aarch64 |
|||||
| U24 | Ubuntu 24.04 (noble) |
u24.x86_64 |
u24.aarch64 |
|||||
| U22 | Ubuntu 22.04 (jammy) |
u22.x86_64 |
u22.aarch64 |
|||||
| D13 | Debian 13 (trixie) |
d13.x86_64 |
d13.aarch64 |
|||||
| D12 | Debian 12 (bookworm) |
d12.x86_64 |
d12.aarch64 |
Pigsty Enterprise Edition subscription includes all service content provided by the Pigsty Professional Edition subscription, plus the following value-added service items:
Pigsty Enterprise Edition subscription provides the broadest range of database/operating system version support, including extended support for EOL operating systems (EL7, D11), domestic operating systems, cloud vendor operating systems, and legacy PostgreSQL major versions (PG12+ on request), as well as full support for Arm64 architecture chips.
Pigsty Enterprise Edition subscription provides domestic innovation and localization solutions, allowing you to use PolarDB v2.0 (this kernel license needs to be purchased separately) kernel to replace the native PostgreSQL kernel and meet local compliance requirements.
Pigsty Enterprise Edition subscription provides higher-standard enterprise-level consulting services, committing to 7x24 with (< 1h) response time SLA, and can provide more types of consulting support: version upgrades, performance bottleneck identification, annual architecture review, extension plugin integration, etc.
Pigsty Enterprise Edition subscription includes 2 person-days of support per year, with optional person-day add-on options, for resolving more complex and time-consuming issues.
Pigsty Enterprise Edition allows you to use Pigsty for DBaaS purposes, building cloud database services for external sales.
Pigsty Enterprise Edition starting price is ¥400,000 / year, equivalent to the annual fee for 24 vCPU AWS high-availability RDS, or an operations expert with a monthly salary of 30,000 yuan.
| Code | OS Distribution Version | x86_64 |
aarch64 |
PG18 | PG17 | PG16 | PG15 | PG14 | PG13 | PG12 |
|---|---|---|---|---|---|---|---|---|---|---|
| EL10 | RHEL 10 / Rocky10 / Alma10 | el10.x86_64 |
el10.aarch64 |
|||||||
| EL9 | RHEL 9 / Rocky9 / Alma9 | el9.x86_64 |
el9.aarch64 |
|||||||
| EL8 | RHEL 8 / Rocky8 / Alma8 / Anolis8 | el8.x86_64 |
el8.aarch64 |
|||||||
| U26 | Ubuntu 26.04 (resolute) |
u26.x86_64 |
u26.aarch64 |
|||||||
| U24 | Ubuntu 24.04 (noble) |
u24.x86_64 |
u24.aarch64 |
|||||||
| U22 | Ubuntu 22.04 (jammy) |
u22.x86_64 |
u22.aarch64 |
|||||||
| D13 | Debian 13 (trixie) |
d13.x86_64 |
d13.aarch64 |
|||||||
| D12 | Debian 12 (bookworm) |
d12.x86_64 |
d12.aarch64 |
|||||||
| D11 | Debian 11 (bullseye) |
d11.x86_64 |
d11.aarch64 |
|||||||
| EL7 | RHEL7 / CentOS7 / UOS … | el7.x86_64 |
- |
Feature Differences
Pigsty Professional/Enterprise Edition includes the following additional features compared to the open source version:
pig)Payment Model
Pigsty subscription uses an annual payment model. After signing the contract, the one-year validity period is calculated from the contract date. If payment is made before the subscription contract expires, it is considered automatic renewal. Consecutive subscriptions have discounts. The first renewal (second year) enjoys a 95% discount, the second and subsequent renewals enjoy a 90% discount on subscription fees, and one-time subscriptions for three years or more enjoy an overall 85% discount.
After the annual subscription contract terminates, you can choose not to renew the subscription service. Pigsty will no longer provide software updates, technical support, and consulting services, but you can continue to use the already installed version of Pigsty Professional Edition software. If you subscribed to Pigsty professional services and choose not to renew, when re-subscribing you do not need to make up for the subscription fees during the interruption period, but all discounts and benefits will be reset.
Pigsty’s pricing strategy ensures value for money - you can immediately get top DBA’s database architecture construction solutions and management best practices, with their consulting support and comprehensive coverage; while the cost is highly competitive compared to hiring database experts full-time or using cloud databases. Here are market references for enterprise-level database professional service pricing:
The fair price for decent database professional services is 10,000 ~ 20,000 yuan / year, with the billing unit being vCPU, i.e., one CPU thread (1 Intel core = 2 vCPU threads). Pigsty provides top-tier PostgreSQL expert services in China and adopts a per-node billing model. On commonly seen high-core-count server nodes, it brings users an unparalleled cost reduction and efficiency improvement experience.
In addition to Pigsty subscription, Pigsty also provides on-demand Pigsty x PostgreSQL expert services - industry-leading database experts available for consultation.
Within three years, provides 10 complex case handling sessions related to PostgreSQL and Pigsty, and unlimited Q&A.
Industry-leading expert on-site support, available for architecture consultation, fault analysis, problem troubleshooting, database health checks, monitoring interpretation, migration assessment, teaching and training, cloud migration/de-cloud consultation, and other continuous time-consuming scenarios.
Consult on any questions you want to know about Pigsty, PostgreSQL, databases, cloud computing, AI…
Database veterans, cloud computing maverick sharing industry-leading insights, cognition, and judgment.
Get a quick diagnostic opinion and response to questions related to PostgreSQL / Pigsty / databases, not exceeding 5 minutes.
Please send an email to [email protected]. Users in mainland China are welcome to add WeChat ID RuohangFeng.
Pigsty is a PostgreSQL database distribution, a local-first open-source RDS cloud database solution. Pigsty is not a Database Management System (DBMS), but rather a tool, distribution, solution, and best practice for managing DBMS.
Analogy: The database is the car, then the DBA is the driver, RDS is the taxi service, and Pigsty is the autonomous driving software.
The ability to use databases well is extremely scarce: either hire database experts at high cost to self-build (hire drivers), or rent RDS from cloud vendors at sky-high prices (hail a taxi), but now you have a new option: Pigsty (autonomous driving). Pigsty helps users use databases well: allowing users to self-build higher-quality and more efficient local cloud database services at less than 1/10 the cost of RDS, without a DBA!
Pigsty has two typical target user groups. The foundation is medium to large companies building ultra-large-scale enterprise/production-grade PostgreSQL RDS / DBaaS services. Through extreme customizability, Pigsty can meet the most demanding database management needs and provide enterprise-level support and service guarantees.
At the same time, Pigsty also provides “out-of-the-box” PG RDS self-building solutions for individual developers, small and medium enterprises lacking DBA capabilities, and the open-source community.
Pigsty embodies the experience and best practices of top experts refined in the most complex and largest-scale client PostgreSQL scenarios, productized into replicable software: Solving extension installation, high availability, connection pooling, monitoring, backup and recovery, parameter optimization, IaC batch management, one-click installation, automated operations, and many other issues at once. Avoiding many pitfalls in advance and preventing repeated mistakes.
Pigsty provides a feature set and infrastructure support far beyond RDS, including 575 extension plugins and 12+ kernel support. Pigsty provides a unique professional-grade monitoring system in the PG ecosystem, along with architectural best practices battle-tested in complex scenarios, simple and easy to use.
Moreover, forged in top-tier client scenarios like Tantan, Apple, and Alibaba, continuously nurtured with passion and love, its depth and maturity are incomparable to RDS’s one-size-fits-all approach.
Pigsty allows you to use 10 ¥/core·month pure hardware resources to run 400¥-1400¥/core·month RDS cloud databases, and save the DBA’s salary. Typically, the total cost of ownership (TCO) of a large-scale Pigsty deployment can be over 90% lower than RDS.
Pigsty can simultaneously reduce software licensing/services/labor costs. Self-building requires no additional staff, allowing you to spend costs where it matters most.
Pigsty integrates the most comprehensive extensions in the PG ecosystem (575), providing an All-in-PG solution: a single component replacing specialized components like Redis, Kafka, MySQL, ES, vector databases, OLAP / big data analytics.
Greatly improving R&D efficiency and agility while reducing complexity costs, and developers can achieve self-service management and autonomous DevOps with Pigsty’s support, without needing a DBA.
Pigsty’s self-healing high-availability architecture ensures hardware failures don’t need immediate handling, letting ops and DBAs sleep well; monitoring aids problem analysis and performance optimization; IaC enables automated management of ultra-large-scale clusters.
Operations can moonlight as DBAs with Pigsty’s support, while DBAs can skip the system building phase, saving significant work hours and focusing on high-value work, or relaxing, learning PG.
Pigsty is primarily developed by Feng Ruohang alone, an open-source contributor, database expert, and evangelist who has focused on PostgreSQL for 10 years, formerly at Alibaba, Tantan, and Apple, a full-stack expert. Now the founder of a one-person company, providing professional consulting services.
He is also a tech KOL, the founder of the top WeChat database personal account “非法加冯” (Illegally Add Feng), with 60,000+ followers across all platforms.
Pigsty is the most influential Chinese open-source project in the global PostgreSQL ecosystem, with about 100,000 users, half from overseas. Pigsty is also one of the most active open-source projects in the PostgreSQL ecosystem, currently dominating in extension distribution and monitoring systems.
PGEXT.Cloud is a PostgreSQL extension repository maintained by Pigsty, with the world’s largest PostgreSQL extension distribution volume. It has become an upstream software supply chain for multiple international PostgreSQL vendors.
Pigsty is currently one of the major distributions in the PostgreSQL ecosystem and a challenger to cloud vendor RDS, now widely used in defense, government, healthcare, internet, finance, manufacturing, and other industries.
Pigsty originated from the need for ultra-large-scale PostgreSQL automated management but has been deeply optimized for ease of use. Individual developers and small-medium enterprises lacking professional DBA capabilities can also easily get started.
The largest deployment is 25K vCPU, 4.5 million QPS, 6+ years; the smallest deployment can run completely on a 1c1g VM for Demo / Devbox use.
Pigsty focuses on integrating the PostgreSQL ecosystem and providing PostgreSQL best practices, but also supports a series of open-source software that works well with PostgreSQL. For example:
Pigsty is 100% open-source software + free software. Under the premise of complying with the open-source license, you can use it freely and for various commercial purposes.
We value software freedom. Pigsty uses the Apache-2.0 license. Please see the license for details.
Pigsty software itself is open-source and free, and provides commercial subscriptions for all budgets, providing quality assurance for Pigsty & PostgreSQL. Subscriptions provide broader OS/PG/chip architecture support ranges, as well as expert consulting and support. Pigsty commercial subscriptions deliver industry-leading management/technical experience/solutions, helping you save valuable time, shouldering risks for you, and providing a safety net for difficult problems.
Pigsty software itself is not a database and is not subject to domestic innovation catalog restrictions, and already has multiple military use cases. However, the Pigsty open-source edition does not provide any form of domestic innovation support. Commercial subscription provides domestic innovation solutions in cooperation with Alibaba Cloud, supporting the use of PolarDB-O with domestic innovation qualifications (requires separate purchase) as the RDS kernel, capable of running on domestic innovation OS/chip environments.
Pigsty uses the Apache-2.0 license. You may use it for DBaaS purposes under the license terms. For explicit commercial authorization, consider the Pigsty Enterprise subscription.
When redistributing Pigsty, you must retain copyright notices, patent notices, trademark notices, and attribution notices from the original work, and attach prominent change descriptions in modified files while preserving the content of the LICENSE file. Under these premises, you can replace PIGSTY’s Logo and trademark, but you must not promote it as “your own original work.” We provide commercial licensing support for OEM and rebranding in the enterprise edition.
Pigsty is a project invested by Miracle Plus S22. The original entity Panji Cloud Data (Beijing) Technology Co., Ltd. has been liquidated and divested of the Pigsty business.
Pigsty is currently independently operated and maintained by author Feng Ruohang. The business entities are:
PIGSTY® and PGSTY® are registered trademarks of Haikou Longhua Yuehang Technology Center.
Pigsty is a local-first RDS alternative released under Apache-2.0, deployable on your own physical/virtual machines or cloud servers.
We’ve chosen Amazon AWS RDS for PostgreSQL (the global market leader) and Alibaba Cloud RDS for PostgreSQL (China’s market leader) as benchmarks for comparison.
Both Aliyun RDS and AWS RDS are closed-source cloud database services, available only through rental models on public clouds. The following cloud-vendor information is a February 2024 archive based on PostgreSQL 16 at that time. The Pigsty column in the Feature Comparison table is maintained against the current release, while the later Key Extensions version table remains a period snapshot.
| Feature | Pigsty | Aliyun RDS | AWS RDS |
|---|---|---|---|
| Major Version Support | 14 - 18 | 13 - 18 | 13 - 18 |
| Read Replicas | Supports unlimited read replicas | Standby instances not exposed to users | Standby instances not exposed to users |
| Read/Write Splitting | Port-based traffic separation | Separate paid component | Separate paid component |
| Fast/Slow Separation | Supports offline ETL instances | Not available | Not available |
| Cross-Region DR | Supports standby clusters | Multi-AZ deployment supported | Multi-AZ deployment supported |
| Delayed Replicas | Supports delayed instances | Not available | Not available |
| Load Balancing | HAProxy / LVS | Separate paid component | Separate paid component |
| Connection Pool | Pgbouncer | Separate paid component: RDS | Separate paid component: RDS Proxy |
| High Availability | Patroni / etcd | Requires HA edition | Requires HA edition |
| Point-in-Time Recovery | pgBackRest / Silo | Backup supported | Backup supported |
| Metrics Monitoring | VictoriaMetrics / Exporter | Free basic / Paid advanced | Free basic / Paid advanced |
| Log Collection | VictoriaLogs / Vector | Basic support | Basic support |
| Visualization | Grafana / Echarts | Basic monitoring | Basic monitoring |
| Alert Aggregation | AlertManager | Basic support | Basic support |
This is a historical PostgreSQL 16 extension-support snapshot based on information visible on 2024-02-28. Its versions and projects—including pg_analytics, which was later archived and removed from the catalog—are not the current Pigsty v4.5.0 or cloud-provider support matrix. Use the extension catalog for current Pigsty coverage and recheck each provider’s documentation for its current service capabilities.
| Extension | Pigsty RDS / PGDG Official Repo | Aliyun RDS | AWS RDS |
|---|---|---|---|
| Install Extensions | Free to install | Not allowed | Not allowed |
| Geospatial | PostGIS 3.4.2 | PostGIS 3.3.4 / Ganos 6.1 | PostGIS 3.4.1 |
| Point Cloud | PG PointCloud 1.2.5 | Ganos PointCloud 6.1 | |
| Vector Embedding | PGVector 0.6.1 / Svector 0.5.6 | pase 0.0.1 | PGVector 0.6 |
| Machine Learning | PostgresML 2.8.1 | ||
| Time Series | TimescaleDB 2.14.2 | ||
| Horizontal Scaling | Citus 12.1 | ||
| Columnar Storage | Hydra 1.1.1 | ||
| Full Text Search | pg_bm25 0.5.6 |
||
| Graph Database | Apache AGE 1.5.0 | ||
| GraphQL | PG GraphQL 1.5.0 | ||
| OLAP | pg_analytics 0.5.6 | ||
| Message Queue | pgq 3.5.0 | ||
| DuckDB | duckdb_fdw 1.1 | ||
| Fuzzy Tokenization | zhparser 1.1 / pg_bigm 1.2 | zhparser 1.0 / pg_jieba | pg_bigm 1.2 |
| CDC Extraction | wal2json 2.5.3 | wal2json 2.5 | |
| Bloat Management | pg_repack 1.5.0 | pg_repack 1.4.8 | pg_repack 1.5.0 |
AWS RDS for PostgreSQL 16 available extensions (excluding PG built-in extensions)
| name | pg16 | pg15 | pg14 | pg13 | pg12 | pg11 | pg10 |
|---|---|---|---|---|---|---|---|
| amcheck | 1.3 | 1.3 | 1.3 | 1.2 | 1.2 | yes | 1 |
| auto_explain | yes | yes | yes | yes | yes | yes | yes |
| autoinc | 1 | 1 | 1 | 1 | null | null | null |
| bloom | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| bool_plperl | 1 | 1 | 1 | 1 | null | null | null |
| btree_gin | 1.3 | 1.3 | 1.3 | 1.3 | 1.3 | 1.3 | 1.2 |
| btree_gist | 1.7 | 1.7 | 1.6 | 1.5 | 1.5 | 1.5 | 1.5 |
| citext | 1.6 | 1.6 | 1.6 | 1.6 | 1.6 | 1.5 | 1.4 |
| cube | 1.5 | 1.5 | 1.5 | 1.4 | 1.4 | 1.4 | 1.2 |
| dblink | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 |
| dict_int | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| dict_xsyn | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| earthdistance | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 |
| fuzzystrmatch | 1.2 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 |
| hstore | 1.8 | 1.8 | 1.8 | 1.7 | 1.6 | 1.5 | 1.4 |
| hstore_plperl | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| insert_username | 1 | 1 | 1 | 1 | null | null | null |
| intagg | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 |
| intarray | 1.5 | 1.5 | 1.5 | 1.3 | 1.2 | 1.2 | 1.2 |
| isn | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.1 |
| jsonb_plperl | 1 | 1 | 1 | 1 | 1 | null | null |
| lo | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 |
| ltree | 1.2 | 1.2 | 1.2 | 1.2 | 1.1 | 1.1 | 1.1 |
| moddatetime | 1 | 1 | 1 | 1 | null | null | null |
| old_snapshot | 1 | 1 | 1 | null | null | null | null |
| pageinspect | 1.12 | 1.11 | 1.9 | 1.8 | 1.7 | 1.7 | 1.6 |
| pg_buffercache | 1.4 | 1.3 | 1.3 | 1.3 | 1.3 | 1.3 | 1.3 |
| pg_freespacemap | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 |
| pg_prewarm | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.1 |
| pg_stat_statements | 1.1 | 1.1 | 1.9 | 1.8 | 1.7 | 1.6 | 1.6 |
| pg_trgm | 1.6 | 1.6 | 1.6 | 1.5 | 1.4 | 1.4 | 1.3 |
| pg_visibility | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 |
| pg_walinspect | 1.1 | 1 | null | null | null | null | null |
| pgcrypto | 1.3 | 1.3 | 1.3 | 1.3 | 1.3 | 1.3 | 1.3 |
| pgrowlocks | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 |
| pgstattuple | 1.5 | 1.5 | 1.5 | 1.5 | 1.5 | 1.5 | 1.5 |
| plperl | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| plpgsql | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| pltcl | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| postgres_fdw | 1.1 | 1.1 | 1.1 | 1 | 1 | 1 | 1 |
| refint | 1 | 1 | 1 | 1 | null | null | null |
| seg | 1.4 | 1.4 | 1.4 | 1.3 | 1.3 | 1.3 | 1.1 |
| sslinfo | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 |
| tablefunc | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| tcn | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| tsm_system_rows | 1 | 1 | 1 | 1 | 1 | 1 | 1.1 |
| tsm_system_time | 1 | 1 | 1 | 1 | 1 | 1 | 1.1 |
| unaccent | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 |
| uuid-ossp | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 |
Aliyun RDS for PostgreSQL 16 available extensions (excluding PG built-in extensions)
| name | pg16 | pg15 | pg14 | pg13 | pg12 | pg11 | pg10 | description |
|---|---|---|---|---|---|---|---|---|
| bloom | 1 | 1 | 1 | 1 | 1 | 1 | 1 | Provides a bloom filter-based index access method. |
| btree_gin | 1.3 | 1.3 | 1.3 | 1.3 | 1.3 | 1.3 | 1.2 | Provides GIN operator class examples that implement B-tree equivalent behavior for multiple data types and all enum types. |
| btree_gist | 1.7 | 1.7 | 1.6 | 1.5 | 1.5 | 1.5 | 1.5 | Provides GiST operator class examples that implement B-tree equivalent behavior for multiple data types and all enum types. |
| citext | 1.6 | 1.6 | 1.6 | 1.6 | 1.6 | 1.5 | 1.4 | Provides a case-insensitive string type. |
| cube | 1.5 | 1.5 | 1.5 | 1.4 | 1.4 | 1.4 | 1.2 | Provides a data type for representing multi-dimensional cubes. |
| dblink | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | Cross-database table operations. |
| dict_int | 1 | 1 | 1 | 1 | 1 | 1 | 1 | Additional full-text search dictionary template example. |
| earthdistance | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | Provides two different methods to calculate great circle distances on the Earth’s surface. |
| fuzzystrmatch | 1.2 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | Determines similarities and distances between strings. |
| hstore | 1.8 | 1.8 | 1.8 | 1.7 | 1.6 | 1.5 | 1.4 | Stores key-value pairs in a single PostgreSQL value. |
| intagg | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | Provides an integer aggregator and an enumerator. |
| intarray | 1.5 | 1.5 | 1.5 | 1.3 | 1.2 | 1.2 | 1.2 | Provides some useful functions and operators for manipulating null-free integer arrays. |
| isn | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.1 | Validates input according to a hard-coded prefix list, also used for concatenating numbers during output. |
| ltree | 1.2 | 1.2 | 1.2 | 1.2 | 1.1 | 1.1 | 1.1 | For representing labels of data stored in a hierarchical tree structure. |
| pg_buffercache | 1.4 | 1.3 | 1.3 | 1.3 | 1.3 | 1.3 | 1.3 | Provides a way to examine the shared buffer cache in real time. |
| pg_freespacemap | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | Examines the free space map (FSM). |
| pg_prewarm | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.1 | Provides a convenient way to load data into the OS buffer or PostgreSQL buffer. |
| pg_stat_statements | 1.1 | 1.1 | 1.9 | 1.8 | 1.7 | 1.6 | 1.6 | Provides a means of tracking execution statistics of all SQL statements executed by a server. |
| pg_trgm | 1.6 | 1.6 | 1.6 | 1.5 | 1.4 | 1.4 | 1.3 | Provides functions and operators for alphanumeric text similarity, and index operator classes that support fast searching of similar strings. |
| pgcrypto | 1.3 | 1.3 | 1.3 | 1.3 | 1.3 | 1.3 | 1.3 | Provides cryptographic functions for PostgreSQL. |
| pgrowlocks | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | Provides a function to show row locking information for a specified table. |
| pgstattuple | 1.5 | 1.5 | 1.5 | 1.5 | 1.5 | 1.5 | 1.5 | Provides multiple functions to obtain tuple-level statistics. |
| plperl | 1 | 1 | 1 | 1 | 1 | 1 | 1 | Provides Perl procedural language. |
| plpgsql | 1 | 1 | 1 | 1 | 1 | 1 | 1 | Provides SQL procedural language. |
| pltcl | 1 | 1 | 1 | 1 | 1 | 1 | 1 | Provides Tcl procedural language. |
| postgres_fdw | 1.1 | 1.1 | 1.1 | 1 | 1 | 1 | 1 | Cross-database table operations. |
| sslinfo | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 | Provides information about the SSL certificate provided by the current client. |
| tablefunc | 1 | 1 | 1 | 1 | 1 | 1 | 1 | Contains multiple table-returning functions. |
| tsm_system_rows | 1 | 1 | 1 | 1 | 1 | 1 | 1 | Provides the table sampling method SYSTEM_ROWS. |
| tsm_system_time | 1 | 1 | 1 | 1 | 1 | 1 | 1 | Provides the table sampling method SYSTEM_TIME. |
| unaccent | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | A text search dictionary that can remove accents (diacritics) from lexemes. |
| uuid-ossp | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | Provides functions to generate universally unique identifiers (UUIDs) using several standard algorithms. |
| xml2 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 | Provides XPath queries and XSLT functionality. |
| Metric | Pigsty | Aliyun RDS | AWS RDS |
|---|---|---|---|
| Peak Performance | PGTPC on NVME SSD Benchmark sysbench oltp_rw | RDS PG Performance Whitepaper sysbench oltp scenario QPS 4000 ~ 8000 per core | |
| Storage Spec: Max Capacity | 32TB / NVME SSD | 32 TB / ESSD PL3 | 64 TB / io2 EBS Block Express |
| Storage Spec: Max IOPS | 4K Random Read: Max 3M, Random Write 2000~350K | 4K Random Read: Max 1M | 16K Random IOPS: 256K |
| Storage Spec: Max Latency | 4K Random Read: 75µs, Random Write: 15µs | 4K Random Read: 200µs | 500µs / Inferred as 16K random IO |
| Storage Spec: Max Reliability | UBER < 1e-18, equivalent to 18 nines MTBF: 2M hours 5DWPD, 3 years continuous | Reliability 9 nines, equivalent to UBER 1e-9 Storage and Data Reliability | Durability: 99.999%, 5 nines (0.001% annual failure rate) io2 specification |
| Storage Spec: Max Cost | ¥31.5/TB·month (5-year warranty amortized / 3.2T / Enterprise-grade / MLC) | ¥3200/TB·month (original ¥6400, monthly ¥4000) 50% off with 3-year prepaid | ¥1900/TB·month using max spec 65536GB / 256K IOPS best discount |
Pigsty provides nearly 3000 monitoring metrics and 50+ monitoring dashboards, covering database monitoring, host monitoring, connection pool monitoring, load balancer monitoring, and more, providing users with an unparalleled observability experience.

Pigsty provides 638 PostgreSQL-related monitoring metrics, while AWS RDS only has 99, and Aliyun RDS has only single-digit metrics:

Additionally, some projects provide PostgreSQL monitoring capabilities, but are relatively simple:
| Metric | Pigsty | Aliyun RDS | AWS RDS |
|---|---|---|---|
| System Usability | Simple | Simple | Simple |
| Configuration Management | Config files / CMDB based on Ansible Inventory | Can use Terraform | Can use Terraform |
| Change Method | Idempotent Playbooks based on Ansible Playbook | Console click operations | Console click operations |
| Parameter Tuning | Auto-adapts to node specs, Four preset templates: OLTP, OLAP, TINY, CRIT | ||
| Infra as Code | Natively supported | Can use Terraform | Can use Terraform |
| Customizable Parameters | Pigsty Parameters 283 parameters | ||
| Service & Support | Commercial subscription support available | After-sales ticket support | After-sales ticket support |
| Air-gapped Deployment | Offline installation supported | N/A | N/A |
| Database Migration | Playbooks for zero-downtime migration from existing v10+ PG instances to Pigsty managed instances via logical replication | Cloud migration assistance Aliyun RDS Data Sync |
Based on experience, RDS unit cost is 5-15 times that of self-hosted for software and hardware resources, with a rent-to-own ratio typically around one month. For details, see Cost Analysis.
| Factor | Metric | Pigsty | Aliyun RDS | AWS RDS |
|---|---|---|---|---|
| Cost | Software License/Service Fee | Free, hardware ~¥20-40/core·month | ¥200-400/core·month | ¥400-1300/core·month |
| Support Service Fee | Service ~¥100/core·month | Included in RDS cost |
Some software and vendors providing PostgreSQL management capabilities:
Pigsty refuses to use Kubernetes for managing databases in production, so there are ecological differences with these solutions.
For more information, see:
The cost data below is intended to illustrate order-of-magnitude differences. Cloud vendor pricing and discounts vary over time, region, instance size, and purchase model.
| EC2 | Core·Month | RDS | Core·Month |
|---|---|---|---|
| DHH Self-Hosted Core-Month Price (192C 384G) | 25.32 | Junior Open Source DB DBA Reference Salary | ¥15K/person·month |
| IDC Self-Hosted (Dedicated Physical: 64C384G) | 19.53 | Mid-Level Open Source DB DBA Reference Salary | ¥30K/person·month |
| IDC Self-Hosted (Container, 500% Oversold) | 7 | Senior Open Source DB DBA Reference Salary | ¥60K/person·month |
| UCloud Elastic VM (8C16G, Oversold) | 25 | ORACLE Database License | 10000 |
| Aliyun ECS 2x Memory (Dedicated, No Oversold) | 107 | Aliyun RDS PG 2x Memory (Dedicated) | 260 |
| Aliyun ECS 4x Memory (Dedicated, No Oversold) | 138 | Aliyun RDS PG 4x Memory (Dedicated) | 320 |
| Aliyun ECS 8x Memory (Dedicated, No Oversold) | 180 | Aliyun RDS PG 8x Memory (Dedicated) | 410 |
| AWS C5D.METAL 96C 200G (Monthly No Prepaid) | 100 | AWS RDS PostgreSQL db.T2 (2x) | 440 |
| AWS C5D.METAL 96C 200G (3-Year Prepaid) | 80 | AWS RDS PostgreSQL db.M5 (4x) | 611 |
| AWS C7A.METAL 192C 384G (3-Year Prepaid) | 104.8 | AWS RDS PostgreSQL db.R6G (8x) | 786 |
| Payment Model | Price | Annualized (¥10K) |
|---|---|---|
| IDC Self-Hosted (Single Physical Machine) | ¥75K / 5 years | 1.5 |
| IDC Self-Hosted (2-3 Machines for HA) | ¥150K / 5 years | 3.0 ~ 4.5 |
| Aliyun RDS On-Demand | ¥87.36/hour | 76.5 |
| Aliyun RDS Monthly (Baseline) | ¥42K / month | 50 |
| Aliyun RDS Annual (85% off) | ¥425,095 / year | 42.5 |
| Aliyun RDS 3-Year Prepaid (50% off) | ¥750,168 / 3 years | 25 |
| AWS On-Demand | $25,817 / month | 217 |
| AWS 1-Year No Prepaid | $22,827 / month | 191.7 |
| AWS 3-Year Full Prepaid | $120K + $17.5K/month | 175 |
| AWS China/Ningxia On-Demand | ¥197,489 / month | 237 |
| AWS China/Ningxia 1-Year No Prepaid | ¥143,176 / month | 171 |
| AWS China/Ningxia 3-Year Full Prepaid | ¥647K + ¥116K/month | 160.6 |
Here’s a comparison of self-hosted vs cloud database costs:
| Method | Annualized (¥10K) |
|---|---|
| IDC Hosted Server 64C / 384G / 3.2TB NVME SSD 660K IOPS (2-3 Machines) | 3.0 ~ 4.5 |
| Aliyun RDS PG HA Edition pg.x4m.8xlarge.2c, 64C / 256GB / 3.2TB ESSD PL3 | 25 ~ 50 |
| AWS RDS PG HA Edition db.m5.16xlarge, 64C / 256GB / 3.2TB io1 x 80k IOPS | 160 ~ 217 |
Using Aliyun as an example, the monthly pure compute price is 5-7x the self-hosted baseline, while 5-year prepaid is 2x self-hosted
| Payment Model | Unit Price (¥/Core·Month) | Relative to Standard | Self-Hosted Premium Multiple |
|---|---|---|---|
| On-Demand (1.5x) | ¥ 202 | 160 % | 9.2 ~ 11.2 |
| Monthly (Standard) | ¥ 126 | 100 % | 5.7 ~ 7.0 |
| 1-Year Prepaid (65% off) | ¥ 83.7 | 66 % | 3.8 ~ 4.7 |
| 2-Year Prepaid (55% off) | ¥ 70.6 | 56 % | 3.2 ~ 3.9 |
| 3-Year Prepaid (44% off) | ¥ 55.1 | 44 % | 2.5 ~ 3.1 |
| 4-Year Prepaid (35% off) | ¥ 45 | 35 % | 2.0 ~ 2.5 |
| 5-Year Prepaid (30% off) | ¥ 38.5 | 30 % | 1.8 ~ 2.1 |
| DHH @ 2023 | ¥ 22.0 | ||
| Tantan IDC Self-Hosted | ¥ 18.0 |
Including common NVMe SSD specs, the monthly pure compute price is 11-14x the self-hosted baseline, while 5-year prepaid is about 9x.
| Payment Model | Unit Price (¥/Core·Month) | + 40GB ESSD PL3 | Self-Hosted Premium Multiple |
|---|---|---|---|
| On-Demand (1.5x) | ¥ 202 | ¥ 362 | 14.3 ~ 18.6 |
| Monthly (Standard) | ¥ 126 | ¥ 286 | 11.3 ~ 14.7 |
| 1-Year Prepaid (65% off) | ¥ 83.7 | ¥ 244 | 9.6 ~ 12.5 |
| 2-Year Prepaid (55% off) | ¥ 70.6 | ¥ 230 | 9.1 ~ 11.8 |
| 3-Year Prepaid (44% off) | ¥ 55.1 | ¥ 215 | 8.5 ~ 11.0 |
| 4-Year Prepaid (35% off) | ¥ 45 | ¥ 205 | 8.1 ~ 10.5 |
| 5-Year Prepaid (30% off) | ¥ 38.5 | ¥ 199 | 7.9 ~ 10.2 |
| DHH @ 2023 | ¥ 25.3 | ||
| Tantan IDC Self-Hosted | ¥ 19.5 |
DHH Case: 192 cores with 12.8TB Gen4 SSD (1c:66); Tantan Case: 64 cores with 3.2T Gen3 MLC SSD (1c:50).
Cloud prices calculated at 40GB ESSD PL3 per core (1 core:4x RAM:40x disk).
| Evaluation Factor | Local PCI-E NVME SSD | Aliyun ESSD PL3 | AWS io2 Block Express |
|---|---|---|---|
| Capacity | 32TB | 32 TB | 64 TB |
| IOPS | 4K Random Read: 600K ~ 1.1M, 4K Random Write: 200K ~ 350K | 4K Random Read: Max 1M | 16K Random IOPS: 256K |
| Latency | 4K Random Read: 75µs, 4K Random Write: 15µs | 4K Random Read: 200µs | Random IO: ~500µs (contextually inferred as 16K) |
| Reliability | UBER < 1e-18, equivalent to 18 nines, MTBF: 2M hours, 5DWPD for 3 years | Data Reliability 9 nines Storage and Data Reliability | Durability: 99.999%, 5 nines (0.001% annual failure rate) io2 Specification |
| Cost | ¥16/TB·month (5-year amortized / 3.2T MLC), 5-year warranty, ¥3000 retail | ¥3200/TB·month (original ¥6400, monthly ¥4000), 50% off with 3-year full prepaid | ¥1900/TB·month using max spec 65536GB 256K IOPS best discount |
| SLA | 5-year warranty, replacement on failure | Aliyun RDS SLA Availability 99.99%: 15% monthly fee, 99%: 30% monthly fee, 95%: 100% monthly fee | Amazon RDS SLA Availability 99.95%: 15% monthly fee, 99%: 25% monthly fee, 95%: 100% monthly fee |
| Date | $/GB·Month | ¥/TB·5Years | HDD ¥/TB | SSD ¥/TB |
|---|---|---|---|---|
| 2006.03 | 0.150 | 63000 | 2800 | |
| 2010.11 | 0.140 | 58800 | 1680 | |
| 2012.12 | 0.095 | 39900 | 420 | 15400 |
| 2014.04 | 0.030 | 12600 | 371 | 9051 |
| 2016.12 | 0.023 | 9660 | 245 | 3766 |
| 2023.12 | 0.023 | 9660 | 105 | 280 |
| Other References | High-Perf Storage | Top-Tier Discounted | vs Purchased NVMe SSD | Price Ref |
| S3 Express | 0.160 | 67200 | DHH 12T | 1400 |
| EBS io2 | 0.125 + IOPS | 114000 | Shannon 3.2T | 900 |
There was a time when “moving to the cloud” was almost politically correct in tech circles, and an entire generation of app developers had their vision obscured by the cloud. Let’s use real data analysis and firsthand experience to explain the value and pitfalls of the public cloud rental model — for your reference in this era of cost reduction and efficiency improvement — please see “Cloud Computing Mudslide: Collection”
Cloud Infrastructure Basics
Exposing Object Storage: From Cost Reduction to Price Gouging
Garbage Tencent Cloud CDN: From Getting Started to Giving Up
Cloud Business Model
Cloud Exit Odyssey
Cloud Failure Post-Mortems
RDS Failures
Cloud Vendor Profiles
Sorted by GitHub stars in descending order. Last updated: 2026-08-13 (Beijing time).
| Project | Star | Author | Type | Summary |
|---|---|---|---|---|
pgsty/pigsty |
5521 | Ruohang Feng @ PGSTY | Distribution | Out-of-the-box PostgreSQL distribution |
polardb/PolarDB-for-PostgreSQL |
3191 | Alibaba Cloud | Kernel | Open-source PolarDB for PostgreSQL kernel |
tensorchord/pgvecto.rs |
2181 | TensorChord | Extension | Vector search extension written in Rust |
tensorchord/VectorChord |
1770 | TensorChord | Extension | Next-generation vector search extension |
Tencent/TBase |
1439 | Tencent Cloud | Kernel | Tencent distributed HTAP database kernel |
apache/cloudberry |
1315 | HashData | Kernel | Open-source MPP data warehouse kernel |
IvorySQL/IvorySQL |
1051 | HighGo | Kernel | Oracle-compatible PostgreSQL fork |
pgplex/pgschema |
995 | Chen Tianzhou | Tool | Declarative Postgres schema migration CLI |
amutu/zhparser |
869 | Jov | Extension | Chinese full-text parser based on SCWS |
opengauss-mirror/openGauss-server |
784 | Huawei | Kernel | Early PostgreSQL 9.2 kernel fork |
HaloTech-Co-Ltd/openHalo |
437 | HaloTech | Kernel | PostgreSQL kernel compatible with MySQL wire protocol |
jaiminpan/pg_jieba |
417 | Pan Jiamin | Extension | Chinese full-text search extension based on Jieba |
alitrack/duckdb_fdw |
409 | Li Hongyan | Extension | DuckDB foreign data wrapper |
tensorchord/VectorChord-bm25 |
375 | TensorChord | Extension | Native BM25 ranking index for PostgreSQL |
pgsty/pg_exporter |
359 | Ruohang Feng @ PGSTY | Tool | Metrics exporter for PostgreSQL and Pgbouncer |
ChenHuajun/pg_roaringbitmap |
286 | Chen Huajun @ Suning | Extension | PostgreSQL RoaringBitmap bitmap extension |
pgsty/pig |
199 | Ruohang Feng @ PGSTY | Tool | PostgreSQL extension package manager |
tensorchord/pg_bestmatch.rs |
101 | TensorChord | Extension | BM25 sparse-vector generation in PostgreSQL |
wublabdubdub/PDU-PostgreSQLDataUnloader |
101 | Zhang Chen | Tool | PostgreSQL database rescue and unloading tool |
tensorchord/pg_tokenizer.rs |
45 | TensorChord | Extension | Full-text search tokenizer extension |
jaiminpan/pg_scws |
41 | Pan Jiamin | Extension | Chinese tokenizer extension based on SCWS |
pgsty/pgext |
31 | Ruohang Feng @ PGSTY | Tool | PostgreSQL extension catalog and metadata tool |
tooltip:
trigger: axis
axisPointer: { type: shadow }
formatter: $fn:tipfmt
grid: { left: 320, right: 72, top: 20, bottom: 26 }
xAxis:
type: value
max: 5600
name: GitHub Stars
nameLocation: middle
nameGap: 24
axisLabel: { formatter: $fn:fnum }
splitLine: { show: true, lineStyle: { type: dashed, opacity: 0.45 } }
yAxis:
type: category
inverse: true
axisLabel:
align: right
margin: 8
width: 300
overflow: truncate
fontSize: 11
fontFamily: monospace
data:
- 'pgsty/pigsty'
- 'polardb/PolarDB-for-PostgreSQL'
- 'tensorchord/pgvecto.rs'
- 'tensorchord/VectorChord'
- 'Tencent/TBase'
- 'apache/cloudberry'
- 'IvorySQL/IvorySQL'
- 'pgplex/pgschema'
- 'amutu/zhparser'
- 'opengauss-mirror/openGauss-server'
- 'HaloTech-Co-Ltd/openHalo'
- 'jaiminpan/pg_jieba'
- 'alitrack/duckdb_fdw'
- 'tensorchord/VectorChord-bm25'
- 'pgsty/pg_exporter'
- 'ChenHuajun/pg_roaringbitmap'
- 'pgsty/pig'
- 'tensorchord/pg_bestmatch.rs'
- 'wublabdubdub/PDU-PostgreSQLDataUnloader'
- 'tensorchord/pg_tokenizer.rs'
- 'jaiminpan/pg_scws'
- 'pgsty/pgext'
series:
- name: Star
type: bar
barWidth: 20
showBackground: true
backgroundStyle: { color: "rgba(148, 163, 184, 0.16)" }
itemStyle:
color: $fn:barclr
borderRadius: [0, 5, 5, 0]
label:
show: true
position: right
formatter: $fn:labfmt
color: '#334155'
fontWeight: 600
data: [5521, 3191, 2181, 1770, 1439, 1315, 1051, 995, 869, 784, 437, 417, 409, 375, 359, 286, 199, 101, 101, 45, 41, 31]Sorted by GitHub stars in descending order, with commercial products that do not publish stars listed last. Last updated: 2026-08-13 (Beijing time).
| Project | Star | Vendor | Type | License | Summary |
|---|---|---|---|---|---|
| CloudNativePG | 9133 | EDB | K8S Native | Apache-2.0 | Mainstream PG Operator without Patroni dependency |
| Pigsty | 5521 | PGSTY | Linux Native | Apache-2.0 | Ansible-driven integrated PostgreSQL distribution |
| Zalando Postgres Operator | 5222 | Zalando | K8S Native | MIT | Long-standing Patroni/Spilo architecture operator |
| PGO | 4436 | Crunchy Data | K8S Native | Apache-2.0 | Production-grade operator with backup and monitoring |
| Autobase | 4332 | vitabaks | Linux Native | MIT | Automated deployment for Patroni/etcd/Consul |
| KubeBlocks | 3102 | ApeCloud | K8S Native | AGPL-3.0 | Unified multi-database operator platform |
| StackGres | 1426 | OnGres | K8S Native | AGPL-3.0 | Integrated PG operator with CRD/CLI/Web UI |
| Kubegres | 1350 | Reactive Tech | K8S Native | Apache-2.0 | Minimal operator built on native streaming replication |
| Tembo Operator | 1263 | Tembo | K8S Native | Unspecified | Scenario-based stacks for PostgreSQL |
| pgEdge | 744 | pgEdge | Linux Native | PostgreSQL | Distributed PG distribution focused on Spock multi-master replication |
| KubeDB | 733 | AppsCode | K8S Native | ACL-1.0 | Multi-database operator with kubectl plugin |
| Percona Operator for PostgreSQL | 381 | Percona | K8S Native | Apache-2.0 | PostgreSQL operator in Percona ecosystem |
| EDB TPA | 86 | EDB | Linux Native | GPL-3.0 | EDB official Ansible delivery toolkit |
| Percona Distribution for PostgreSQL | - | Percona | Linux Native | Multi | Integrated PostgreSQL distribution bundle |
| ClusterControl | - | ServerNines | Linux Native | Commercial | Multi-database deploy, monitoring, backup, and failover platform |
| CYBERTEC PGEE | - | CYBERTEC | Linux Native | Commercial | Enterprise PostgreSQL distribution focused on security and performance |
| Crunchy Postgres for Ansible | - | Crunchy Data | Linux Native | Commercial | Crunchy bare-metal/VM automation solution |
| EDB Postgres Advanced Server (EPAS) | - | EDB | Linux Native | Commercial | EDB flagship distribution with Oracle-compatibility features |
pgsty/pigstyUse -c with configure to select a template. Its value is a path relative to conf/ without the .yml suffix. If omitted, Pigsty uses the default meta template.
| Category | Templates |
|---|---|
| Solo Templates | meta, rich, fat, slim, infra, vibe, docker |
| Kernel Templates | pgsql, pg19, mssql, polar, ivory, agens, pgedge, mysql (OpenHalo), mongo, pgtde, oriole |
| HA Templates | ha/simu, ha/octo, ha/citus, ha/full, ha/safe, ha/trio, ha/dual |
| App Templates | supabase, app/odoo, app/dify, app/insforge, app/hindsight, app/electric, app/maybe, app/teable, app/mattermost, app/registry, app/immich, app/jumpserver |
| Misc Templates | demo/bare, demo/el, demo/debian, demo/demo, demo/kernel, demo/redis, demo/minio, demo/kafka, demo/mysql (native MySQL pilot), demo/remote, demo/saas, demo/wool, build/oss, build/dev |
The meta configuration template is Pigsty’s default template, designed to fulfill Pigsty’s core functionality—deploying PostgreSQL—on a single node.
To maximize compatibility, meta installs only the minimum required software set to ensure it runs across all operating system distributions and architectures.
metael8, el9, el10, d12, d13, u22, u24, u26x86_64, aarch64meta, slim, fatUsage: This is the default config template, so there’s no need to specify -c meta explicitly during configure:
For example, if you want to install PostgreSQL 16 rather than the default 18, you can use the -v arg in configure:
Source: pigsty/conf/meta.yml
The meta template is Pigsty’s default getting-started configuration, designed for quick onboarding.
Use Cases:
Key Features:
repo_enabled: false)postgis and pgvector extensionsNotes:
rich templateThe rich configuration template is an enhanced version of meta, designed for users who need to experience complete functionality.
If you want to build a local software repository, use Silo for backup storage, run Docker applications, or need preconfigured business databases, use this template.
richmetael8, el9, el10, d12, d13, u22, u24, u26x86_64, aarch64meta, slim, fatThis template’s main enhancements over meta:
repo_enabled: true), downloads all PG extensionsUsage:
Source: pigsty/conf/rich.yml
The rich template is Pigsty’s complete functionality showcase configuration, suitable for users who want to deeply experience all features.
Use Cases:
Main Differences from meta:
repo_enabled: true)pgbackrest_method: minio)Notes:
The slim configuration template provides minimal installation capability, installing a PostgreSQL high-availability cluster directly from the internet without deploying Infra monitoring infrastructure.
When you only need an available database instance without the monitoring system, consider using the Slim Installation mode.
slimel8, el9, el10, d12, d13, u22, u24, u26x86_64, aarch64metaUsage:
Source: pigsty/conf/slim.yml
The slim template is Pigsty’s minimal installation configuration, designed for quick deployment of bare PostgreSQL clusters.
Use Cases:
Key Features:
slim.yml playbook instead of deploy.yml for installationDifferences from meta:
slim uses dedicated slim.yml playbook, skips Infra module installationNotes:
The fat configuration template is Pigsty’s Feature-All-Test template, installing all extension plugins on a single node and building a local software repository containing all extensions for PostgreSQL 14-18 (five major versions).
This is a full-featured configuration for testing and development, suitable for scenarios requiring complete software package cache or testing all extensions.
fatel8, el9, el10, d12, d13, u22, u24, u26x86_64, aarch64meta, slim, fatUsage:
To specify a particular PostgreSQL version:
Source: pigsty/conf/fat.yml
The fat template is Pigsty’s full-featured test configuration, designed for completeness testing and offline package building.
Key Features:
Repository Contents:
| Category | Description |
|---|---|
| PostgreSQL 14-18 | Five major versions’ kernels and all extensions |
| Extension Categories | time, gis, rag, fts, olap, feat, lang, type, util, func, admin, stat, sec, fdw, sim, etl |
| Enterprise Components | kafka-stack, Java Runtime, Sealos, TigerBeetle |
| Database Kernels | PolarDB, IvorySQL |
Differences from rich:
fat contains all five versions of PostgreSQL 14-18, rich only contains current default versionfat contains additional enterprise components (Kafka, PolarDB, IvorySQL, etc.)fat requires larger disk space and longer build timeUse Cases:
Notes:
The infra configuration template only deploys Pigsty’s observability infrastructure components (VictoriaMetrics/Grafana/VictoriaLogs/Nginx, etc.), without PostgreSQL and etcd.
Suitable for scenarios requiring a standalone monitoring stack, such as monitoring external PostgreSQL/RDS instances or other data sources.
infrael8, el9, el10, d12, d13, u22, u24, u26x86_64, aarch64metaUsage:
Source: pigsty/conf/infra.yml
The infra template is Pigsty’s pure monitoring stack configuration, designed for standalone deployment of observability infrastructure.
Use Cases:
Included Components:
Not Included:
Monitoring External Instances:
After configuration, add monitoring for external PostgreSQL instances via the pgsql-monitor.yml playbook:
Notes:
The vibe config template provides a ready-to-use AI coding sandbox, integrating Code-Server (Web VS Code), JupyterLab, Claude Code observability, Codex CLI, JuiceFS distributed filesystem, and a feature-rich PostgreSQL database.
vibeel8, el9, el10, d12, d13, u22, u24, u26x86_64, aarch64metaUsage:
Source: pigsty/conf/vibe.yml
The vibe template is an AI-era Web coding sandbox, enabling development, data analysis, AI app building all in browser.
Core Components:
| Component | Description | Access Method |
|---|---|---|
| Code-Server | Web version of VS Code, full-featured code editor | http://<ip>/code |
| JupyterLab | Interactive data science notebook, Python/SQL | http://<ip>/jupyter |
| Claude Code | AI coding runtime and observability entrypoint (claude_env customizable) |
Terminal / Dashboard |
| Codex CLI | OpenAI agentic coding CLI; VIBE installs it but does not manage its configuration | Terminal |
| JuiceFS | PostgreSQL-based distributed filesystem | Mount point /fs |
| PostgreSQL 18 | Feature-rich database with pg18-main + categorized extension package groups |
Port 5432 |
Node tools explicitly installed by this template (node_packages):
openssh-server, juicefs, restic, rcloneuv, opencode, golangasciinema, tmuxPostgreSQL Extensions:
This template installs PostgreSQL 18 extension groups by category:
By default, the meta database enables postgis, timescaledb, and vector; other extensions can be enabled as needed.
The VIBE module provides AI coding sandbox capability; vibe.yml explicitly enables Code-Server and Jupyter and installs Claude Code and Codex CLI by default.
Code-Server: VS Code in browser
code_enabled, code_passwordcode_port, code_data, code_galleryJupyterLab: Interactive computing environment
jupyter_enabled, jupyter_passwordjupyter_port, jupyter_data, jupyter_venvClaude Code: AI coding assistant runtime
claude_envclaude-code dashboard for usage monitoringCodex CLI: AI coding assistant
codex_enabled, which defaults to true@openai/codex only; it does not write Codex configuration or connect Codex to the Claude Code dashboardThis template uses JuiceFS for distributed filesystem capability, with a special feature: both metadata and data stored in PostgreSQL.
Architecture Features:
/fs (controlled by juice_instances.jfs.path)9567 provides Prometheus metricsUse Cases:
Config Example:
After deployment, access via browser:
code_password and jupyter_password defaults are for testing only0.0.0.0:8888, allows any Origin, disables XSRF checks, and relies on the token by default; restrict the port and portal sources and never expose it directly to the Internet5432 (node_firewall_public_port) and includes addr: world HBA by default; remove those public paths for production and add portal Basic Auth when appropriateclaude_envThe docker configuration template runs Pigsty inside a Docker container and provides a minimal single-node stack for infrastructure and PostgreSQL.
For full workflow details, see Docker Deployment.
docker127.0.0.1 and trimmed system capabilities for Docker scenariosx86_64, aarch64meta, vibeUsage:
Source: pigsty/conf/docker.yml
The docker template is optimized for development and validation inside containers.
Key Features:
repo_enabled: false) to avoid extra build overhead in containers/etc/hosts rewritepg18-*)intra and world ranges in pg_hba_rules for fast testingNotes:
pg_hba_rules and password policy for production/data in the container runtime to persist PostgreSQL and component dataThe pgsql configuration template uses the native PostgreSQL kernel, Pigsty’s default database kernel, with stable support for PostgreSQL 14 to 18. The current configure also accepts version 19, but PG19 remains Beta; use the dedicated pg19 template for evaluation.
pgsqlel8, el9, el10, d12, d13, u22, u24, u26x86_64, aarch64metaUsage:
To specify a non-default PostgreSQL version (e.g., 16):
Source: pigsty/conf/pgsql.yml
The pgsql template is Pigsty’s standard kernel configuration, using community-native PostgreSQL.
Version Support:
./configure -c pg19)Use Cases:
meta template, explicitly declaring native kernel usageDifferences from meta:
pgsql template explicitly declares using native PostgreSQL kernelpg19 is the single-node PostgreSQL 19 Beta evaluation template. It follows the meta topology, enables the beta repository, and limits the local repository’s additional cache to core PGSQL packages without preinstalling extensions.
pg1919 Betameta, pgsqlUsage:
Source: pigsty/conf/pg19.yml
Important defaults and limitations:
node_repo_modules: node,infra,pgsql,beta obtains PG19 packages from the PGDG Beta repositoryrepo_extra_packages: [pgsql-core] limits the local repository’s additional cache to core PGSQL packages; instances still use the role’s default pgsql-main pgsql-common installation setpg_extensions: [] installs no extension packagespgbackrest_enabled: true and pgbackrest_exporter_enabled: true; pg-meta retains its daily 01:00 full-backup jobThis is a Beta evaluation configuration, not a production template. Do not treat -v 19 on an ordinary template as a production-ready PG19 deployment; validate extension compatibility, backup and recovery, and upgrade procedures separately.
The mssql configuration template uses a PostgreSQL 17-compatible Babelfish kernel instead of native PostgreSQL, providing Microsoft SQL Server wire protocol (TDS) and T-SQL syntax compatibility. The current template is pinned to pg_version: 17; configure does not apply -v overrides to this fixed-kernel template.
Since Pigsty v4.2, Babelfish is built directly by Pigsty, no longer using the WiltonDB repository, and is available on all supported Linux platforms.
For the complete tutorial, see: Babelfish (MSSQL) Kernel Guide
mssqlel8, el9, el10, d12, d13, u22, u24, u26x86_64, aarch64metaUsage:
Source: pigsty/conf/mssql.yml
The mssql template allows you to use SQL Server Management Studio (SSMS) or other SQL Server client tools to connect to PostgreSQL (through Babelfish protocol compatibility).
Key Features:
multi-db and single-db migration modesbabelfish + pgsql-common + sqlcmduuid-ossp, babelfishpg_common, babelfishpg_tsql, babelfishpg_tds, and babelfishpg_money by defaultx86_64 / aarch64)Connection Methods:
Use Cases:
Notes:
mssql template is pinned to a PostgreSQL 17-compatible kernel; do not rely on -v to switch its major versionmulti-db (babelfishpg_tsql.migration_mode), configurable to single-db when neededmd5 authentication method (not scram-sha-256)The polar configuration template uses Alibaba Cloud’s PolarDB for PostgreSQL database kernel instead of native PostgreSQL, providing “cloud-native” Aurora-style storage-compute separation capability.
For the complete tutorial, see: PolarDB for PostgreSQL (POLAR) Kernel Guide. For kernel differences and version references, see the PGSQL kernel overview.
polarel8, el9, el10, d12, d13, u22, u24, u26x86_64, aarch64metaUsage:
Source: pigsty/conf/polar.yml
The polar template uses Alibaba Cloud’s open-source PolarDB for PostgreSQL kernel, providing cloud-native database capabilities.
Key Features:
/usr/polar-17pgaudit, pg_partman, pg_profile, pg_repack, pg_stat_kcache, pg_cron, and pg_hint_planUse Cases:
Notes:
x86_64 and aarch64The ivory configuration template uses Highgo’s IvorySQL database kernel instead of native PostgreSQL, providing Oracle syntax and PL/SQL compatibility.
For the complete tutorial, see: IvorySQL (Oracle Compatible) Kernel Guide
ivoryel8, el9, el10, d12, d13, u22, u24, u26x86_64, aarch64metaUsage:
Source: pigsty/conf/ivory.yml
The ivory template uses Highgo’s open-source IvorySQL kernel, providing Oracle database compatibility.
Key Features:
Use Cases:
Notes:
liboracle_parser requires loading into shared_preload_librariespgbackrest may have checksum issues in Oracle-compatible mode, PITR capability is limitedThe agens configuration template replaces native PostgreSQL with the AgensGraph kernel and enables property-graph modeling plus Cypher queries.
For the full guide, see: AgensGraph kernel guide
agensel8, el9, el10, d12, d13, u22, u24, u26x86_64, aarch64meta, pgsqlEnable with:
Source: pigsty/conf/agens.yml
The agens template enables pg_mode: agens in the pg-meta cluster and installs the agensgraph kernel package instead of standard PostgreSQL.
Key features:
Typical use cases:
Caveats:
pg_version: 17The pgedge configuration template replaces native PostgreSQL with the pgEdge kernel and provides distributed, multi-master capabilities for edge deployments.
For the full guide, see: pgEdge kernel guide. For kernel differences and version references, see the PGSQL kernel overview.
pgedged12, d13, u22, u24, u26 for PG18 packages. For EL/RPM platforms, check current PGSQL repository availability for pgedge_18.x86_64, aarch64meta, pgsqlEnable with:
Source: pigsty/conf/pgedge.yml
The pgedge template enables pg_mode: pgedge in pg-meta and pre-installs pgEdge core extensions for logical replication and edge distribution.
Key features:
pgedge kernel package (PG15/16/17/18 compatible, default PG18)spock, snowflake, and lolor in the pgedge-$v kernel package and creates them in the meta database by defaultspock and lolor for multi-master setup readinessTypical use cases:
Caveats:
pg_version: 18; keep consistent with target cluster versionsThe mysql configuration template uses OpenHalo database kernel instead of native PostgreSQL, providing MySQL wire protocol and SQL syntax compatibility.
mysqlx86_64, aarch64metaUsage:
Source: pigsty/conf/mysql.yml
The mysql template uses the OpenHalo kernel, allowing you to connect to PostgreSQL using MySQL client tools.
Key Features:
Connection Methods:
Use Cases:
Notes:
openhalo package alias covers Pigsty’s supported Linux platforms on both architectures; actual installation still depends on the target platform’s repository indexThe pgtde configuration template uses Percona PostgreSQL database kernel, providing Transparent Data Encryption (TDE) capability.
pgtdeel8, el9, el10, d12, d13, u22, u24, u26x86_64, aarch64metaUsage:
Source: pigsty/conf/pgtde.yml
The pgtde template selects pg_mode: pgtde and installs the pgtde package
alias. Pigsty links the private /usr/pgtde-$v prefix (currently
/usr/pgtde-18) to its stable /usr/pgsql entry point.
Key Features:
Use Cases:
Usage:
Notes:
x86_64 and aarch64 packages are available on the listed distributionsThe oriole configuration template uses OrioleDB storage engine instead of PostgreSQL’s default Heap storage, providing bloat-free, high-performance OLTP capability.
oriole16, 17, or 18el8, el9, el10, d12, d13, u22, u24, u26x86_64, aarch64metaUsage:
Source: pigsty/conf/oriole.yml
The oriole template uses OrioleDB storage engine, fundamentally solving PostgreSQL table bloat problems.
Key Features:
Use Cases:
Usage:
Notes:
-v 16, -v 17, or -v 18orioledb to shared_preload_librariesThe mongo configuration template is a PostgreSQL deployment mode, not an independent Pigsty module. It combines:
PGSQL moduledocumentdb extension and its required preload librariesAll data, high availability, backup, monitoring, and lifecycle management remain PostgreSQL responsibilities. FerretDB only provides the MongoDB wire-compatible endpoint.
The default template is a single-node deployment on 10.10.10.10. FerretDB listens on loopback by default.
Install mongosh separately if it is not already available, or use another MongoDB-compatible client.
The dedicated mongod PostgreSQL login is declared by the template. FerretDB authentication is enabled, but MongoDB authorization roles are not implemented; PostgreSQL remains the security boundary.
| Layer | Implementation | Responsibility |
|---|---|---|
| Data | PostgreSQL + DocumentDB | Durable storage, transactions, HA, PITR, ACL, monitoring |
| Protocol | FerretDB Docker APP | Stateless MongoDB wire compatibility |
| Access | 127.0.0.1:27017 by default |
Local MongoDB client endpoint |
The container connects to Pigsty’s local primary service on port 5436 through host.docker.internal. The default Mongo endpoint is not exposed to the network; change FERRETDB_BIND_ADDR only when remote access is required.
Source: pigsty/conf/mongo.yml
FerretDB settings are ordinary APP overrides under apps.ferretdb.conf:
Use the standard PostgreSQL parameters, playbooks, dashboards, and administration procedures for the backend cluster. There are no mongo_* inventory parameters or standalone mongo.yml playbook.
The template contains a commented pg-mongo example for three PostgreSQL/FerretDB nodes. Uncomment that block and the two additional etcd members when needed.
In HA mode, each FerretDB container binds {{ inventory_hostname }}:27018; HAProxy exposes all three backends through the floating endpoint 10.10.10.4:27017 (mongo.pigsty). PostgreSQL failover is still handled by Patroni, while FerretDB remains stateless.
The ha/simu configuration template is a 20-node production environment simulation, requiring a powerful host machine to run.
ha/simupigsty/vagrant/spec/simu.rbel8, el9, el10, d12, d13, u22, u24, u26x86_64, aarch64Usage:
Source: pigsty/conf/ha/simu.yml
The ha/simu template is a large-scale production environment simulation for testing and validating complex scenarios.
Architecture:
Use Cases:
Notes:
ha/octo uses the first eight nodes from vagrant/spec/deci.rb to build a compact high-availability simulation. It exercises co-located modules, VIPs, remote backup, and larger membership counts. Do not use it directly as a production blueprint without reviewing capacity, security, and failure domains.
ha/octo10.10.10.10 through 10.10.10.17minio_type, so both deployment and removal roles default to Silo; verify that value, the exact target, and data paths before removalpg-meta: 3-node PostgreSQL cluster with VIP 10.10.10.2/24pg-test: 5-node PostgreSQL cluster whose final instance has the offline role, with VIP 10.10.10.3/24sss.pigsty:9002 and also retains a local repositoryThis template depends on fixed eight-node addresses and VIPs. For any other environment, update the host addresses, VIPs, interfaces, DNS, repository node, and every public example credential together.
Source: pigsty/conf/ha/octo.yml
pg-meta and pg-test PostgreSQL clusters are co-located with those two sets respectively.sss.pigsty through Keepalived VIP 10.10.10.9 and HAProxy port 9002. Silo is the current default engine, while the module and variables retain minio_* compatibility names.pg-meta takes one full backup daily. pg-test takes a weekly full backup and incremental backups on the remaining days; both write to the encrypted S3 pgBackRest repository.repo_enabled: false do not build local repositories. Every node still installs packages from the first node’s local repository.For a conventional minimal HA deployment, prefer ha/trio. For a larger full-scenario simulation, see ha/simu.
The ha/full configuration template is Pigsty’s recommended sandbox demonstration environment, deploying two PostgreSQL clusters across four nodes for testing and demonstrating various Pigsty capabilities.
Most Pigsty tutorials and examples are based on this template’s sandbox environment.
ha/fullel8, el9, el10, d12, d13, u22, u24, u26x86_64, aarch64ha/trio, ha/safe, demo/demoUsage:
After configuration, modify the IP addresses of the other three nodes.
Source: pigsty/conf/ha/full.yml
The ha/full template is Pigsty’s complete feature demonstration configuration, showcasing the collaboration of various components.
Components Overview:
| Component | Node Distribution | Description |
|---|---|---|
| INFRA | Node 1 | Monitoring/Alerting/Nginx/DNS |
| ETCD | Node 1 | DCS Service |
| Silo | Node 1 | S3-compatible Storage |
| pg-meta | Node 1 | Single-node PostgreSQL |
| pg-test | Nodes 2-4 | Three-node HA PostgreSQL |
| redis-ms | Node 1 | Redis Primary-Replica Mode |
| redis-meta | Node 2 | Redis Sentinel Mode |
| redis-test | Nodes 3-4 | Redis Native Cluster Mode |
Use Cases:
Differences from ha/trio:
Notes:
ha/safe uses a three-node high-availability topology to demonstrate TLS, client certificates, password checks, backup encryption, the CRIT parameter template, and related security settings. It is a configuration example to customize, not a compliance-certified template.
ha/safeel8, el9, el10, d12, d13, u22, u24, u26x86_64; some security extensions do not have ARM64 packagesha/trio, ha/fullGenerate the configuration:
-g randomizes only credentials recognized by the configuration wizard. You must still replace Silo users, the pgBackRest cipher_pass, and other template example values.
| Setting | Template Behavior | Boundary and Follow-up |
|---|---|---|
| PostgreSQL HBA | Main TCP rules use ssl; public administrator access uses cert |
Local ident and selected localhost pwd rules remain |
| PgBouncer | pgbouncer_sslmode: require |
Clients must still verify the server certificate where required |
| Patroni | REST API uses HTTPS and a constrained listen address | Basic Auth remains; rotate the password |
| Password check | passwordcheck is preloaded through pg_libs |
Affects only newly set or changed passwords |
| Account lifetime | Built-in and example application users set expire_in: 7300 |
Twenty years is not a rotation policy; shorten it to organizational requirements |
| Listen addresses | PostgreSQL is limited to ${ip},${vip},${lo} |
Firewalls and HBA are still required |
| Backup | Uses Silo with AES-256-CBC | pgBR.${pg_cluster} is a predictable example and must be replaced |
| PostgreSQL parameters | pg-meta uses crit.yml |
Strict synchronous mode can block writes without a synchronous replica |
| Logging | CRIT logs connection and disconnection events | Fine-grained SQL auditing requires explicit pgaudit configuration |
| Security extensions | Installs passwordcheck, credcheck, pgaudit, and related packages |
Installation does not preload, create, or configure an extension |
| Delayed replica | Provides a commented one-hour delayed-cluster example | Not created by default; enable it explicitly |
minio_users, pgbackrest_repo, application users, and API passwords.sslmode=verify-full and a trusted CA.pgaudit, credcheck, and other extensions as required.See Security Model, Authentication, Encrypted Communication, and Data Security for the underlying mechanisms.
Source: pigsty/conf/ha/safe.yml
Three nodes is the minimum scale for majority-based high availability. The ha/trio template distributes INFRA, ETCD, PGSQL, and Silo across three servers. PostgreSQL, ETCD, and object storage continue serving when one server is unavailable.
ha/trioel8, el9, el10, d12, d13, u22, u24, u26x86_64, aarch64ha/dual, ha/full, ha/safeUsage:
After configuration, modify placeholder IPs 10.10.10.11 and 10.10.10.12 to actual node IP addresses.
Source: pigsty/conf/ha/trio.yml
The ha/trio template is Pigsty’s standard HA configuration, providing true automatic failover capability.
Architecture:
10.10.10.9 with HAProxy listening on 9002 on all three nodesHA Guarantees:
sss.pigsty resolves to the object-storage VIP; pgBackRest and mcli use https://sss.pigsty:9002Object Storage:
minio_data: /data/minio is a filesystem directory, not a raw device such as /dev/sdb./data/minio must reside on a separately mounted /data filesystem or be a mount point itself.findmnt -T /data/minio to inspect the actual mount. A result that still points to / means the path is only a directory on the root drive.The template’s S3 API endpoint is highly available. The Portal administration UI still connects to port 9001 on the first node and is outside this API HA path.
Use Cases:
Extension Suggestions:
The ha/dual template uses two-node deployment, implementing a “semi-HA” architecture with one primary and one standby. If you only have two servers, this is a pragmatic choice.
ha/dualel8, el9, el10, d12, d13, u22, u24, u26x86_64, aarch64ha/trio, slimUsage:
After configuration, modify placeholder IP 10.10.10.11 to actual standby node IP address.
Source: pigsty/conf/ha/dual.yml
The ha/dual template is Pigsty’s two-node limited HA configuration, designed for scenarios with only two servers.
Architecture:
Failure Scenario Analysis:
| Failed Node | Impact | Auto Recovery |
|---|---|---|
| Node B down | Primary switches to Node A | Auto |
| Node A etcd down | Primary continues running (no DCS) | Manual |
| Node A pgsql down | Primary continues running | Manual |
| Node A complete failure | Primary degrades to standalone | Manual |
Use Cases:
Notes:
The ha/citus template deploys a complete Citus distributed PostgreSQL cluster with 1 infra node, 1 coordinator group, and 5 worker groups (12 Citus nodes total), providing transparent horizontal scaling and data sharding.
ha/citusel8, el9, el10, d12, d13, u22, u24, u26x86_64meta, ha/trioUsage:
This is a 13-node template. Modify the node addresses after generation.
Source: pigsty/conf/ha/citus.yml
| Cluster | Nodes | IP Addresses | VIP | Role |
|---|---|---|---|---|
| pg-meta | 1 | 10.10.10.10 | - | Infra + CMDB |
| pg-citus1 | 2 | 10.10.10.21, 22 | 10.10.10.29 | Coordinator (group 0) |
| pg-citus2 | 2 | 10.10.10.31, 32 | 10.10.10.39 | Worker (group 1) |
| pg-citus3 | 2 | 10.10.10.41, 42 | 10.10.10.49 | Worker (group 2) |
| pg-citus4 | 2 | 10.10.10.51, 52 | 10.10.10.59 | Worker (group 3) |
| pg-citus5 | 2 | 10.10.10.61, 62 | 10.10.10.69 | Worker (group 4) |
| pg-citus6 | 2 | 10.10.10.71, 72 | 10.10.10.79 | Worker (group 5) |
Architecture:
vip-manager for transparent failoverThe ha/citus template deploys production-grade Citus cluster for large-scale horizontal scaling scenarios.
Key Features:
Pre-installed Extensions:
Security:
pg_dbsu_password enabled for Citus inter-node communicationsslmode=verify-fullVerify after deployment:
Create Distributed Table:
Create Reference Table (replicated to all nodes):
pg_vip_interface defaults to auto; specify an interface explicitly for unusual network environmentsdemo/bare is Pigsty’s smallest configuration example. It keeps only three core groups and three global parameters to show a working inventory skeleton.
Source: pigsty/conf/demo/bare.yml
This template relies on Pigsty defaults and defines no business users, databases, extensions, backup policy, or security hardening. Use it to learn configuration hierarchy or as a minimal customization base; explicitly add passwords, HBA rules, backup, and safeguards for a real environment.
The demo/el configuration template is optimized for Enterprise Linux family distributions (RHEL, Rocky Linux, Alma Linux, Oracle Linux).
demo/elel8, el9, el10x86_64, aarch64meta, demo/debianUsage:
Source: pigsty/conf/demo/el.yml
The demo/el template is optimized for Enterprise Linux family distributions.
Supported Distributions:
Key Features:
Use Cases:
The demo/debian configuration template is optimized for Debian and Ubuntu distributions.
demo/debiand12, d13, u22, u24, u26x86_64, aarch64meta, demo/elUsage:
Source: pigsty/conf/demo/debian.yml
The demo/debian template is optimized for Debian and Ubuntu distributions.
Supported Distributions:
Key Features:
Use Cases:
The demo/demo configuration template is used by Pigsty’s public demo site, demonstrating how to expose services publicly, configure SSL certificates, and install all available extensions.
If you want to set up your own public service on a cloud server, you can use this template as a reference.
demo/demoel8, el9, el10, d12, d13, u22, u24, u26x86_64meta, richUsage:
This template enhances the meta template with:
pigsty.cc)Source: pigsty/conf/demo/demo.yml
The demo/demo template is Pigsty’s public demo configuration, showcasing a complete production-grade deployment example.
Key Features:
Use Cases:
Notes:
The demo/kernel configuration template demonstrates the major PostgreSQL kernels and compatible branches supported by Pigsty in a single configuration. It is intended for feature validation and kernel difference testing, not production use.
demo/kernelpg-cituspgsql, mssql, mongoUsage:
This is a fixed-IP demo template. Adjust node addresses for your actual environment after generation.
Source: pigsty/conf/demo/kernel.yml
This template uses single-node clusters to show the minimum viable configuration for different kernels:
pg-citus: PostgreSQL 18 + Cituspg-ivory: IvorySQL, compatible with PostgreSQL 18pg-mssql: Babelfish, compatible with PostgreSQL 17pg-polar: PolarDB for PostgreSQL, compatible with PostgreSQL 17pg-tde: Percona PostgreSQL 18 + pg_tdepg-oriole: OrioleDB, supports PostgreSQL 16, 17, and 18; the current demo config defaults to PG18pg-mysql: OpenHalo, compatible with PostgreSQL 14pg-mongo: DocumentDB backend for PostgreSQL Mongo mode, default PostgreSQL 18pg-agens: AgensGraph, compatible with PostgreSQL 17pg-edge: pgEdge, compatible with PostgreSQL 18Notes:
demo/minio demonstrates a highly available S3 object-storage cluster with four nodes and four drives per node, for 16 drives total. The template retains MINIO module compatibility naming and explicitly sets minio_type: silo; the current v4.5.0 source accepts only this value, and both deployment and removal roles default to silo. Still verify it together with the exact target, cluster identity, and data paths before removal.
For more tutorials, see the MINIO module documentation.
demo/minioel8, el9, el10, d12, d13, u22, u24, u26x86_64, aarch64metaUsage:
This is a four-node template. You need to modify the IP addresses of the other three nodes after generating the configuration.
Source: pigsty/conf/demo/minio.yml
demo/minio is a reference configuration for production object storage using the Multi-Node Multi-Drive (MNMD) architecture. Its volume layout, HAProxy health checks, and clients retain MinIO-compatible interfaces.
Key Features:
Access:
Use Cases:
Notes:
/data1 - /data4vip_interface)demo/redis demonstrates standalone/replica, Sentinel, and native Cluster modes supported by Pigsty’s Redis module in one configuration.
demo/redisredis-ms, redis-meta, redis-testdemo/demoSource: pigsty/conf/demo/redis.yml
redis-ms: a 6379 primary and 6380 replica on one noderedis-meta: three Sentinel instances monitoring the redis-ms primaryredis-test: a native Redis Cluster across two nodes with three instances per nodeThe IP addresses, passwords, and memory limits are demonstration values. Adjust them to the real topology, then install the Redis module with the redis.yml playbook.
demo/kafka declares two Kafka 4.x dynamic KRaft clusters across four nodes: the plaintext single-node development cluster kf-meta, and the three-node TLS/SCRAM/ACL demonstration cluster kf-test.
demo/kafkakf-meta: Single combined Broker/Controller node in plaintext modekf-test: Three combined nodes with TLS/SCRAM/ACL, topic replication factor 3, and min.insync.replicas=2deploy.yml only deploys the core path and does not run the KAFKA playbook automatically. Each kafka.yml run must select one complete Kafka cluster; the role rejects convergence against only part of a cluster.
Source: pigsty/conf/demo/kafka.yml
kf-meta creates quickstart.events for single-node development and connectivity tests.kf-test creates the test-app SCRAM user, prefix ACLs, and the three-replica test.events topic.kafka-stack and java-runtime; when using only a local repository, cache both complete package groups first.See the KAFKA module for operations, security, and scaling constraints.
demo/mysql is the four-node example for the native MySQL 8.4 LTS pilot module. It is distinct from conf/mysql.yml, which provides MySQL protocol compatibility through the OpenHalo PostgreSQL kernel.
demo/mysqlmy-meta: Standalone MySQL 8.4 instancemy-test: Three-node, single-primary InnoDB Cluster with MySQL Router on every memberReplace every CHANGE_ME value in the template. Real deployment also requires explicit approval. Start with read-only preflight checks:
After explicitly approving an active-inventory update, run ./configure -c demo/mysql, then run both node.yml and mysql.yml with --check and real convergence against the same complete cluster scope. The three-node cluster does not accept a partial-member scope.
Source: pigsty/conf/demo/mysql.yml
3306. The three-node cluster also uses Group Replication on 33061, with Router RW on 6446 and RO on 6447 on each member.mysqld_exporter are enabled by default. The current pilot does not provide continuous binlog archiving, PITR, or automatic recovery.node.yml installs the shared trust anchor at /etc/pki/ca.crt; the MySQL role only issues and installs leaf certificates.See the native MySQL pilot documentation for complete constraints and the confirmed removal workflow.
The build/oss configuration template is the build environment configuration for Pigsty open-source edition offline packages, used to batch-build offline installation packages across multiple operating systems.
This configuration is intended for developers and contributors only.
build/ossel9, el10, d12, d13, u22, u24, u26x86_64Usage:
This is a build template with fixed IP addresses, intended for internal use only.
Source: pigsty/conf/build/oss.yml
The build/oss template is the build configuration for Pigsty open-source edition offline packages.
Build Contents:
Supported Operating Systems:
Build Process:
Use Cases:
The build/dev configuration template is Pigsty’s three-node local build and development environment. It is used to validate repository build and package download workflows across EL9, Debian 12, and Ubuntu 24 nodes.
This template is intended only for developers and contributors.
build/devel9, d12, u24)infra,node,pgsql modulesel9, d12, u24x86_64, aarch64build/ossUsage:
This is a fixed-IP development build template. Adjust host addresses for your local environment before use.
Source: pigsty/conf/build/dev.yml
build/dev is mainly used to validate the Pigsty software repository build pipeline, not for ordinary production installation.
Key Features:
pg_version: 18dist/${version}infra,node,pgsql modules by defaultUse Cases:
demo/remote deploys no local PostgreSQL cluster. Instead, it declares multiple pg_exporters on an INFRA node to monitor remote PostgreSQL, PolarDB, or cloud RDS instances.
demo/remote20001-20016Source: pigsty/conf/demo/remote.yml
Each pg_exporters entry uses a unique local listen port and declares the remote instance’s pg_cluster, pg_seq, pg_host, and optional connection settings. The template demonstrates complete URLs, split credentials, database allowlists, and auto-discovery.
All hostnames and credentials are placeholders. Keep only the entries you need, use a least-privilege monitoring account, and never commit real RDS passwords.
demo/saas is a legacy feature-rich single-node example with predefined business users, databases, and application entrypoints. It demonstrates how PostgreSQL, Silo, Redis, Docker, and the portal can be combined.
demo/saasrich, supabaseSource: pigsty/conf/demo/saas.yml
The template contains placeholder database users and databases for Grafana, Bytebase, Kong, Gitea, Wiki, NocoDB, and Odoo. It uses Silo as the pgBackRest repository and includes a Redis replica example and multiple portal domains.
This compatibility/reference bundle does not install every listed application automatically. For new deployments, prefer rich plus the relevant app/* template. Remove unused users, databases, and entrypoints and replace all passwords first.
demo/wool targets small cloud instances in China and defaults to region: china, PostgreSQL 18, and the tiny tuning profiles.
demo/woolmeta, slimSource: pigsty/conf/demo/wool.yml
pg_conf: tiny.yml and node_tune: tiny on pg-meta10.10.10.10 to be replaced by the cloud instance’s private IPThis template trades backup capability for lower resource use and is suitable only for temporary testing. Production deployments must enable and verify backups, tighten network rules, replace default passwords, and remove unused portal entries.
PGSQL is Pigsty’s core module. Ansible inventory declares PostgreSQL clusters; Patroni and etcd provide HA orchestration; pgBackRest provides backup and PITR; HAProxy, VIP, DNS, PgBouncer, and the observability stack expose and monitor database services.
This page follows the Pigsty v4.5.0 source layout. Exact defaults live only in the parameter reference so the module landing page does not become a second stale parameter snapshot.
| Task | Entry point |
|---|---|
| Initialize a cluster or add an instance | Cluster administration · pgsql.yml |
| Create or change users | User administration · pgsql-user.yml |
| Create or change databases | Database administration · pgsql-db.yml |
| Change HBA or parameters | HBA administration · Component administration |
| Patroni switchovers, maintenance, and incidents | Patroni administration |
| Install, create, update, or remove extensions | Extension administration |
| Monitor an external instance | pgsql-monitor.yml |
| Prepare a migration | Migration · pgsql-migration.yml |
| Remove an instance or cluster | Safe removal workflow · pgsql-rm.yml |
Real runs of pgsql.yml, pgsql-user.yml, pgsql-db.yml, and related playbooks change the target environment; pgsql-rm.yml can delete data and backups by default. Resolve the exact cluster/node and recent backup first. Removal also requires the operator to type and confirm the exact target.
pgsql-pitr.yml, node-local pig pitr, and low-level pig pb restore.Restore is destructive. Production recovery requires an independent recent tested backup and separate gates for shutdown, restore, data validation, timeline promotion, DCS rebuild, replica rebuild, and a fresh full backup.
The current source contains 29 PostgreSQL/PGCAT dashboards under files/grafana/pgsql, covering fleet, cluster, instance, database, table, query, session, transaction, replication, service, PgBouncer, PITR, and alerts.
The PGSQL parameter reference is the single documentation source for v4.5.0 defaults and semantics:
PG_ID: cluster and instance identity.PG_BUSINESS: users, databases, services, and other business objects.PG_INSTALL: kernel, packages, and extensions.PG_BOOTSTRAP: Patroni bootstrap, replication, and database initialization.PG_PROVISION: in-database objects and privileges.PG_BACKUP: pgBackRest and backup repositories.PG_ACCESS: PgBouncer, services, VIP, and DNS.PG_MONITOR: exporters, monitoring registration, and metrics.PG_REMOVE: removal safeguards and cleanup scope.Pigsty is a “configuration-driven” PostgreSQL platform: all behaviors come from the combination of inventory files in ~/pigsty/conf/*.yml and PGSQL parameters.
Once you’ve written the configuration, you can replicate a customized cluster with instances, users, databases, access control, extensions, and tuning policies in just a few minutes.
pigsty/conf/*.yml template or write an Ansible Inventory from scratch, placing cluster groups (all.children.<cls>.hosts) and global variables (all.vars) in the same file.PGSQL parameters in the vars block. The override order from global → cluster → host determines the final value../configure -c <conf> or bin/pgsql-add <cls> and other playbooks to apply the configuration. Pigsty will generate the configuration files needed for Patroni/pgbouncer/pgbackrest based on the parameters.Pigsty’s default demo inventory conf/pgsql.yml is a minimal example: one pg-meta cluster, global pg_version: 18, and a few business user and database definitions. You can expand with more clusters from this base.
Pigsty’s PostgreSQL configuration can be organized from the following dimensions. Subsequent documentation will explain “how to configure” each:
pg_cluster / pg_role / pg_seq / pg_upstream.pg_version, pg_mode, pg_packages, pg_extensions, pg_conf, and other parameters.pg_default_roles and pg_users.pg_databases, baseline, schemas, extensions, pool_* fields and automatically integrate with pgbouncer/Grafana.pg_default_hba_rules and pg_hba_rules to ensure access boundaries for different roles/networks.pg_default_privileges, pg_default_roles, pg_revoke_public parameters, providing an out-of-the-box layered role system.After understanding these parameters, you can write declarative inventory manifests as “configuration as infrastructure” for any business requirement. Pigsty will handle execution and ensure idempotency.
The following snippet shows how to control instance topology, kernel version, extensions, users, and databases in the same configuration file:
pg-analytics cluster contains one primary and one offline replica.pg_version: 18 with a set of extension examples and load olap.yml tuning.pg_databases and pg_users, automatically generating schema/extension and connection pool entries.pg_hba_rules restrict access sources and authentication methods.Modify and apply this inventory to get a customized PostgreSQL cluster without manual configuration.
Choose the appropriate instance and cluster types based on your requirements to configure PostgreSQL database clusters that meet your needs.
You can define different types of instances and clusters. Here are several common PostgreSQL instance/cluster types in Pigsty:
We start with the simplest case: a single instance cluster consisting of one primary:
This configuration is concise and self-describing, consisting only of identity parameters. Matching the Ansible group name to pg_cluster remains convenient for -l pg-test, but it is not a hard membership constraint. Current code discovers actual members from each host’s pg_cluster identity, so one PostgreSQL cluster may span multiple inventory groups.
Use the following command to create this cluster:
For demos, development testing, hosting temporary requirements, or performing non-critical analytical tasks, a single database instance may not be a big problem. However, such a single-node cluster has no high availability. When hardware failures occur, you’ll need to use PITR or other recovery methods to ensure the cluster’s RTO/RPO. For this reason, you may consider adding several read-only replicas to the cluster.
To add a read-only replica instance, you can add a new node to pg-test and set its pg_role to replica.
If the entire cluster doesn’t exist, you can directly create the complete cluster. If the cluster primary has already been initialized, you can add a replica to the existing cluster:
When the cluster primary fails, the read-only instance (Replica) can take over the primary’s work with the help of the high availability system. Additionally, read-only instances can be used to execute read-only queries: many businesses have far more read requests than write requests, and most read-only query loads can be handled by replica instances.
Offline instances are dedicated read-only replicas specifically for serving slow queries, ETL, OLAP traffic, and interactive queries. Slow queries/long transactions have adverse effects on the performance and stability of online business, so it’s best to isolate them from online business.
To add an offline instance, assign it a new instance and set pg_role to offline.
Dedicated offline instances work similarly to common replica instances, but they serve as backup servers in the pg-test-replica service. That is, only when all replica instances are down will the offline and primary instances provide this read-only service.
In many cases, database resources are limited, and using a separate server as an offline instance is not economical. As a compromise, you can select an existing replica instance and mark it with the pg_offline_query flag to indicate it can handle “offline queries”. In this case, this read-only replica will handle both online read-only requests and offline queries. You can use pg_default_hba_rules and pg_hba_rules for additional access control on offline instances.
When Sync Standby is enabled, PostgreSQL will select one replica as the sync standby, with all other replicas as candidates. The primary database will wait for the standby instance to flush to disk before confirming commits. The standby instance always has the latest data with no replication lag, and primary-standby switchover to the sync standby will have no data loss.
PostgreSQL uses asynchronous streaming replication by default. If the primary fails, WAL that has not yet replicated may be lost. pg_rpo is Patroni’s sampled lag threshold for failover candidates, not a hard upper bound on actual loss; the real window also depends on write rate, replication state, and Patroni sampling timing.
However, in some critical scenarios (e.g., financial transactions), data loss is completely unacceptable, or read replication lag is unacceptable. In such cases, you can use synchronous commit to solve this problem. To enable sync standby mode, you can simply use the crit.yml template in pg_conf.
To enable sync standby on an existing cluster, configure the cluster and enable synchronous_mode:
In this case, the PostgreSQL configuration parameter synchronous_standby_names is automatically managed by Patroni.
One replica will be elected as the sync standby, and its application_name will be written to the PostgreSQL primary configuration file and applied.
Quorum Commit provides more powerful control than sync standby: especially when you have multiple replicas, you can set criteria for successful commits, achieving higher/lower consistency levels (and trade-offs with availability).
If you want at least two replicas to confirm commits, you can adjust the synchronous_node_count parameter through Patroni cluster configuration and apply it:
If you want to use more sync replicas, modify the synchronous_node_count value. When the cluster size changes, you should ensure this configuration is still valid to avoid service unavailability.
In this case, the PostgreSQL configuration parameter synchronous_standby_names is automatically managed by Patroni.
After applying the configuration, two sync standbys appear.
Another scenario is using any n replicas to confirm commits. In this case, the configuration is slightly different. For example, if we only need any one replica to confirm commits:
After applying, the configuration takes effect, and all standbys become regular replicas in Patroni. However, in pg_stat_replication, you can see sync_state becomes quorum.
You can clone an existing cluster and create a standby cluster for data migration, horizontal splitting, multi-region deployment, or disaster recovery.
Under normal circumstances, the standby cluster will follow the upstream cluster and keep content synchronized. You can promote the standby cluster to become a truly independent cluster.
The standby cluster definition is basically the same as a normal cluster definition, except that the pg_upstream parameter is additionally defined on the primary. The primary of the standby cluster is called the Standby Leader.
For example, below defines a pg-test cluster and its standby cluster pg-test2. The configuration inventory might look like this:
The primary node pg-test2-1 of the pg-test2 cluster will be a downstream replica of pg-test and serve as the Standby Leader in the pg-test2 cluster.
Just ensure the pg_upstream parameter is configured on the standby cluster’s primary node to automatically pull backups from the original upstream.
If necessary (e.g., upstream primary-standby switchover/failover), you can change the standby cluster’s replication upstream through cluster configuration.
To do this, simply change standby_cluster.host to the new upstream IP address and apply.
You can promote the standby cluster to an independent cluster at any time, so the cluster can independently handle write requests and diverge from the original cluster.
To do this, you must configure the cluster and completely erase the standby_cluster section, then apply.
If you specify pg_upstream on a replica instead of the primary, you can configure cascade replication for the cluster.
When configuring cascade replication, you must use the IP address of an instance in the cluster as the parameter value, otherwise initialization will fail. The replica performs streaming replication from a specific instance rather than the primary.
The instance acting as a WAL relay is called a Bridge Instance. Using a bridge instance can share the burden of sending WAL from the primary. When you have dozens of replicas, using bridge instance cascade replication is a good idea.
A Delayed Cluster is a special type of standby cluster used to quickly recover “accidentally deleted” data.
For example, if you want a cluster named pg-testdelay whose data content is the same as the pg-test cluster from one hour ago:
You can also configure a “replication delay” on an existing standby cluster.
When some tuples and tables are accidentally deleted, you can modify this parameter to advance this delayed cluster to an appropriate point in time, read data from it, and quickly fix the original cluster.
Delayed clusters require additional resources, but are much faster than PITR and have much less impact on the system. For very critical clusters, consider setting up delayed clusters.
Pigsty natively supports Citus. You can refer to conf/ha/citus.yml as a complete example.
To define a Citus cluster, you need to specify the following parameters:
pg_mode must be set to citus, not the default pgsqlpg_shard and shard number pg_group must be defined on each shard clusterpg_primary_db must be defined to specify the database managed by Patroni.pg_dbsu postgres instead of the default pg_admin_username to execute admin commands, then pg_dbsu_password must be set to a non-empty plaintext passwordAdditionally, extra hba rules are needed to allow SSL access from localhost and other data nodes. As shown below:
On the coordinator node, you can create distributed tables and reference tables and query them from any data node. Starting from 11.2, any Citus database node can act as a coordinator.
Choosing a “kernel” in Pigsty means determining the PostgreSQL major version, mode/distribution, packages to install, and tuning templates to load.
The Pigsty v4.5 source currently supports PostgreSQL 14-18 and uses 18 by default. The following content shows how to make these choices through configuration files.
pg_version: Specify the PostgreSQL major version (default 18). Pigsty will automatically map to the correct package name prefix based on the version.pg_packages: Define the core package set to install, supports using package aliases (default pgsql-main pgsql-common, includes kernel + patroni/pgbouncer/pgbackrest and other common tools).pg_extensions: List of additional extension packages to install, also supports aliases; defaults to empty meaning only core dependencies are installed.Effect: Ansible will pull packages corresponding to
pg_version=18during installation, pre-install extensions to the system, and database initialization scripts can then directlyCREATE EXTENSION.
Extension support varies across versions in Pigsty’s offline repository: 14 has relatively fewer available extensions, while 17/18 have the broadest coverage. If an extension is not pre-packaged, it can be added via repo_extra_packages.
pg_mode controls the kernel “flavor” to deploy. Default pgsql indicates standard PostgreSQL. Pigsty currently supports the following modes:
| Mode | Scenario |
|---|---|
pgsql |
Standard PostgreSQL, HA + replication |
citus |
Citus distributed cluster, requires additional pg_shard / pg_group |
gpsql |
Cloudberry / Greenplum / MatrixDB |
mssql |
Babelfish |
mysql |
OpenGauss/HaloDB compatible with MySQL protocol |
polar |
Alibaba PolarDB (based on pg polar distribution) |
ivory |
IvorySQL (Oracle-compatible syntax) |
pgtde |
Percona PostgreSQL with pg_tde under /usr/pgtde-$v |
oriole |
OrioleDB storage engine |
agens |
AgensGraph graph database kernel |
pgedge |
pgEdge distributed replication kernel |
pg_mode determines binary paths, Patroni integration, and some kernel-specific logic; it does not automatically add every required package, extension, and business database. Use the matching conf/*.yml template in real deployments, or explicitly configure pg_packages, pg_extensions, pg_libs, and pg_databases. Here is a minimal Citus example:
conf/ha/citus.ymlprovides the current complete example. The minimal configuration above explicitly installs Citus packages and creates the extension in thecitusdatabase.
Besides system packages, you can control components automatically loaded after database startup through the following parameters:
pg_libs: List to write to shared_preload_libraries. For example: pg_libs: 'timescaledb, pg_stat_statements, auto_explain'.pg_default_extensions / pg_default_schemas: Control schemas and extensions pre-created in template1 and postgres by initialization scripts.pg_parameters: Rendered by Pigsty into postgresql.auto.conf during configuration. Do not also manage the same settings manually with ALTER SYSTEM.Example: Enable TimescaleDB, pgvector and customize some system parameters.
Effect: During initialization, default extensions are created in
template1andpostgres; newly created databases based ontemplate1inherit those objects.pg_parametersis written directly topostgresql.auto.conf.
pg_conf)
pg_conf points to Patroni templates in roles/pgsql/templates/*.yml. Pigsty includes four built-in general templates:
| Template | Applicable Scenario |
|---|---|
oltp.yml |
Default template, for 4–128 core TP workload |
olap.yml |
Optimized for analytical scenarios |
crit.yml |
Emphasizes sync commit/minimal latency, suitable for zero-loss scenarios like finance |
tiny.yml |
Lightweight machines / edge scenarios / resource-constrained environments |
You can directly replace the template or customize a YAML file in templates/, then specify it in cluster vars.
Effect: Copy
crit.ymlas Patroni configuration, overlaypg_parameterswritten topostgresql.auto.conf, making instances run immediately in synchronous commit mode.
olap.yml tuning.pg_libs.Replace the above parameters according to business needs to complete all kernel-level customization.
PostgreSQL package naming conventions vary significantly across different operating systems:
pgvector_18, postgis36_18*postgresql-18-pgvector, postgresql-18-postgis-3This difference adds cognitive burden to users: you need to remember different package name rules for different systems, and handle the embedding of PostgreSQL version numbers.
Pigsty solves this problem through the Package Alias mechanism: you only need to use unified aliases, and Pigsty will handle all the details:
Aliases can also group a set of packages as a whole. For example, Pigsty’s default installed packages - the default value of pg_packages is:
Pigsty will query the current operating system alias list (assuming el10.x86_64) and translate it to PGSQL kernel, extensions, and toolkits:
Next, Pigsty further translates pgsql-main using the currently specified PG major version (assuming pg_version = 18):
Through this approach, Pigsty shields the complexity of packages, allowing users to simply specify the functional components they want.
You can use package aliases in the following four parameters, and the aliases will be automatically converted to actual package names according to the translation process:
pg_extensions - PG extension packagespg_packages - PG kernel/base utility packagesrepo_packages - Package download parameter: packages to download to local repositoryrepo_extra_packages - Extension installation parameter: additional packages to download to local repositoryYou can find the alias mapping files for each operating system and architecture in the roles/node_id/vars/ directory of the Pigsty project source code:
el10.x86_64el10.aarch64el9.x86_64el9.aarch64el8.x86_64el8.aarch64u26.x86_64u26.aarch64u24.x86_64u24.aarch64u22.x86_64u22.aarch64d13.x86_64d13.aarch64d12.x86_64d12.aarch64Pigsty’s alias system uses $v as a placeholder for the PostgreSQL version number. When you specify a PostgreSQL version using pg_version, all $v in aliases will be replaced with the actual version number.
For example, when pg_version: 18:
| Alias Definition (EL) | Expanded Result |
|---|---|
postgresql$v* |
postgresql18* |
pgvector_$v* |
pgvector_18* |
timescaledb-tsl_$v* |
timescaledb-tsl_18* |
| Alias Definition (Debian/Ubuntu) | Expanded Result |
|---|---|
postgresql-$v |
postgresql-18 |
postgresql-$v-pgvector |
postgresql-18-pgvector |
postgresql-$v-timescaledb-tsl |
postgresql-18-timescaledb-tsl |
On EL systems, many aliases use the * wildcard to match related subpackages. For example:
postgis36_18* will match postgis36_18, postgis36_18-client, postgis36_18-utils, etc.postgresql18* will match postgresql18, postgresql18-server, postgresql18-libs, postgresql18-contrib, etc.This design ensures you don’t need to list each subpackage individually - one alias can install the complete extension.
In this document, “user” refers to a logical object within a database cluster created with
CREATE USER/ROLE.
In PostgreSQL, users belong directly to the database cluster rather than a specific database. Therefore, when creating business databases and users, follow the principle of “users first, databases later”.
Pigsty defines roles and users through two config parameters:
pg_default_roles: Define globally shared roles and userspg_users: Define business users and roles at cluster levelThe former defines roles/users shared across the entire environment; the latter defines business roles/users specific to a single cluster. Both have the same format as arrays of user definition objects. Users/roles are created sequentially in array order, so later users can belong to roles defined earlier.
By default, all users marked with pgbouncer: true are added to the Pgbouncer connection pool user list.
Example from Pigsty demo pg-meta cluster:
Each user/role definition is a complex object. Only name is required:
User-level pool quota is consistently defined by
pool_connlimit(mapped to Pgbouncermax_user_connections).
The only required field is name - a valid, unique username within the cluster. All other params have sensible defaults.
| Field | Category | Type | Attr | Description |
|---|---|---|---|---|
name |
Basic | string |
Required | Username, must be valid and unique |
state |
Basic | enum |
Optional | State: create (default), absent |
password |
Basic | string |
Mutable | User password, plaintext or hash |
comment |
Basic | string |
Mutable | User comment |
login |
Privilege | bool |
Mutable | Can login, default true |
superuser |
Privilege | bool |
Mutable | Is superuser, default false |
createdb |
Privilege | bool |
Mutable | Can create databases, default false |
createrole |
Privilege | bool |
Mutable | Can create roles, default false |
inherit |
Privilege | bool |
Mutable | Inherit role privileges, default true |
replication |
Privilege | bool |
Mutable | Can replicate, default false |
bypassrls |
Privilege | bool |
Mutable | Bypass RLS, default false |
connlimit |
Privilege | int |
Mutable | Connection limit, -1 unlimited |
expire_in |
Validity | int |
Mutable | Expire N days from now (priority) |
expire_at |
Validity | string |
Mutable | Expiration date, YYYY-MM-DD format |
roles |
Role | array |
Additive | Roles array, string or object format |
parameters |
Params | object |
Mutable | Role-level parameters |
pgbouncer |
Pool | bool |
Mutable | Add to connection pool, default false |
pool_mode |
Pool | enum |
Mutable | Pool mode: transaction (default) |
pool_connlimit |
Pool | int |
Mutable | Pool user max connections |
name
String, required. Username - must be unique within the cluster.
Must be a valid PostgreSQL identifier matching ^[a-z_][a-z0-9_]{0,62}$: starts with lowercase letter or underscore, contains only lowercase letters, digits, underscores, max 63 chars.
state
Enum for user operation: create or absent. Default create.
| State | Description |
|---|---|
create |
Default, create user, update if exists |
absent |
Delete user with DROP ROLE |
These system users cannot be deleted via state: absent (to prevent cluster failure):
postgres: Database superuserreplicator: Replication user (or pg_replication_username)dbuser_dba: Admin user (or pg_admin_username)dbuser_monitor: Monitor user (or pg_monitor_username)password
String, mutable. User password - users without password can’t login via password auth.
Password can be:
| Format | Example | Description |
|---|---|---|
| Plaintext | DBUser.Meta |
Not recommended, logged to config |
| SCRAM-SHA-256 | SCRAM-SHA-256$4096:xxx$yyy:zzz |
Recommended, PG10+ default |
| MD5 hash | md5... |
Legacy compatibility |
When setting password, Pigsty temporarily disables logging to prevent leakage:
To generate SCRAM-SHA-256 hash:
comment
String, mutable. User comment, defaults to business user {name}.
Set via COMMENT ON ROLE, supports special chars (quotes auto-escaped).
login
Boolean, mutable. Can login, default true.
Setting false creates a Role rather than User - typically for permission grouping.
In PostgreSQL, CREATE USER equals CREATE ROLE ... LOGIN.
superuser
Boolean, mutable. Is superuser, default false.
Superusers have full database privileges, bypassing all permission checks.
Pigsty provides default superuser via pg_admin_username (dbuser_dba). Don’t create additional superusers unless necessary.
createdb
Boolean, mutable. Can create databases, default false.
Some applications (Gitea, Odoo, etc.) may require CREATEDB privilege for their admin users.
createrole
Boolean, mutable. Can create other roles, default false.
Users with CREATEROLE can create, modify, delete other non-superuser roles.
inherit
Boolean, mutable. Auto-inherit privileges from member roles, default true.
Setting false requires explicit SET ROLE to use member role privileges.
replication
Boolean, mutable. Can initiate streaming replication, default false.
Usually only replication users (replicator) need this. Normal users shouldn’t have it unless for logical decoding subscriptions.
bypassrls
Boolean, mutable. Bypass row-level security (RLS) policies, default false.
When enabled, user can access all rows even with RLS policies. Usually only for admins.
connlimit
Integer, mutable. Max concurrent connections, default -1 (unlimited).
Positive integer limits max simultaneous sessions for this user. Doesn’t affect superusers.
expire_in
Integer, mutable. Expire N days from current date.
This param has higher priority than expire_at. Expiration recalculated on each playbook run - good for temp users needing periodic renewal.
Generates SQL:
expire_at
String, mutable. Expiration date in YYYY-MM-DD format, or special value infinity.
Lower priority than expire_in. Use infinity for never-expiring users.
roles
Array, additive. Roles this user belongs to. Elements can be strings or objects.
Simple format - strings for role names:
Full format - objects for fine-grained control:
Object Format Parameters:
| Param | Type | Description |
|---|---|---|
name |
string | Role name (required) |
state |
enum | grant (default) or absent/revoke: control membership |
admin |
bool | true: WITH ADMIN OPTION, false: REVOKE ADMIN |
set |
bool | PG16+: true: WITH SET TRUE, false: REVOKE SET |
inherit |
bool | PG16+: true: WITH INHERIT TRUE, false: REVOKE INHERIT |
PostgreSQL 16+ New Features:
PostgreSQL 16 introduced finer-grained role membership control:
SET ROLE to switch to this roleset and inherit options only work in PG16+. On earlier versions they’re ignored with warning comments.
parameters
Object, mutable. Role-level config params via ALTER ROLE ... SET. Applies to all sessions for this user.
Use special value DEFAULT (case-insensitive) to reset to PostgreSQL default:
Common role-level params:
| Parameter | Description | Example |
|---|---|---|
work_mem |
Query work memory | '64MB' |
statement_timeout |
Statement timeout | '30s' |
lock_timeout |
Lock wait timeout | '10s' |
idle_in_transaction_session_timeout |
Idle transaction timeout | '10min' |
search_path |
Schema search path | 'app,public' |
log_statement |
Log level | 'ddl' |
temp_file_limit |
Temp file size limit | '10GB' |
Query user-level params via pg_db_role_setting system view.
pgbouncer
Boolean, mutable. Add user to Pgbouncer user list, default false.
For prod users needing connection pool access, must explicitly set pgbouncer: true.
Default false prevents accidentally exposing internal users to the pool.
Users with pgbouncer: true are added to /etc/pgbouncer/userlist.txt.
pool_mode
Enum, mutable. User-level pool mode: transaction, session, or statement. Default transaction.
| Mode | Description | Use Case |
|---|---|---|
transaction |
Return connection after txn | Most OLTP apps, default |
session |
Return connection after session | Apps needing session state |
statement |
Return after each statement | Simple stateless queries |
User-level pool params are configured via /etc/pgbouncer/useropts.txt:
pool_connlimit
Integer, mutable. User-level maximum pool connections. If omitted, no user-level override is generated and Pigsty’s global pgbouncer.ini default of 100 applies. PgBouncer uses 0 to mean unlimited.
Pigsty provides a built-in access control / ACL model. Assign these default business roles to users as required:
| Role | Privileges | Typical Use Case |
|---|---|---|
dbrole_readwrite |
Global read-write | Primary application accounts |
dbrole_readonly |
Global read-only | Read-only application access |
dbrole_admin |
DDL privileges | Application administrators and table creation |
dbrole_offline |
Independent read-only; instance scope controlled by HBA | Ad hoc users, ETL, and analytics |
dbrole_offline does not itself restrict a user to offline instances. To establish that boundary, set role: offline on the corresponding HBA rule; see Offline Role and Instance Isolation.
To redesign your own ACL system, customize:
pg_default_roles: System-wide roles and global userspg_default_privileges: Default privileges for new objectspg-init-roles.sql: Role creation SQL templatepg-init-template.sql: Privilege SQL templatePgbouncer is enabled by default as connection pool middleware. Pigsty adds all users in pg_users with explicit pgbouncer: true flag to the pgbouncer user list.
Users in connection pool are listed in /etc/pgbouncer/userlist.txt:
User-level pool params are maintained in /etc/pgbouncer/useropts.txt:
When creating users, Pgbouncer user list is refreshed via online reload - doesn’t affect existing connections.
Pgbouncer runs as same dbsu as PostgreSQL (default postgres OS user). Use pgb alias to access pgbouncer admin functions.
pgbouncer_auth_query param allows dynamic query for pool user auth - convenient when you prefer not to manually manage pool users.
For user management operations, see User Management.
For user access privileges, see Access Control: Role System.
In this document, “database” refers to a logical object within a database cluster created with
CREATE DATABASE.
A PostgreSQL cluster can serve multiple databases simultaneously. In Pigsty, you can define required databases in cluster configuration.
Pigsty customizes the template1 template database - creating default schemas, installing default extensions, configuring default privileges. Newly created databases inherit these settings from template1.
You can also specify other template databases via template for instant database cloning.
By default, all business databases are 1:1 added to Pgbouncer connection pool; pg_exporter auto-discovers all business databases for in-database object monitoring.
All databases are also registered as PostgreSQL datasources in Grafana on all INFRA nodes for PGCAT dashboards.
Business databases are defined in cluster param pg_databases, an array of database definition objects.
During cluster initialization, databases are created in definition order, so later databases can use earlier ones as templates.
Example from Pigsty demo pg-meta cluster:
Each database definition is a complex object with fields below. Only name is required:
Since Pigsty
v4.1.0, database pool fields are unified aspool_reserveandpool_connlimit; legacy aliasespool_size_reserve/pool_max_db_connare converged.
The only required field is name - a valid, unique database name within the cluster. All other params have sensible defaults.
Parameters marked “Immutable” only take effect at creation; changing them requires database recreation.
| Field | Category | Type | Attr | Description |
|---|---|---|---|---|
name |
Basic | string |
Required | Database name, must be valid and unique |
state |
Basic | enum |
Optional | State: create (default), absent, recreate |
owner |
Basic | string |
Mutable | Database owner, defaults to postgres |
comment |
Basic | string |
Mutable | Database comment |
template |
Template | string |
Immutable | Template database, default template1 |
strategy |
Template | enum |
Immutable | Clone strategy: FILE_COPY or WAL_LOG (PG15+) |
encoding |
Encoding | string |
Immutable | Character encoding, default inherited (UTF8) |
locale |
Encoding | string |
Immutable | Locale setting, default inherited (C) |
lc_collate |
Encoding | string |
Immutable | Collation rule, default inherited (C) |
lc_ctype |
Encoding | string |
Immutable | Character classification, default inherited (C) |
locale_provider |
Encoding | enum |
Immutable | Locale provider: libc, icu, builtin (PG15+) |
icu_locale |
Encoding | string |
Immutable | ICU locale rules (PG15+) |
icu_rules |
Encoding | string |
Immutable | ICU collation customization (PG16+) |
builtin_locale |
Encoding | string |
Immutable | Builtin locale rules (PG17+) |
tablespace |
Storage | string |
Mutable | Default tablespace, change triggers data migration |
is_template |
Privilege | bool |
Mutable | Mark as template database |
allowconn |
Privilege | bool |
Mutable | Allow connections, default true |
revokeconn |
Privilege | bool |
Mutable | Revoke PUBLIC CONNECT privilege |
connlimit |
Privilege | int |
Mutable | Connection limit, -1 for unlimited |
baseline |
Init | string |
Mutable | SQL baseline file path, runs on every provisioning |
schemas |
Init | (string|object)[] |
Mutable | Schema definitions to create |
extensions |
Init | (string|object)[] |
Mutable | Extension definitions to install |
parameters |
Init | object |
Mutable | Database-level parameters |
pgbouncer |
Pool | bool |
Mutable | Add to connection pool, default true |
pool_mode |
Pool | enum |
Mutable | Pool mode: transaction (default) |
pool_size |
Pool | int |
Mutable | Default pool size, default 50 |
pool_size_min |
Pool | int |
Mutable | Min pool size, default 0 |
pool_reserve |
Pool | int |
Mutable | Reserve pool size, default 30 |
pool_connlimit |
Pool | int |
Mutable | Max database connections, default 100 |
pool_auth_user |
Pool | string |
Mutable | Auth query user |
register_datasource |
Monitor | bool |
Mutable | Register to Grafana datasource, default true |
name
String, required. Database name - must be unique within the cluster.
The current role does not enforce this regular expression, and SQL identifiers are double-quoted. However, the name is also used in temporary file paths and shell/SQL command assembly. For safe operation across the entire automation chain, keep it within 63 bytes, follow ^[A-Za-z_][A-Za-z0-9_$]{0,62}$, and avoid spaces, quotes, slashes, or other special characters.
state
Enum for database operation: create, absent, or recreate. Default create.
| State | Description |
|---|---|
create |
Default, create or modify database, adjust mutable params if exists |
absent |
Delete database with DROP DATABASE WITH (FORCE) |
recreate |
Drop then create, for database reset |
owner
String. Database owner, defaults to pg_dbsu (postgres) if not specified.
Target user must exist. Changing owner executes (old owner retains existing privileges):
Database owner has full control including creating schemas, tables, extensions - useful for multi-tenant scenarios.
comment
String. Database comment, defaults to business database {name}.
Set via COMMENT ON DATABASE, supports Chinese and special characters (Pigsty auto-escapes quotes). Stored in the shared-object comment catalog pg_shdescription, viewable via \l+.
template
String, immutable. Template database for creation, default template1.
PostgreSQL’s CREATE DATABASE clones the template - new database inherits all objects, extensions, schemas, permissions. Pigsty customizes template1 during cluster init, so new databases inherit these settings.
| Template | Description |
|---|---|
template1 |
Default, includes Pigsty pre-configured extensions/schemas/perms |
template0 |
Clean template, required for non-default locale providers |
| Custom database | Use existing database as template for cloning |
When using icu or builtin locale provider, must specify template: template0 since template1 locale settings can’t be overridden.
Using template0 skips monitoring extensions/schemas and default privileges - allowing fully custom database.
strategy
Enum, immutable. Clone strategy: FILE_COPY or WAL_LOG. Available PG15+.
| Strategy | Description | Use Case |
|---|---|---|
FILE_COPY |
Direct file copy with checkpoints before and after | Large templates, lower WAL volume |
WAL_LOG |
Block-by-block copy written to WAL; PG15+ default | Small templates, non-blocking |
WAL_LOG doesn’t block template connections during clone but less efficient for large templates. Ignored on PG14 and earlier.
encoding
String, immutable. Character encoding, inherits from template if unspecified (usually UTF8).
Strongly recommend UTF8 unless special requirements. Cannot be changed after creation.
locale
String, immutable. Locale setting - sets both lc_collate and lc_ctype. Inherits from template (usually C).
Determines string sort order and character classification. Use C or POSIX for best performance and cross-platform consistency; use language-specific locales (e.g., zh_CN.UTF-8) for proper language sorting.
lc_collate
String, immutable. String collation rule. Inherits from template (usually C).
Determines ORDER BY and comparison results. Common values: C (byte order, fastest), C.UTF-8, en_US.UTF-8, zh_CN.UTF-8. Cannot be changed after creation.
lc_ctype
String, immutable. Character classification rule for upper/lower case, digits, letters. Inherits from template (usually C).
Affects upper(), lower(), regex \w, etc. Cannot be changed after creation.
locale_provider
Enum, immutable. Locale implementation provider: libc, icu, or builtin. Available PG15+, default libc.
| Provider | Version | Description |
|---|---|---|
libc |
- | OS C library, traditional default, varies by system |
icu |
PG15+ | ICU library, cross-platform consistent, more langs |
builtin |
PG17+ | PostgreSQL builtin, most efficient, C/C.UTF-8 only |
Using icu or builtin requires template: template0 with corresponding icu_locale or builtin_locale.
icu_locale
String, immutable. ICU locale identifier. Available PG15+ when locale_provider: icu.
ICU identifiers follow BCP 47. Common values:
| Value | Description |
|---|---|
en-US |
US English |
en-GB |
British English |
zh-Hans |
Simplified Chinese |
zh-Hant |
Traditional Chinese |
ja-JP |
Japanese |
ko-KR |
Korean |
icu_rules
String, immutable. Custom ICU collation rules. Available PG16+.
Allows fine-tuning default sort behavior using ICU Collation Customization.
builtin_locale
String, immutable. Builtin locale provider rules. Available PG17+ when locale_provider: builtin. Values: C or C.UTF-8.
builtin provider is PG17’s new builtin implementation - faster than libc with consistent cross-platform behavior. Suitable for C/C.UTF-8 collation only.
tablespace
String, mutable. Default tablespace, default pg_default.
Changing tablespace triggers physical data migration - PostgreSQL moves all objects to new tablespace. Can take long time for large databases, use cautiously.
is_template
Boolean, mutable. Mark database as template, default false.
When true, any user with CREATEDB privilege can use this database as template for cloning. Template databases typically pre-install standard schemas, extensions, and data.
Deleting is_template: true databases: Pigsty first executes ALTER DATABASE ... IS_TEMPLATE false then drops.
allowconn
Boolean, mutable. Allow connections, default true.
Setting false completely disables connections at database level - no user (including superuser) can connect. Used for maintenance or archival purposes.
revokeconn
Boolean, mutable. Revoke PUBLIC CONNECT privilege, default false.
When true, Pigsty executes:
replicator) and monitor user (dbuser_monitor)dbuser_dba) and owner with WITH GRANT OPTIONSetting false restores PUBLIC CONNECT privilege.
connlimit
Integer, mutable. Max concurrent connections, default -1 (unlimited).
Positive integer limits max simultaneous sessions. Doesn’t affect superusers.
baseline
String. SQL baseline file path executed while provisioning the database.
Baseline files typically contain schema definitions, initial data, stored procedures. Path is relative to Ansible search path, usually in files/.
Whenever baseline is defined, the current role runs the file on every provisioning pass for that database, even if the database already exists. It also runs after state: recreate. Make the baseline SQL idempotent, or avoid rerunning it against an existing database.
schemas
Array, mutable (add/remove). Schema definitions to create or drop. Elements can be strings or objects.
Simple format - strings for schema names (create only):
Full format - objects for owner and drop operations:
Create uses IF NOT EXISTS; drop uses CASCADE (deletes all objects in schema).
extensions
Array, mutable (add/remove). Extension definitions to install or uninstall. Elements can be strings or objects.
Simple format - strings for extension names (install only):
Full format - objects for schema, version, and uninstall:
Installation uses IF NOT EXISTS ... CASCADE; PostgreSQL emits a NOTICE and skips an extension that already exists, while automatically installing dependencies when possible. Uninstallation uses CASCADE and deletes dependent objects.
parameters
Object, mutable. Database-level config params via ALTER DATABASE ... SET. Applies to all sessions connecting to this database.
Use special value DEFAULT (case-insensitive) to reset to PostgreSQL default:
pgbouncer
Boolean, mutable. Add database to Pgbouncer pool list, default true.
Setting false excludes database from Pgbouncer - clients can’t access via connection pool. For internal management databases or direct-connect scenarios.
pool_mode
Enum, mutable. Pgbouncer pool mode: transaction, session, or statement. Default transaction.
| Mode | Description | Use Case |
|---|---|---|
transaction |
Return connection after txn | Most OLTP apps, default |
session |
Return connection after session | Apps needing session state |
statement |
Return after each statement | Simple stateless queries |
pool_size
Integer, mutable. Pgbouncer default pool size, default 50.
Pool size is the regular backend-connection limit for this database’s pool; pool_size_min controls prewarmed connections. Adjust it for the workload.
pool_size_min
Integer, mutable. Pgbouncer minimum pool size, default 0.
Values > 0 pre-create specified backend connections for connection warming, reducing first-request latency.
pool_reserve
Integer, mutable. Pgbouncer reserve pool size, default 30.
When default pool exhausted, Pgbouncer can allocate up to pool_reserve additional connections for burst traffic.
pool_connlimit
Integer, mutable. Max connections via Pgbouncer pool, default 100.
This is Pgbouncer-level limit, independent of database’s connlimit param.
pool_auth_user
String, mutable. User for Pgbouncer auth query.
Requires pgbouncer_auth_query enabled. When set, all Pgbouncer connections to this database use specified user for auth query password verification.
register_datasource
Boolean, mutable. Register database to Grafana as PostgreSQL datasource, default true.
Set false to skip Grafana registration. For temp databases, test databases, or internal databases not needed in monitoring.
Many parameters inherit from template database if not explicitly specified. Default template is template1, whose encoding settings are determined by cluster init params:
| Cluster Param | Default | Description |
|---|---|---|
pg_encoding |
UTF8 |
Cluster encoding |
pg_locale |
C / C-UTF-8 (if supported) |
Cluster locale |
pg_lc_collate |
C / C-UTF-8 (if supported) |
Cluster collation |
pg_lc_ctype |
C / C-UTF-8 (if supported) |
Cluster ctype |
New databases fork from template1, which is customized during PG_PROVISION with extensions, schemas, and default privileges. Unless you explicitly use another template.
Pigsty provides rich customization params. To customize template database, refer to:
pg_default_roles: Default predefined roles and system userspg_default_privileges: Default privileges for objects created by admin userpg_default_schemas: Default schemas to createpg_default_extensions: Default extensions to createpg_default_hba_rules: Default PostgreSQL HBA rulespgb_default_hba_rules: Default Pgbouncer HBA rulesIf above configurations don’t meet your needs, use pg_init to specify custom cluster init scripts:
pg-init: Cluster init scriptpg-init-template.sql: Template customization SQLpg-init-roles.sql: Default roles SQLPostgreSQL 15+ introduced locale_provider for different locale implementations. These are immutable after creation.
Pigsty’s configure wizard selects builtin C.UTF-8/C locale provider based on PG and OS versions.
Databases inherit cluster locale by default. To specify different locale provider, you must use template0.
Using ICU provider (PG15+):
Using builtin provider (PG17+):
Provider comparison: libc (traditional, OS-dependent), icu (PG15+, cross-platform, feature-rich), builtin (PG17+, most efficient C/C.UTF-8).
Pgbouncer connection pool optimizes short-connection performance, reduces contention, prevents excessive connections from overwhelming database, and provides flexibility during migrations.
Pigsty configures 1:1 connection pool for each PostgreSQL instance, running as same pg_dbsu (default postgres OS user). Pool communicates with database via /var/run/postgresql Unix socket.
Pigsty adds all databases in pg_databases to pgbouncer by default.
Set pgbouncer: false to exclude specific databases.
Pgbouncer database list and config params are defined in /etc/pgbouncer/database.txt:
When creating databases, Pgbouncer database list is refreshed via online reload - doesn’t affect existing connections.
HBA (Host-Based Authentication) controls “who can connect to the database, from where, and how”. See Authentication for the authentication model and default rules.
Pigsty manages HBA rules declaratively through pg_default_hba_rules and pg_hba_rules.
Pigsty renders the following config files during cluster init or HBA refresh:
| Config File | Path | Description |
|---|---|---|
| PostgreSQL HBA | /pg/data/pg_hba.conf |
PostgreSQL server HBA rules |
| PgBouncer HBA | /etc/pgbouncer/pgb_hba.conf |
Connection pool HBA rules |
HBA rules are controlled by these parameters:
| Parameter | Level | Description |
|---|---|---|
pg_default_hba_rules |
G | PostgreSQL global default HBA |
pg_hba_rules |
G/C/I | PostgreSQL cluster/instance add |
pgb_default_hba_rules |
G | PgBouncer global default HBA |
pgb_hba_rules |
G/C/I | PgBouncer cluster/instance add |
Rule features:
role field, auto-filter based on instance’s pg_roleorder field, controls position in final config fileAfter modifying config, re-render config files and reload services:
Script executes the following playbook:
PostgreSQL only: ./pgsql.yml -l <cls> -t pg_hba,pg_reload -e pg_reload=true
PgBouncer only: ./pgsql.yml -l <cls> -t pgbouncer_hba,pgbouncer_reload
Don’t directly edit /pg/data/pg_hba.conf or /etc/pgbouncer/pgb_hba.conf - they’ll be overwritten on next playbook run.
All changes should be made in pigsty.yml, then execute bin/pgsql-hba to refresh.
pg_default_hba_rules
PostgreSQL global default HBA rule list, usually defined in all.vars, provides base access control for all clusters.
rule[], Level: Global (G)pg_hba_rules
PostgreSQL cluster/instance-level additional HBA rules, can override at cluster or instance level, merged with default rules and sorted by order.
rule[], Level: Global/Cluster/Instance (G/C/I), Default: []pgb_default_hba_rules
PgBouncer global default HBA rule list, usually defined in all.vars.
rule[], Level: Global (G)pgb_hba_rules
PgBouncer cluster/instance-level additional HBA rules.
rule[], Level: Global/Cluster/Instance (G/C/I), Default: []Note: PgBouncer HBA does not support
db: replication.
Each HBA rule is a YAML dict supporting these fields:
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
user |
string | No | all |
Username, supports all, placeholders, +rolename |
db |
string | No | all |
Database name, supports all, replication, db name |
addr |
string | Yes* | - | Address alias or CIDR, see Address Aliases |
auth |
string | No | pwd |
Auth method alias, see Auth Methods |
title |
string | No | - | Rule description, rendered as comment in config |
role |
string | No | common |
Instance role filter, see Role Filtering |
order |
int | No | 1000 |
Sort weight, lower first, see Order Sorting |
rules |
list | Yes* | - | Raw HBA text lines, mutually exclusive with addr |
Either
addrorrulesmust be specified. Userulesto write raw HBA format directly.
Pigsty provides address aliases to simplify HBA rule writing:
| Alias | Expands To | Description |
|---|---|---|
local |
Unix socket | Local Unix socket |
localhost |
Unix socket + 127.0.0.1/32 + ::1/128 |
Loopback addresses |
admin |
${admin_ip}/32 |
Admin IP address |
infra |
All infra group node IPs | Infrastructure nodes |
cluster |
All current cluster member IPs | Same cluster instances |
intra / intranet |
10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 |
Intranet CIDRs |
world / all |
0.0.0.0/0 + ::/0 |
Any address (IPv4 + IPv6) |
<CIDR> |
Direct use | e.g., 192.168.1.0/24 |
Intranet CIDRs can be customized via node_firewall_intranet:
Pigsty provides auth method aliases for simplified config:
| Alias | Actual Method | Connection Type | Description |
|---|---|---|---|
pwd |
scram-sha-256 or md5 |
host |
Auto-select based on pg_pwd_enc |
ssl |
scram-sha-256 or md5 |
hostssl |
Force SSL + password |
ssl-sha |
scram-sha-256 |
hostssl |
Force SSL + SCRAM-SHA-256 |
ssl-md5 |
md5 |
hostssl |
Force SSL + MD5 |
cert |
cert |
hostssl |
Client certificate auth |
trust |
trust |
host |
Unconditional trust (dangerous) |
deny / reject |
reject |
host |
Reject connection |
ident |
ident |
host |
OS user mapping (PostgreSQL) |
peer |
peer |
local |
OS user mapping (PgBouncer/local) |
pg_pwd_encdefaults toscram-sha-256, can be set tomd5for legacy client compatibility.
HBA rules support these user placeholders, auto-replaced with actual usernames during rendering:
| Placeholder | Default | Corresponding Param |
|---|---|---|
${dbsu} |
postgres |
pg_dbsu |
${repl} |
replicator |
pg_replication_username |
${monitor} |
dbuser_monitor |
pg_monitor_username |
${admin} |
dbuser_dba |
pg_admin_username |
The role field in HBA rules controls which instances the rule applies to:
| Role | Description |
|---|---|
common |
Default, applies to all instances |
primary |
Primary instance only |
replica |
Replica instance only |
offline |
Offline instance only (pg_role: offline or pg_offline_query: true) |
standby |
Standby instance |
delayed |
Delayed replica instance |
Role filtering matches based on instance’s pg_role variable. Non-matching rules are commented out (prefixed with #).
PostgreSQL HBA is first-match-wins, rule order is critical. Pigsty controls rule rendering order via the order field.
Order Interval Convention
| Interval | Usage |
|---|---|
0 - 99 |
User high-priority rules (before all defaults) |
100 - 650 |
Default rule zone (spaced by 50 for insertion) |
1000+ |
User rule default (rules without order) |
PostgreSQL Default Rules Order
| Order | Rule Description |
|---|---|
| 100 | dbsu local ident |
| 150 | dbsu replication local |
| 200 | replicator localhost |
| 250 | replicator intra replication |
| 300 | replicator intra postgres |
| 350 | monitor localhost |
| 400 | monitor infra |
| 450 | admin infra ssl |
| 500 | admin world ssl |
| 550 | dbrole_readonly localhost |
| 600 | dbrole_readonly intra |
| 650 | dbrole_offline intra |
PgBouncer Default Rules Order
| Order | Rule Description |
|---|---|
| 100 | dbsu local peer |
| 150 | all localhost pwd |
| 200 | monitor pgbouncer intra |
| 250 | monitor world deny |
| 300 | admin intra pwd |
| 350 | admin world deny |
| 400 | all intra pwd |
Alias Form: Using Pigsty simplified syntax
Rendered result:
Raw Form: Using PostgreSQL HBA syntax directly
Rendered result:
Blacklist IP: Use order: 0 to ensure first match
Whitelist App Server: High priority for specific IP
Admin Force Certificate: Override default SSL password auth
Offline Instance Dedicated Network: Only on offline instances
Restrict Access by Database: Sensitive databases limited to specific networks
PgBouncer Dedicated Rules: Note no db: replication support
View Current HBA Rules
Test Connection Auth
Common Issues
| Error Message | Possible Cause | Solution |
|---|---|---|
no pg_hba.conf entry for host... |
No matching HBA rule | Add corresponding rule and refresh |
password authentication failed |
Wrong password or enc | Check password and pg_pwd_enc |
| Rule not taking effect | Not refreshed or order | Run bin/pgsql-hba, check order |
order wiselyrole field matches target instance’s pg_role10.0.0.0/8 not 10.0.0.0/255.0.0.0db: replicationssl and cert require server-side TLS; clients must still use verify-full to authenticate the serveraddr: cluster need refresh after cluster membership changesAccess control combines roles, object privileges, database ACLs, and HBA. This page covers configuration parameters; see Access Control Concepts for design and boundaries.
Pigsty provides a compact ACL model described by these parameters:
pg_default_roles: system roles and system users.pg_users: application users and roles.pg_default_privileges: default privileges on objects created by managed administrators and owners.pg_revoke_public, pg_default_schemas, and pg_default_extensions: default behavior for template1.Manage these parameters together with HBA and database definitions to produce reproducible access-control configuration.
The defaults contain four business roles and four system users:
| Name | Type | Description |
|---|---|---|
dbrole_readonly |
NOLOGIN |
Shared read-only role with SELECT and USAGE |
dbrole_readwrite |
NOLOGIN |
Inherits read-only and adds INSERT, UPDATE, and DELETE |
dbrole_admin |
NOLOGIN |
Inherits pg_monitor and read-write; can create objects and triggers |
dbrole_offline |
NOLOGIN |
Independent read-only role; instance scope must be restricted explicitly through HBA |
postgres |
User | System superuser; same name as pg_dbsu |
replicator |
User | Streaming replication and backup; inherits monitoring and read-only privileges |
dbuser_dba |
User | Primary administration account, also synchronized to PgBouncer |
dbuser_monitor |
User | Monitoring account with pg_monitor; records slow SQL by default |
These definitions live in pg_default_roles. The parameter is a complete list. When customizing it, copy and retain the required default roles and system users, then add new roles in dependency order. If a role name changes, update references in HBA, default privileges, and scripts.
These parameters control system-user names and passwords:
| Parameter | Default | Purpose |
|---|---|---|
pg_dbsu |
postgres |
Database and OS superuser |
pg_dbsu_password |
Empty string | dbsu password, disabled by default |
pg_replication_username |
replicator |
Replication user name |
pg_replication_password |
DBUser.Replicator |
Replication password |
pg_admin_username |
dbuser_dba |
Administrator user name |
pg_admin_password |
DBUser.DBA |
Administrator password |
pg_monitor_username |
dbuser_monitor |
Monitoring user |
pg_monitor_password |
DBUser.Monitor |
Monitoring password |
After changing these parameters, update the corresponding user definitions in pg_default_roles so user names and role attributes remain consistent.
Declare application users with pg_users; see User Configuration for field details. The roles field grants business roles.
Example read-only and read-write users:
Application users inherit default object privileges through dbrole_*. Database CONNECT privileges and pg_hba_rules continue to control which databases and sources can connect.
For finer ACLs, use standard GRANT and REVOKE in baseline SQL or a later playbook, and include those additional grants in reviews.
pg_default_privileges applies to pg_dbsu, pg_admin_username, dbrole_admin, and every declared database owner. The default template is:
Objects created by these identities receive the corresponding privileges automatically. Other object creators need their own
ALTER DEFAULT PRIVILEGESconfiguration.
Additional notes:
pg_revoke_public defaults to true, revoking CREATE from PUBLIC on databases and the public schema.pg_default_schemas and pg_default_extensions control schemas and extensions created in template1/postgres, usually for monitoring objects such as the monitor schema and pg_stat_statements.This adds an HBA rule allowing the partner to reach analytics over TLS from the specified CIDR. pg_hba_rules does not remove broader default rules. If the account must reach only this database, also narrow the default HBA policy and configure database CONNECT privileges.
app_admininherits DDL privileges fromdbrole_admin. To apply the default privileges configured fordbrole_adminto new objects, runSET ROLE dbrole_adminfirst. Ifapp_adminis a declared database owner, it can also create objects directly as that owner.
This parameter replaces the complete default privilege list. Referenced roles must already exist. Changes affect only objects created afterward; grant privileges separately on existing objects.
pg_hba_rules to bind roles, databases, and sources. To restrict dbrole_offline, set role: offline on its rule.pgbouncer: true are written to userlist.txt; pool_mode and pool_connlimit control pool-level quotas.dbuser_monitor receives privileges from pg_default_roles. When adding another monitoring user, grant pg_monitor and check access to the monitor schema.These parameters can be versioned with the inventory. Continue to review effective privileges through PostgreSQL catalogs.
PostgreSQL parameters can be configured at multiple levels with different scopes and precedence. Pigsty supports four configuration levels, from global to local:
| Level | Scope | Configuration Method | Storage Location |
|---|---|---|---|
| Cluster | All instances in cluster | Patroni DCS / Tuning Templates | etcd + postgresql.conf |
| Instance | Single PG instance | pg_parameters / ALTER SYSTEM |
postgresql.auto.conf |
| Database | All sessions in a DB | pg_databases[].parameters |
pg_db_role_setting |
| User | All sessions of a user | pg_users[].parameters |
pg_db_role_setting |
Priority from low to high: Cluster < Instance < Database < User < Session (SET command).
Higher priority settings override lower ones.
For complete PostgreSQL parameter documentation, see PostgreSQL Docs: Server Configuration.
Cluster-level parameters are shared across all instances (primary and replicas) in a PostgreSQL cluster. In Pigsty, cluster parameters are managed via Patroni and stored in DCS (etcd by default).
Pigsty provides four pre-configured Patroni tuning templates optimized for different workloads, specified via pg_conf:
| Template | Use Case | Characteristics |
|---|---|---|
oltp.yml |
OLTP transactions | Low latency, high concurrency (default) |
olap.yml |
OLAP analytics | Large queries, high throughput |
crit.yml |
Critical/Financial | Max durability, safety over perf |
tiny.yml |
Tiny instances | Resource-constrained, dev/test |
Template files are located in roles/pgsql/templates/ and contain auto-calculated values based on hardware specs.
Templates are rendered to /etc/patroni/patroni.yml during cluster initialization. See Tuning Templates for details.
Before cluster creation, you can adjust these templates to modify initial parameters. Once initialized, parameter changes should be made via Patroni’s configuration management.
Patroni stores cluster config in DCS (etcd by default), ensuring consistent configuration across all members.
Storage Structure:
Rendering Flow:
oltp.yml) rendered via Jinja2 to /etc/patroni/patroni.ymlLocal Cache:
Each Patroni instance caches DCS config locally at /pg/conf/<instance>.yml:
Patroni renders DCS config to local PostgreSQL config files:
Load Order (priority low to high):
postgresql.conf: Dynamically generated by Patroni with DCS cluster paramspostgresql.base.conf: Loaded via include, static base configpostgresql.auto.conf: Auto-loaded by PostgreSQL, instance overridesSince postgresql.auto.conf loads last, its parameters override earlier files.
Instance-level parameters apply only to a single PostgreSQL instance, overriding cluster-level config.
These are written to postgresql.auto.conf, which loads last and can override any cluster parameter.
This is a powerful technique for setting instance-specific values:
hot_standby_feedback = on on replicaswork_mem or maintenance_work_mem for specific instancesrecovery_min_apply_delay for delayed replicasIn Pigsty config, use pg_parameters to define instance-level parameters:
Use ./pgsql.yml -l <cls> -t pg_param to apply parameters, which renders to postgresql.auto.conf.
pg_parameters can be defined at different Ansible config levels, priority low to high:
You can also modify instance parameters at runtime via ALTER SYSTEM:
ALTER SYSTEM writes to postgresql.auto.conf.
Note: In Pigsty-managed clusters,
postgresql.auto.confis managed by Ansible viapg_parameters. ManualALTER SYSTEMchanges may be overwritten on next playbook run. Usepg_parametersinpigsty.ymlfor persistent instance-level params.
PostgreSQL has special parameters accepting comma-separated lists. In YAML config, the entire value must be quoted, otherwise YAML parses it as an array:
Pigsty auto-detects these list parameters and renders them without outer quotes:
| Parameter | Description | Example Value |
|---|---|---|
shared_preload_libraries |
Preload shared libs | 'timescaledb, pg_stat_statements' |
search_path |
Schema search path | '"$user", public, app' |
local_preload_libraries |
Local preload libs | 'auto_explain' |
session_preload_libraries |
Session preload libs | 'pg_hint_plan' |
log_destination |
Log output targets | 'csvlog, stderr' |
unix_socket_directories |
Unix socket dirs | '/var/run/postgresql, /tmp' |
temp_tablespaces |
Temp tablespaces | 'ssd_space, hdd_space' |
debug_io_direct |
Direct I/O mode (PG16+) | 'data, wal' |
Rendering Example:
Database-level parameters apply to all sessions connected to a specific database.
Implemented via ALTER DATABASE ... SET, stored in pg_db_role_setting.
Use the parameters field in pg_databases:
Like instance-level params, list-type values must be quoted in YAML.
Database params are set via ALTER DATABASE ... SET. Pigsty auto-selects correct syntax:
List-type params (search_path, temp_tablespaces, local_preload_libraries, session_preload_libraries, log_destination) without outer quotes:
Scalar params with quoted values:
Note: While
log_destinationis in the database whitelist, itscontextissighup, so it cannot take effect at database level. Configure it at instance level (pg_parameters).
User-level parameters apply to all sessions of a specific database user.
Implemented via ALTER USER ... SET, also stored in pg_db_role_setting.
Use the parameters field in pg_users or pg_default_roles:
Same as database-level:
List-type params (search_path, temp_tablespaces, local_preload_libraries, session_preload_libraries) without outer quotes:
Scalar params with quoted values:
Use DEFAULT (case-insensitive) to reset a parameter to PostgreSQL default:
When the same parameter is set at multiple levels, PostgreSQL applies this priority (low to high):
Database vs User Priority:
When a user connects to a specific database and the same parameter is set at both levels, PostgreSQL uses the user-level parameter since it has higher priority.
Example:
analyst connecting to analytics: work_mem = 512MB (user takes precedence)analytics: work_mem = 256MB (database applies)analyst connecting to other DBs: work_mem = 512MB (user applies)Split read and write operations, route traffic correctly, and reliably deliver PostgreSQL cluster capabilities.
Service is an abstraction: it is the form in which database clusters provide capabilities externally, encapsulating the details of the underlying cluster.
Service is critical for stable access in production environments, showing its value during high availability cluster automatic failovers. Personal users typically don’t need to worry about this concept.
The concept of “service” is for production environments. Personal users/single-machine clusters can skip the complexity and directly access the database using instance names/IP addresses.
For example, Pigsty’s default single-node pg-meta.meta database can be directly connected using three different users:
In real-world production environments, we use primary-replica database clusters based on replication. Within the cluster, there is one and only one instance as the leader (primary) that can accept writes. Other instances (replicas) continuously fetch change logs from the cluster leader to stay synchronized. Additionally, replicas can handle read-only requests, significantly offloading the primary in read-heavy, write-light scenarios. Therefore, distinguishing between write requests and read-only requests to the cluster is a very common practice.
Moreover, for production environments with high-frequency short connections, we pool requests through connection pooling middleware (Pgbouncer) to reduce the overhead of connection and backend process creation. But for scenarios like ETL and change execution, we need to bypass the connection pool and directly access the database. At the same time, high-availability clusters may experience failover during failures, which causes a change in the cluster leader. Therefore, high-availability database solutions require write traffic to automatically adapt to cluster leader changes. These different access requirements (read-write separation, pooling vs. direct connection, automatic adaptation to failovers) ultimately abstract the concept of Service.
Typically, database clusters must provide this most basic service:
For production database clusters, at least these two services should be provided:
Additionally, depending on specific business scenarios, there might be other services, such as:
Pigsty provides four different services by default for each PostgreSQL database cluster. Here are the default services and their definitions:
| Service | Port | Description |
|---|---|---|
| primary | 5433 | Production read-write, connect to primary pool (6432) |
| replica | 5434 | Production read-only, connect to replica pool (6432) |
| default | 5436 | Admin, ETL writes, direct access to primary (5432) |
| offline | 5438 | OLAP, ETL, personal users, interactive queries |
Taking the default pg-meta cluster as an example, it provides four default services:
From the sample cluster architecture diagram, you can see how these four services work:
The actual DNS target of pg-meta is controlled by pg_dns_target. The default auto points to the L2 VIP when VIP is enabled; otherwise it points to the inventory primary’s IP. VIP is not enabled by default. See Access Service.
In Pigsty, services are implemented using haproxy on nodes, differentiated by different ports on the host node.
Haproxy is enabled by default on every node managed by Pigsty to expose services, and database nodes are no exception. Although nodes in the cluster have primary-replica distinctions from the database perspective, from the service perspective, all nodes are the same: This means even if you access a replica node, as long as you use the correct service port, you can still use the primary’s read-write service. This design seals the complexity: as long as you can access any instance on the PostgreSQL cluster, you can fully access all services.
This design is similar to the NodePort service in Kubernetes. Similarly, in Pigsty, every service includes these two core elements:
The boundary of Pigsty’s service delivery stops at the cluster’s HAProxy. Users can access these load balancers in various ways. Please refer to Access Service.
All services are declared through configuration files. For instance, the default PostgreSQL service is defined by the pg_default_services parameter:
You can also define additional services in pg_services. Both pg_default_services and pg_services are arrays of Service Definition objects.
Pigsty allows you to define your own services:
pg_default_services: Services uniformly exposed by all PostgreSQL clusters, with four by default.pg_services: Additional PostgreSQL services, can be defined at global or cluster level as needed.haproxy_services: Directly customize HAProxy service content, can be used for other component accessFor PostgreSQL clusters, you typically only need to focus on the first two.
Each service definition generates a new configuration file in the configuration directory of all related HAProxy instances: /etc/haproxy/conf.d/<pg_cluster>-<service>.cfg
Here’s a custom service example standby: When you want to provide a read-only service with no replication delay, you can add this record in pg_services:
The service definition above is rendered as /etc/haproxy/conf.d/pg-test-standby.cfg on the sample three-node pg-test cluster:
Here, all three instances of the pg-test cluster are selected by selector: "[]" and rendered into the backend list of the pg-test-standby service. Because of the /sync health check, the Patroni REST API returns HTTP 200 only on the primary and synchronous standby, so only those members can actually serve requests.
Additionally, the primary satisfies the condition pg_role == primary and is selected by the backup selector, marked as a backup server, and will only be used when no other instances (i.e., sync standby) can satisfy the requirement.
The Primary service is probably the most critical service in production environments. It provides read-write capability to the database cluster on port 5433, with the service definition as follows:
selector: "[]" means all cluster members will be included in the Primary servicecheck: /primary), actually serving Primary service traffic.dest: default means the Primary service destination is affected by the pg_default_service_dest parameterdest is default which will be replaced with the value of pg_default_service_dest, defaulting to pgbouncer.pgbouncer_port, defaulting to 6432If the value of pg_default_service_dest is postgres, then the primary service destination will bypass the connection pool and directly use the PostgreSQL database port (pg_port, default value 5432), which is very useful for scenarios where you don’t want to use a connection pool.
Patroni’s high availability mechanism ensures that at most one instance’s /primary health check is true at any time, so the Primary service will always route traffic to the primary instance.
One benefit of using the Primary service instead of directly connecting to the database is that if the cluster experiences a split-brain situation (for example, killing the primary Patroni with kill -9 without watchdog), Haproxy can still avoid split-brain in this situation, because it only distributes traffic when Patroni is alive and returns primary status.
The Replica service is second only to the Primary service in importance in production environments. It provides read-only capability to the database cluster on port 5434, with the service definition as follows:
selector: "[]" means all cluster members will be included in the Replica servicecheck: /read-only), serving Replica service traffic.[? pg_role == 'primary' || pg_role == 'offline' ] marks the primary and offline replicas as backup servers.dest: default means the Replica service destination is also affected by the pg_default_service_dest parameterdest is default which will be replaced with the value of pg_default_service_dest, defaulting to pgbouncer, same as the Primary servicepgbouncer_port, defaulting to 6432The Replica service is very flexible: If there are living dedicated Replica instances, it will prioritize using these instances to serve read-only requests. Only when all replica instances are down will the primary serve as a fallback for read-only requests. For the common one-primary-one-replica two-node cluster: use the replica as long as it’s alive, use the primary only when the replica is down.
Additionally, unless all dedicated read-only instances are down, the Replica service will not use dedicated Offline instances, thus avoiding mixing online fast queries with offline slow queries and their mutual interference.
The Default service provides service on port 5436, and it’s a variant of the Primary service.
The Default service always bypasses the connection pool and directly connects to PostgreSQL on the primary, which is useful for admin connections, ETL writes, CDC change data capture, etc.
If pg_default_service_dest is changed to postgres, then the Default service is completely equivalent to the Primary service except for port and name. In this case, you can consider removing Default from default services.
The Offline service runs on port 5438 and bypasses the connection pool to access PostgreSQL directly. It is normally used for slow or analytical queries, ETL reads, and interactive personal queries:
The Offline service routes traffic directly to dedicated offline replicas, or regular read-only instances marked with pg_offline_query.
pg_role = offline, or regular read-only instances marked with pg_offline_query = true/replica only returns 200 for replicas, primary returns error, so Offline service will never distribute traffic to the primary instance, even if only the primary remains in the cluster.The Offline service provides restricted read-only service, typically used for two types of queries: interactive queries (personal users), slow queries and long transactions (analytics/ETL).
The Offline service requires extra care. HAProxy’s /replica health check automatically rejects the new primary after a switchover, but selector uses static pg_role / pg_offline_query labels from the inventory. In a one-primary-one-replica cluster where only the replica serves Offline queries, a switchover may temporarily leave no eligible backend.
Reloading an unchanged inventory does not add the old primary to the Offline backend list. First update the inventory labels (or pg_offline_query) to match the new plan and then reload service, or switch the primary back.
If your business model is relatively simple, you can consider removing Default service and Offline service, using Primary service and Replica service to directly connect to the database.
Reload services when cluster membership changes, service definitions or static selector labels change, or relative weights are adjusted. Normal Primary/Replica switchover is handled by Patroni health checks and does not require a separate reload.
The boundary of Pigsty’s service delivery stops at the cluster’s HAProxy. Users can access these load balancers in various ways.
The typical approach is to use DNS or VIP access, binding to all or any number of load balancers in the cluster.

You can use different host & port combinations, which provide PostgreSQL services in different ways.
Host
| Type | Example | Description |
|---|---|---|
| Cluster Domain Name | pg-test |
Access via cluster domain name (resolved by dnsmasq @ infra nodes) |
| Cluster VIP Address | 10.10.10.3 |
Access via L2 VIP address managed by vip-manager, bound to primary |
| Instance Hostname | pg-test-1 |
Access via any instance hostname (resolved by dnsmasq @ infra nodes) |
| Instance IP Address | 10.10.10.11 |
Access any instance IP address |
Port
Pigsty uses different ports to distinguish pg services
| Port | Service | Type | Description |
|---|---|---|---|
| 5432 | postgres | database | Direct access to postgres server |
| 6432 | pgbouncer | middleware | Go through connection pool middleware before postgres |
| 5433 | primary | service | Access primary pgbouncer (or postgres) |
| 5434 | replica | service | Access replica pgbouncer (or postgres) |
| 5436 | default | service | Access primary postgres |
| 5438 | offline | service | Access offline postgres |
Combinations
You can override the default service configuration in several ways. A common requirement is to have Primary service and Replica service bypass Pgbouncer connection pool and directly access PostgreSQL database.
To achieve this, you can change pg_default_service_dest to postgres, so all services with svc.dest='default' in the service definition will use postgres instead of the default pgbouncer as the target.
If you’ve already pointed Primary service to PostgreSQL, then the default service becomes redundant and can be removed.
If you don’t need to distinguish between personal interactive queries and analytics/ETL slow queries, you can consider removing the Offline service from the default service list pg_default_services.
If you don’t need read-only replicas to share online read-only traffic, you can also remove Replica service from the default service list.
Pigsty exposes PostgreSQL services with haproxy on nodes. All haproxy instances in the cluster are configured with the same service definition.
However, you can delegate pg service to a specific node group (e.g., dedicated haproxy lb cluster) rather than haproxy on PostgreSQL cluster members.
To do so, you need to override the default service definition with pg_default_services and set pg_service_provider to the proxy group name.
For example, this configuration will expose pg cluster primary service on haproxy node group proxy with port 10013.
It’s user’s responsibility to make sure each delegate service port is unique among the proxy cluster.
A dedicated load balancer cluster example is provided in the 20-node production environment simulation sandbox: conf/ha/simu.yml
PostgreSQL security combines authentication, authorization, network boundaries, encrypted communication, data protection, and operational process. Pigsty provides configuration entry points for these mechanisms; operators must still harden, verify, and audit the deployment for its environment.
| Topic | Content |
|---|---|
| Security and Compliance | Default state, capability boundaries, and hardening path |
| Authentication | HBA, SCRAM, certificate authentication, and credential management |
| Access Control | Built-in roles, default privileges, database ACLs, and instance-access boundaries |
| Encrypted Communication | CA, TLS, server authentication, and certificate rotation |
| Data Security | Page checksums, replication, backup, PITR, audit, and logging |
| Compliance | Launch checks, control mappings, and evidence requirements |
The inventory describes desired state. Acceptance checks should also inspect HBA, certificates, listen ports, and sensitive files on running nodes, and verify effective roles and privileges through PostgreSQL catalogs.
| Action | Command | Description |
|---|---|---|
| Create Cluster | bin/pgsql-add <cls> |
Create a new PostgreSQL cluster |
| Expand Cluster | bin/pgsql-add <cls> <ip...> |
Add replica to existing cluster |
| Shrink Cluster | bin/pgsql-rm <cls> <ip...> |
Remove instance from cluster |
| Remove Cluster | bin/pgsql-rm <cls> |
Destroy entire PostgreSQL cluster |
| Reload Service | bin/pgsql-svc <cls> [ip...] |
Reload cluster load balancer config |
| Reload HBA | bin/pgsql-hba <cls> [ip...] |
Reload cluster HBA access rules |
| Clone Cluster | - | Clone via standby cluster or PITR |
For other management tasks, see: HA Management, Manage Users, Manage Databases.
To create a new PostgreSQL cluster, first define the cluster in the inventory, then add nodes and initialize:
On managed nodes, create the cluster with: (Execute pgsql.yml playbook on <cls> group)
Example: Create 3-node PG cluster pg-test
demo/pgsql.cast — /demo/pgsql.cast
If you re-run create on an existing cluster, Pigsty won’t remove existing data files, but service configs will be overwritten and the cluster will restart!
Additionally, if you specified a baseline SQL in database definition, it will re-execute - if it contains delete/overwrite logic, data loss may occur.
To add a new replica to an existing PostgreSQL cluster, add the instance definition to inventory: all.children.<cls>.hosts.
Scaling out is similar to creating a cluster. First add the new node to Pigsty: Add Node:
Then run the following on the new node to scale out (Install PGSQL module on new node with same pg_cluster):
After scaling, you should Reload Service to add the new member to load balancer.
Example: Add replica 10.10.10.13 to 2-node cluster pg-test
demo/pgsql-append.cast — /demo/pgsql-append.cast
To remove a replica from an existing PostgreSQL cluster, remove the instance definition from inventory all.children.<cls>.hosts.
Scale-in stops the instance and deletes its data directory by default. First run pig pg list <cls> and pig pb info, verify that the target is not the primary and that a recent restorable backup exists,
then have the operator enter the exact <ip> and execute only after confirmation.
First uninstall PGSQL module from target node (Execute pgsql-rm.yml on <ip>):
After removing PGSQL module, optionally remove the node from Pigsty: Remove Node:
After scaling in, remove the instance from inventory, then Reload Service to remove it from load balancer.
Example: Remove replica 10.10.10.13 from 3-node cluster pg-test
demo/pgsql-shrink.cast — /demo/pgsql-shrink.cast
To destroy a cluster, uninstall PGSQL module from all nodes (Execute pgsql-rm.yml on <cls>):
This is irreversible data deletion. Inspect pig pg list <cls> and pig pb info, verify a recent backup and any independent copy to retain,
and have the operator enter the exact cluster name. The commands below perform the corresponding destruction directly.
After destroying PGSQL, optionally remove all nodes from Pigsty: Remove Node (optional if other services exist):
After removal, delete the entire cluster definition from inventory.
Example: Destroy 3-node PG cluster pg-test
demo/pgsql-rm.cast — /demo/pgsql-rm.cast
Note: If pg_safeguard is configured (or globally true), pgsql-rm.yml will abort to prevent accidental removal.
Override with playbook command line to force removal.
By default, cluster backup repo is deleted with the cluster. To preserve backups (e.g., with centralized repo), set pg_rm_backup=false:
PostgreSQL clusters expose services via HAProxy on host nodes. When service definitions, instance weights, or cluster membership change (for example, scale out or scale in), reload services to update HAProxy’s static member configuration. The default Primary and Replica services detect the current role through Patroni REST API health checks, so ordinary switchover or failover reroutes automatically and does not require regenerating HAProxy configuration.
To reload service config on entire cluster or specific instances (Execute pg_service subtask of pgsql.yml on <cls> or <ip>):
If you use a dedicated load-balancer cluster (pg_service_provider), only reloading the cluster primary updates the load-balancer configuration.
Example: Reload pg-test cluster service config
demo/pgsql-svc.cast — /demo/pgsql-svc.cast
When HBA configs change, reload HBA rules to apply. (pg_hba_rules / pgb_hba_rules)
If you have inventory-role-specific HBA rules or address ranges that reference cluster member aliases, reload HBA after changing pg_role labels or scaling the cluster. Role selectors use static inventory variables and do not change automatically after a Patroni switchover.
To reload PG and Pgbouncer HBA rules on entire cluster or specific instances (Execute HBA subtasks of pgsql.yml on <cls> or <ip>):
Example: Reload pg-test cluster HBA rules
demo/pgsql-hba.cast — /demo/pgsql-hba.cast
PostgreSQL config params are managed by Patroni. Initial params are specified by Patroni config template.
After cluster init, config is stored in Etcd, dynamically managed and synced by Patroni.
Most Patroni config params can be modified via patronictl.
Other params (e.g., etcd DCS config, log/RestAPI config) can be updated via subtasks. For example, when etcd cluster membership changes, refresh Patroni config:
You can override Patroni-managed defaults at different levels: specify params per instance, specify params per user, or specify params per database.
Two ways to clone a cluster: use Standby Cluster, or use Point-in-Time Recovery. The former is simple and requires no backup repository, but it does require a reachable replication upstream and can clone only the latest state. The latter requires a centralized backup repository such as Silo and can clone to any point within the retention period.
| Method | Pros | Cons | Use Cases |
|---|---|---|---|
| Standby Cluster | No backup repository needed | Requires reachable upstream; latest state only | DR, read-write separation, migration |
| PITR | Recover to any point | Requires centralized backup | Undo mistakes, data audit |
Standby Cluster continuously syncs from upstream cluster via streaming replication - the simplest cloning method.
Specify pg_upstream on the new cluster primary to auto-pull data from upstream.
Create standby cluster with:
Standby cluster follows upstream, keeping data in sync. Promote to independent cluster anytime:
Via Config Cluster, remove standby_cluster config to promote:
After promotion, pg-test2 becomes independent cluster accepting writes, forked from pg-test.
If upstream cluster switchover occurs, change standby cluster upstream via Config Cluster:
Point-in-Time Recovery (PITR) allows recovery to any point within backup retention. Requires a centralized backup repository (Silo/S3), but is more powerful.
To clone via PITR, add pg_pitr param specifying recovery target:
Execute clone with pgsql-pitr.yml playbook:
PITR supports multiple recovery target types:
| Target Type | Example | Description |
|---|---|---|
| Time | time: "2025-01-10 10:00:00+00" |
Recover to specific timestamp |
| XID | xid: "250000" |
Recover to before/after txn |
| Name | name: "before_migration" |
Recover to named restore point |
| LSN | lsn: "0/4001C80" |
Recover to specific WAL pos |
| Latest | pg_pitr: {} |
Recover to end of WAL archive |
Pigsty v5.0 PITR keeps archiving enabled by default (archive: true). If you explicitly set archive: false for exploratory recovery, reset archive_mode, restart the cluster, and perform a new full backup after confirming the recovered data is correct:
For detailed PITR usage, see Restore Operations documentation.
Pigsty uses declarative management: first define users in the inventory, then use bin/pgsql-user <cls> <username> to create or modify.
For the complete user definition reference, see User Configuration. See Access Control for roles and privileges, and Authentication for credential management.
name is the key used by pgsql-user.yml to look up a user definition; the playbook does not rename roles. For a rename, create the replacement role, migrate ownership, memberships, and client credentials, validate the cutover, and only then remove the old role. Do not treat delete-and-create as a lossless rename.
| Action | Command | Description |
|---|---|---|
| Create User | bin/pgsql-user <cls> <user> |
Create new business user or role |
| Modify User | bin/pgsql-user <cls> <user> |
Modify existing user properties |
| Delete User | bin/pgsql-user <cls> <user> |
Dependency-aware destructive deletion (state: absent) |
demo/pgsql-user.cast — /demo/pgsql-user.cast
Users defined in pg_users are auto-created during PostgreSQL cluster creation in the pg_user task.
To create a new user on an existing cluster, add user definition to all.children.<cls>.pg_users, then execute:
Example: Create business user dbuser_app
Result: Creates dbuser_app user on primary, sets password, grants dbrole_readwrite role, adds to Pgbouncer pool, reloads Pgbouncer config on all instances.
For manual user creation, you must ensure Pgbouncer user list sync yourself.
Same command as create - playbook is idempotent. When target user exists, Pigsty modifies properties to match config.
Not directly mutable: name is the identity key in the declarative definition. The playbook does not rename an existing role. Use a controlled create, ownership/privilege and client migration, validation, and old-role removal sequence.
All other properties can be modified. Common examples:
Modify password: Update password field. Logging is temporarily disabled during password change to prevent leakage.
Modify privilege attributes: Configure boolean flags for user privileges.
Modify expiration: Use expire_in for relative expiry (N days), or expire_at for absolute date. expire_in takes priority and recalculates on each playbook run - good for temp users needing periodic renewal.
Modify role membership: Use roles array with simple or extended format. Role membership is additive - won’t remove undeclared existing roles. Use state: absent to explicitly revoke.
Manage user parameters: Use parameters dict for user-level params, generates ALTER USER ... SET. Use DEFAULT to reset.
Connection pool config: Set pgbouncer: true to add user to pool. Optional pool_mode and pool_connlimit.
Deleting a user terminates sessions, transfers object ownership, revokes grants, and runs DROP ROLE; it is irreversible. Confirm the exact cluster, role, successor owner, and a recent backup before setting the user to state: absent and applying the change.
Config example:
Deletion process: On the primary, the task runs pg-drop-role <user> postgres --force. It disables login, terminates active sessions, transfers database and tablespace ownership plus objects in each connectable database to postgres, runs DROP OWNED to remove grants, revokes role memberships, and finally runs DROP ROLE. A pre-change audit snapshot is written to /tmp/pg_drop_role_<user>_<timestamp>.log.
Protection: The Ansible task skips postgres and the replication, admin, and monitor usernames configured in inventory. When invoked directly, pg-drop-role protects only the hard-coded default names postgres, replicator, dbuser_dba, and dbuser_monitor; renamed system accounts are not recognized automatically.
pg-drop-role skips DROP OWNED in a database if its preceding REASSIGN OWNED fails, but the cross-database procedure is not one transaction. A mid-run failure can leave the role NOLOGIN, some ownership already transferred, or dependencies still present. The v4.5 Ansible task also uses ignore_errors, so a playbook result is not sufficient evidence. Verify role absence, successor ownership, application cutover, and the audit log afterward.
In v4.5, pgsql-user.yml reloads Pgbouncer but does not reliably prune a deleted role from /etc/pgbouncer/userlist.txt. Check every cluster instance after deletion:
If an exact Pgbouncer entry remains, remove that single line under change control, reload Pgbouncer, and validate application connections. Do not use a broad pattern to delete entries.
For manual user deletion, use pg-drop-role script directly:
Common user configuration examples:
Basic business user
Read-only user
Admin user (can execute DDL)
Temp user (expires in 30 days)
Role (no login, for permission grouping)
User with advanced role options (PG16+)
Common SQL queries for user info:
List all users
View user role membership
View user-level parameters
View expiring users
Connection pool params in user definitions are applied to Pgbouncer when creating/modifying users.
Users with pgbouncer: true are added to /etc/pgbouncer/userlist.txt. User-level pool params (pool_mode, pool_connlimit) are configured via /etc/pgbouncer/useropts.txt.
Use postgres OS user with pgb alias to access Pgbouncer admin database. For more pool management, see Pgbouncer Management.
For a business user, follow Modify User: persist the new password in its pg_users definition, preview the scoped playbook, and then apply it. The three default users require extra coordination because other services consume their credentials.
| Parameter | Default | Role | Consumers |
|---|---|---|---|
pg_admin_password |
DBUser.DBA |
dbuser_dba |
Admin clients, Pgbouncer, Infra service files, pgAdmin |
pg_monitor_password |
DBUser.Monitor |
dbuser_monitor |
Exporters, Pgbouncer, Grafana data sources |
pg_replication_password |
DBUser.Replicator |
replicator |
Patroni replication and .pgpass files |
These accounts belong to pg_default_roles, not pg_users. pgsql-user.yml looks up only pg_users, so do not rotate a default password by overriding pg_users on the command line: that changes the business-user list visible to that run and exposes plaintext in shell history.
Rotate one account at a time:
pigsty.yml or the inventory actually in use; never put the plaintext password on the command line.psql as a superuser and run \password <username>; the meta-command reads the secret interactively.-l cluster/node scope.Refresh every consumer for the account. Replace <cls> and constrain infra to the actual targets:
A mismatch between the replication role and Patroni nodes prevents new replication connections, so rotate that credential in a maintenance window and validate promptly. If VIBE or another module has rendered an admin connection string into its workspace context, rerender that module’s files as well.
In v4.5, env_pgpass adds the new line with lineinfile; it does not remove older lines by username. Because libpq uses the first matching line, inspect every target Infra node after the refresh and remove obsolete entries through controlled editing without printing secrets:
patroni_password protects the Patroni REST API; it is not a PostgreSQL role password. After changing it in inventory, refresh the target PostgreSQL cluster and Infra management side separately:
Then validate authentication and cluster state with patronictl or pig pg list <cls>.
Pigsty uses declarative management: first define databases in the inventory, then use bin/pgsql-db <cls> <dbname> to create or modify.
For the complete database definition reference, see Database Configuration. For database access permissions, see Access Control: Database Isolation.
Note: Some parameters can only be specified at creation time. Modifying these requires recreating the database (use state: recreate).
| Action | Command | Description |
|---|---|---|
| Create Database | bin/pgsql-db <cls> <db> |
Create new business database |
| Modify Database | bin/pgsql-db <cls> <db> |
Modify existing database properties |
| Delete Database | bin/pgsql-db <cls> <db> |
Delete database (requires state: absent) |
| Rebuild Database | bin/pgsql-db <cls> <db> |
Drop and recreate (requires state: recreate) |
| Clone Database | bin/pgsql-db <cls> <db> |
Clone database using template |
demo/pgsql-db.cast — /demo/pgsql-db.cast
Databases defined in pg_databases are auto-created during PostgreSQL cluster creation in the pg_db task.
To create a new database on an existing cluster, add database definition to all.children.<cls>.pg_databases, then execute:
Example: Create business database myapp
Result: Creates myapp database on primary, sets owner to dbuser_myapp, creates app schema, enables pg_trgm and btree_gin extensions. Database is auto-added to Pgbouncer pool and registered as Grafana datasource.
For manual database creation, you must ensure Pgbouncer pool and Grafana datasource sync yourself.
Same command as create - playbook is idempotent when no baseline SQL is defined.
When target database exists, Pigsty modifies properties to match config. However, some properties can only be set at creation.
Immutable properties: These can’t be modified after creation, require state: recreate:
name (database name), template, strategy (clone strategy)encoding, locale/lc_collate/lc_ctype, locale_provider/icu_locale/icu_rules/builtin_localeAll other properties can be modified. Common examples:
Modify owner: Update owner field, executes ALTER DATABASE ... OWNER TO and grants permissions.
Modify connection limit: Use connlimit to limit max connections.
Revoke public connect: Setting revokeconn: true revokes PUBLIC CONNECT privilege, allowing only owner, DBA, monitor, and replication users.
Manage parameters: Use parameters dict for database-level params, generates ALTER DATABASE ... SET. Use special value DEFAULT to reset.
Manage schemas: Use schemas array with simple or extended format. Use state: absent to drop (CASCADE).
Manage extensions: Use extensions array with simple or extended format. Use state: absent to uninstall (CASCADE).
Dropping schemas or uninstalling extensions uses CASCADE, deleting all dependent objects. Understand impact before executing.
Connection pool config: By default all databases are added to Pgbouncer. Configure pgbouncer, pool_mode, pool_size, pool_reserve, pool_size_min, pool_connlimit, and pool_auth_user.
Since Pigsty
v4.1.0, database pool fields are unified aspool_reserveandpool_connlimit; legacy aliasespool_size_reserve/pool_max_db_connare converged.
To delete a database, set state to absent and execute:
Config example:
Deletion process: If is_template: true, first executes ALTER DATABASE ... IS_TEMPLATE false; uses DROP DATABASE ... WITH (FORCE) (PG13+) to force drop and terminate all connections; removes from Pgbouncer pool; unregisters from Grafana datasource.
Protection: System databases postgres, template0, template1 cannot be deleted. Deletion only runs on primary - streaming replication syncs to replicas.
Database deletion is irreversible - permanently deletes all data. Before executing: ensure recent backup exists, confirm no business uses the database, notify stakeholders. Pigsty is not responsible for any data loss from database deletion. Use at your own risk.
recreate state rebuilds database (drop then create):
Config example:
Use cases: Test environment reset, clear dev database, modify immutable properties (encoding, locale), restore to initial state.
Difference from manual DROP + CREATE: Single command; auto-preserves Pgbouncer and Grafana config; auto-loads baseline init script.
Clone PostgreSQL databases using PG template mechanism. During cloning, no active connections to template database are allowed.
Config example:
Instant Clone (PG18+): If using PostgreSQL 18+, Pigsty defaults file_copy_method. With strategy: FILE_COPY, database clone completes in ~200ms without copying data files. E.g., cloning 30GB database: normal takes 18s, instant takes 200ms.
Manual clone: Ensure all connections to template are terminated:
Limitations: Instant clone only available on supported filesystems (xfs, btrfs, zfs, apfs); don’t use postgres database as template; in high-concurrency environments, all template connections must be cleared within clone window (~200ms).
Connection pool params in database definitions are applied to Pgbouncer when creating/modifying databases.
By default all databases are added to Pgbouncer pool (pgbouncer: true). Databases are added to /etc/pgbouncer/database.txt. Database-level pool params (pool_auth_user, pool_mode, pool_size, pool_reserve, pool_size_min, pool_connlimit) are configured via this file.
Use postgres OS user with pgb alias to access Pgbouncer admin database. For more pool management, see Pgbouncer Management.
Pigsty uses Patroni to manage PostgreSQL clusters. It handles config changes, status checks, switchover, restart, reinit replicas, and more.
To use Patroni for management, you need one of the following identities:
pg_dbsu (default postgres), managing the current cluster only.Patroni provides patronictl CLI for management. Pigsty provides a wrapper alias pg to simplify operations.
| Command | Function | Description |
|---|---|---|
edit-config |
Edit Config | Interactively edit cluster Patroni/PostgreSQL config |
list |
List Status | List cluster members and their status |
switchover |
Switchover | Switch primary role to specified replica (planned) |
failover |
Failover | Force failover to specified replica (emergency) |
restart |
Restart | Restart PostgreSQL instance to apply restart-required params |
reload |
Reload | Reload Patroni config (no restart needed) |
reinit |
Reinit Replica | Reinitialize replica (wipe data and re-clone) |
pause |
Pause Auto-Failover | Pause Patroni automatic failover |
resume |
Resume Auto-Failover | Resume Patroni automatic failover |
history |
View History | Show cluster failover history |
show-config |
Show Config | Display current cluster config (read-only) |
query |
Execute Query | Execute SQL query on cluster members |
topology |
View Topology | Display cluster replication topology |
version |
View Version | Display Patroni version info |
remove |
Remove Member | Remove cluster member from DCS (dangerous) |
Use edit-config to interactively edit cluster Patroni and PostgreSQL config. This opens an editor to modify config stored in DCS, automatically applying changes to all members. You can change Patroni params (ttl, loop_wait, synchronous_mode, etc.) and PostgreSQL params in postgresql.parameters.
demo/pgsql-config.cast — /demo/pgsql-config.cast
Common config modification examples:
Some params require PostgreSQL restart to take effect. Use pg list to check - instances marked with * need restart. Then use pg restart to apply.
You can also use curl or programs to call Patroni REST API:
Use list to view cluster members and status. Output shows each instance’s name, host, role, state, timeline, and replication lag. This is the most commonly used command for checking cluster health.
Example output:
Column descriptions: Member is instance name, composed of pg_cluster-pg_seq; Host is instance IP; Role is role type - Leader (primary), Replica, Sync Standby, Standby Leader (cascade primary); State is running state - running, streaming, in archive recovery, starting, stopped, etc.; TL is timeline number, incremented after each switchover; Lag in MB is replication lag in MB (not shown for primary).
Instances requiring restart show * after the name:
Use switchover for planned primary-replica switchover. Switchover is graceful: Patroni ensures replica is fully synced, demotes primary, then promotes target replica. Takes seconds with brief write unavailability. Use for primary host maintenance, upgrades, or migrating primary to better nodes.
Before switchover, ensure all replicas are healthy (running or streaming), replication lag is acceptable, and stakeholders are notified.
After switchover, use pg list to confirm new cluster topology.
Use failover for emergency failover. Unlike switchover, failover is for when primary is unavailable. It directly promotes a replica without waiting for original primary confirmation. Since replicas may not be fully synced, failover may cause minor data loss. Use switchover for non-emergency situations.
Failover examples:
Switchover vs Failover: Switchover is for planned maintenance, requires original primary online, ensures full sync before switching, no data loss; Failover is for emergency recovery, original primary can be offline, directly promotes replica, may lose unsynced data. Use Switchover for daily maintenance/upgrades; use Failover only when primary is completely down and unrecoverable.
The built-in Patroni
failoversubcommand currently has no--leaderoption. Use plannedswitchover --leader ...when you need to validate or name the old primary; failover accepts only the candidate replica.
Use restart to restart PostgreSQL instances, typically to apply restart-required parameter changes. When run against the whole cluster, patronictl submits each selected member in turn but does not guarantee a replica-first, leader-last order. If that order matters, restart replicas by role and then restart the leader separately.
After modifying restart-required params (shared_buffers, shared_preload_libraries, max_connections, max_worker_processes, etc.), use this command.
Use reload to reload Patroni config without restarting PostgreSQL. This re-reads config files and applies non-restart params via pg_reload_conf(). Lighter than restart - doesn’t interrupt connections or running queries.
Most PostgreSQL params work via reload. Only postmaster-context params (shared_buffers, max_connections, shared_preload_libraries, archive_mode, etc.) require restart.
Use reinit to reinitialize a replica. This deletes all data on the replica and rebuilds it according to Patroni’s create_replica_methods order. Pigsty tries basebackup (pg_basebackup) first by default; when a remote pgBackRest repository is enabled, pgbackrest is also configured as a fallback. Use this when replica data is corrupted, the replica is too far behind and required WAL has been removed, or replica configuration must be reset.
This operation deletes all data on the target instance. Run it only on a replica, never on the primary.
During rebuild, use pg list to check progress. Replica state shows creating replica:
Use pause to pause Patroni automatic failover. When paused, Patroni won’t auto-promote replicas even if primary fails. Use for planned maintenance windows (prevent accidental triggers), debugging (prevent cluster state changes), or manual switchover timing control.
While paused, the cluster will not recover automatically if the primary fails. Run resume after maintenance.
Use resume to resume Patroni automatic failover. Execute immediately after maintenance to ensure cluster auto-recovers on primary failure.
Use history to view cluster failover history. Each switchover (auto or manual) creates a new timeline record.
Column descriptions: TL is timeline number, incremented after each switchover, distinguishes primary histories; LSN is Log Sequence Number at switchover, marks WAL position; Reason is switchover reason - switchover to xxx (manual), failover to xxx (failure), or no recovery target specified (init); Timestamp is when switchover occurred.
Use show-config to view current cluster config stored in DCS. This is read-only; use edit-config to modify.
Use query to quickly execute SQL on cluster members. Convenient for debugging - for complex production queries, use psql or applications.
Use topology to view cluster replication topology as a tree. More intuitive than list for showing primary-replica relationships, especially for cascading replication.
In cascading replication, topology clearly shows replication hierarchy - e.g., pg-test-3 replicates from pg-test-2, which replicates from primary pg-test-1.
Use version to view patronictl version.
Use remove to remove cluster or member metadata from DCS. This is dangerous - only removes DCS metadata, doesn’t stop PostgreSQL or delete data files. Misuse may cause cluster state inconsistency.
Normally you don’t need this command. To properly remove clusters/instances, use Pigsty’s bin/pgsql-rm script or pgsql-rm.yml playbook.
Only consider remove for: orphaned DCS metadata (node physically removed but metadata remains), or cluster destroyed via other means requiring metadata cleanup.
Pigsty uses declarative management: first define HBA rules in the inventory, then use bin/pgsql-hba <cls> to refresh.
For rule syntax, see HBA Configuration. For authentication methods, default boundaries, and credential management, see Authentication.
| Action | Description | Risk |
|---|---|---|
| Refresh HBA Rules | Re-render config files and reload service | Low |
| Verify HBA Rules | View current rules, test connection auth | Read |
| Common Scenarios | Add rules, block IP, role-based, post-expansion | Low |
| Troubleshooting | Connection rejected, auth failed, rules not applied | - |
| Pgbouncer HBA | Pgbouncer connection pool HBA management | Low |
demo/pgsql-hba.cast — /demo/pgsql-hba.cast
After modifying HBA rules in pigsty.yml, re-render config files and reload services.
Result: Renders PostgreSQL and Pgbouncer HBA config files based on inventory definitions, then reloads services to apply.
Config file locations
| Service | Config File Path | Template File |
|---|---|---|
| PostgreSQL | /pg/data/pg_hba.conf |
roles/pgsql/templates/pg_hba.conf |
| Pgbouncer | /etc/pgbouncer/pgb_hba.conf |
roles/pgsql/templates/pgbouncer.hba |
Directly editing /pg/data/pg_hba.conf or /etc/pgbouncer/pgb_hba.conf works temporarily, but will be overwritten next time Ansible playbook runs. All HBA rule changes should be in pigsty.yml, then execute bin/pgsql-hba to refresh.
Related Tags
| Tag | Description |
|---|---|
pg_hba |
Render PostgreSQL HBA config file |
pg_reload |
Reload PostgreSQL config (needs pg_reload=true) |
pgbouncer_hba |
Render Pgbouncer HBA config file |
pgbouncer_reload |
Reload Pgbouncer config |
After refreshing HBA rules, verify config is correctly applied.
View current HBA rules
Check HBA config syntax
Add rule to cluster config’s pg_hba_rules, then refresh:
When detecting malicious IP, add high-priority (order: 0) deny rule:
Configure different HBA rules for primary and replica using role parameter:
After refresh, rules auto-enable/disable based on instance’s pg_role.
When cluster adds new instances, rules using addr: cluster need refresh to include new members:
After Patroni failover, instance pg_role may not match config. If HBA rules use role filtering, update config and refresh:
Symptom: FATAL: no pg_hba.conf entry for host "x.x.x.x", user "xxx", database "xxx"
Steps:
Confirm client IP, username, database matches any rule
Check rule order (HBA uses first-match-wins)
Add corresponding rule and refresh:
Symptom: FATAL: password authentication failed for user "xxx"
Steps:
pg_pwd_enc) compatibility with clientSteps:
HBA uses first-match-wins. If rules not working as expected:
order values in rule definitionspsql -c "TABLE pg_hba_file_rules" to view actual orderorder values (lower numbers = higher priority)Pgbouncer HBA management is similar to PostgreSQL, with some differences.
Config differences
| Difference | PostgreSQL | Pgbouncer |
|---|---|---|
| Config file | /pg/data/pg_hba.conf |
/etc/pgbouncer/pgb_hba.conf |
| Replication | Supports db: replication |
Not supported |
| Local auth | Uses ident |
Uses peer |
Refresh Pgbouncer HBA
pg_hba.conf directly - all changes through pigsty.ymlorder: 0 to ensure priority matchingaddr: world + auth: trustpg_stat_activitypigsty.yml before important changesPigsty uses Pgbouncer as PostgreSQL connection pooling middleware, listening on port 6432 by default, proxying access to local PostgreSQL on port 5432.
This is an optional component. If you don’t have massive connections or need transaction pooling and query metrics, you can disable it, connect directly to the database, or keep it unused.
Pgbouncer users and databases are auto-managed by Pigsty, applying database config and user config when creating databases and creating users.
Database Management: Databases defined in pg_databases are auto-added to Pgbouncer by default. Set pgbouncer: false to exclude specific databases.
User Management: Users defined in pg_users need explicit pgbouncer: true to be added to connection pool user list.
Since Pigsty
v4.1.0, database pool fields are unified aspool_reserveandpool_connlimit; legacy aliasespool_size_reserve/pool_max_db_connare converged.
In Pigsty, PostgreSQL cluster Primary Service and Replica Service default to Pgbouncer port 6432.
To bypass connection pool and access PostgreSQL directly, customize pg_services, or set pg_default_service_dest to postgres.
Pgbouncer config files are in /etc/pgbouncer/, generated and managed by Pigsty:
| File | Description |
|---|---|
pgbouncer.ini |
Main config, pool-level params |
database.txt |
Database list, database-level params |
userlist.txt |
User password list |
useropts.txt |
User-level pool params |
pgb_hba.conf |
HBA access control rules |
Pigsty auto-manages database.txt and userlist.txt, updating them when creating databases or creating users.
You can manually edit config then RELOAD to apply:
Pgbouncer runs as the same dbsu as PostgreSQL, default postgres OS user. Pigsty provides pgb alias for easy management:
Use pgb on database nodes to connect to Pgbouncer admin console for management commands and monitoring queries.
| Command | Function | Description |
|---|---|---|
PAUSE |
Pause | Pause database, wait for txn completion then disconnect |
RESUME |
Resume | Resume database paused by PAUSE/KILL/SUSPEND |
DISABLE |
Disable | Reject new client connections for database |
ENABLE |
Enable | Allow new client connections for database |
RECONNECT |
Reconnect | Gracefully close and rebuild server connections |
KILL |
Kill | Immediately disconnect all client and server connections |
KILL_CLIENT |
Kill Client | Terminate specific client connection |
SUSPEND |
Suspend | Flush buffers and stop listening, for online restart |
SHUTDOWN |
Shutdown | Shutdown Pgbouncer process |
RELOAD |
Reload | Reload config files |
WAIT_CLOSE |
Wait Close | Wait for server connections to close after RECONNECT/RELOAD |
| Monitor Commands | Monitor | View pool status, clients, servers, etc. |
Use PAUSE to pause database connections. Pgbouncer waits for active txn/session to complete based on pool mode, then disconnects server connections. New client requests are blocked until RESUME.
Typical use cases:
SUSPEND for Pgbouncer online restartAfter pause, SHOW DATABASES shows paused status:
Use RESUME to restore databases paused by PAUSE, KILL, or SUSPEND, allowing new connections and resuming normal service.
Use DISABLE to disable a database, rejecting all new client connection requests. Existing connections are unaffected.
Typical use cases:
Use ENABLE to enable a database previously disabled by DISABLE, accepting new client connections again.
Use RECONNECT to gracefully rebuild server connections. Pgbouncer closes connections when released back to pool, creating new ones when needed.
Typical use cases:
After RECONNECT, use WAIT_CLOSE to wait for old connections to fully release.
Use KILL to immediately disconnect all client and server connections for a database. Unlike PAUSE, KILL doesn’t wait for transaction completion - forces immediate disconnect.
After KILL, new connections are blocked until RESUME.
Use KILL_CLIENT to terminate a specific client connection. Client ID can be obtained from SHOW CLIENTS output.
Use SUSPEND to suspend Pgbouncer. Flushes all socket buffers and stops listening until RESUME.
SUSPEND is mainly for Pgbouncer online restart (zero-downtime upgrade):
Use SHUTDOWN to shut down Pgbouncer process. Multiple shutdown modes supported:
| Mode | Description |
|---|---|
SHUTDOWN |
Immediately shutdown Pgbouncer |
WAIT_FOR_SERVERS |
Stop accepting new connections, wait for server release |
WAIT_FOR_CLIENTS |
Stop accepting new connections, wait for all clients disconnect, for rolling restart |
Use RELOAD to reload Pgbouncer config files. Dynamically updates most config params without process restart.
Pigsty provides playbook task to reload Pgbouncer config:
Use WAIT_CLOSE to wait for server connections to finish closing. Typically used after RECONNECT or RELOAD to ensure old connections are fully released.
Pgbouncer provides rich SHOW commands for monitoring pool status:
| Command | Description |
|---|---|
SHOW HELP |
Show available commands |
SHOW DATABASES |
Show database config and status |
SHOW POOLS |
Show pool statistics |
SHOW CLIENTS |
Show client connection list |
SHOW SERVERS |
Show server connection list |
SHOW USERS |
Show user config |
SHOW STATS |
Show statistics (requests, bytes) |
SHOW STATS_TOTALS |
Show cumulative statistics |
SHOW STATS_AVERAGES |
Show average statistics |
SHOW CONFIG |
Show current config params |
SHOW MEM |
Show memory usage |
SHOW DNS_HOSTS |
Show DNS cached hostnames |
SHOW DNS_ZONES |
Show DNS cached zones |
SHOW SOCKETS |
Show open socket info |
SHOW ACTIVE_SOCKETS |
Show active sockets |
SHOW LISTS |
Show internal list counts |
SHOW FDS |
Show file descriptor usage |
SHOW STATE |
Show Pgbouncer running state |
SHOW VERSION |
Show Pgbouncer version |
Common monitoring examples:
For more monitoring command details, see Pgbouncer official docs.
Pgbouncer supports Unix signal control, useful when admin console is unavailable:
| Signal | Equivalent Command | Description |
|---|---|---|
SIGHUP |
RELOAD |
Reload config files |
SIGTERM |
SHUTDOWN WAIT_FOR_CLIENTS |
Graceful shutdown, wait clients |
SIGINT |
SHUTDOWN WAIT_FOR_SERVERS |
Graceful shutdown, wait servers |
SIGQUIT |
SHUTDOWN |
Immediate shutdown |
SIGUSR1 |
PAUSE |
Pause all databases |
SIGUSR2 |
RESUME |
Resume all databases |
Pigsty-managed database routes live in /etc/pgbouncer/database.txt. To move one database’s Pgbouncer traffic to another node, edit that file, reload the configuration, then drain and rebuild existing server connections:
The
pgb-routefunction currently shipped in the source only edits/etc/pgbouncer/pgbouncer.ini. That file merely includesdatabase.txtand does not contain the generated per-databasehost=routes, so the function does not change managed database backends. Do not use it in place of the procedure above.
Pigsty’s PGSQL module consists of multiple components, each running as a systemd service on nodes. (pgbackrest is an exception)
Understanding these components and their management is essential for maintaining production PostgreSQL clusters.
| Component | Port | Service Name | Description |
|---|---|---|---|
| Patroni | 8008 |
patroni |
HA manager, manages PostgreSQL lifecycle |
| PostgreSQL | 5432 |
postgres |
Placeholder service, not used, for emergency |
| Pgbouncer | 6432 |
pgbouncer |
Connection pooling middleware, traffic entry |
| PgBackRest | - | - | pgBackRest has no daemon service |
| HAProxy | 543x |
haproxy |
Load balancer, exposes database services |
| pg_exporter | 9630 |
pg_exporter |
PostgreSQL metrics exporter |
| pgbouncer_exporter | 9631 |
pgbouncer_exporter |
Pgbouncer metrics exporter |
| vip-manager | - | vip-manager |
Optional, manages L2 VIP address floating |
Do NOT use systemctl directly to manage PostgreSQL service. PostgreSQL is managed by Patroni - use patronictl commands instead.
Direct PostgreSQL operations may cause Patroni state inconsistency and trigger unexpected failover. The postgres service is an emergency escape hatch when Patroni fails.
| Operation | Command |
|---|---|
| Start | systemctl start <service> |
| Stop | systemctl stop <service> |
| Restart | systemctl restart <service> |
| Reload | systemctl reload <service> |
| Status | systemctl status <service> |
| Logs | journalctl -u <service> -f |
| Enable | systemctl enable <service> |
| Disable | systemctl disable <service> |
Common service names: patroni, pgbouncer, haproxy, pg_exporter, pgbouncer_exporter, vip-manager
Patroni is PostgreSQL’s HA manager, handling startup, shutdown, failure detection, and automatic failover. It’s the core PGSQL module component. PostgreSQL process is managed by Patroni - don’t use systemctl to manage postgres service directly.
Start Patroni
After starting, Patroni auto-launches PostgreSQL. On first start, behavior depends on role:
Stop Patroni
Stopping Patroni gracefully shuts down PostgreSQL. Note: If this is primary and auto-failover isn’t paused, may trigger failover.
Restart Patroni
Restart causes brief service interruption. For production, use pg restart for rolling restart.
Reload Patroni
Reload re-reads config file and applies hot-reloadable params to PostgreSQL.
View Status & Logs
Config file: /etc/patroni/patroni.yml
Best Practice: Use
patronictlinstead of systemctl to manage PostgreSQL clusters.
Pgbouncer is a lightweight PostgreSQL connection pooling middleware. Business traffic typically goes through Pgbouncer (6432) rather than directly to PostgreSQL (5432) for connection reuse and database protection.
Start Pgbouncer
Stop Pgbouncer
Note: Stopping Pgbouncer disconnects all pooled business connections.
Restart Pgbouncer
Restart disconnects all existing connections. For config changes only, use reload.
Reload Pgbouncer
Reload re-reads config files (user list, pool params, etc.) without disconnecting existing connections.
View Status & Logs
Config files:
/etc/pgbouncer/pgbouncer.ini/etc/pgbouncer/pgb_hba.conf/etc/pgbouncer/userlist.txt/etc/pgbouncer/database.txtAdmin Console
Common admin commands:
HAProxy is a high-performance load balancer that routes traffic to correct PostgreSQL instances. Pigsty uses HAProxy to expose services, routing traffic based on role (primary/replica) and health status.
Start HAProxy
Stop HAProxy
Note: Stopping HAProxy disconnects all load-balanced connections.
Restart HAProxy
Reload HAProxy
HAProxy supports graceful reload without disconnecting existing connections. Use reload for config changes.
View Status & Logs
Config files: the main configuration is /etc/haproxy/haproxy.cfg; Pigsty-generated service fragments are stored under /etc/haproxy/conf.d/.
Admin Interface
HAProxy provides a web admin interface, default port 9101:
Default auth: username admin, password configured by haproxy_admin_password.
pg_exporter is PostgreSQL’s Prometheus metrics exporter for collecting database performance metrics.
Start pg_exporter
Stop pg_exporter
After stopping, Prometheus can’t collect PostgreSQL metrics from this instance.
Restart pg_exporter
View Status & Logs
Config file: /etc/pg_exporter.yml
Verify Metrics
pgbouncer_exporter is Pgbouncer’s Prometheus metrics exporter.
Start/Stop/Restart
View Status & Logs
Verify Metrics
vip-manager is an optional component for managing L2 VIP address floating.
When pg_vip_enabled is enabled, vip-manager binds VIP to current primary node.
Start vip-manager
Stop vip-manager
After stopping, VIP address is released from current node.
Restart vip-manager
View Status & Logs
Config file: /etc/default/vip-manager
Verify VIP Binding
Recommended PGSQL module component startup order:
Stop order should be reversed. Pigsty playbooks handle these dependencies automatically.
Batch Start All Services
Batch Stop All Services
Service Startup Failure
Patroni Won’t Start
| Symptom | Possible Cause | Solution |
|---|---|---|
| Can’t connect to etcd | etcd cluster unavailable | Check etcd service status |
| Data dir permission error | File ownership not postgres | chown -R postgres:postgres /pg/data |
| Port in use | Leftover PostgreSQL process | pg_ctl stop -D /pg/data or kill |
Pgbouncer Won’t Start
| Symptom | Possible Cause | Solution |
|---|---|---|
| Config syntax error | INI format error | Check /etc/pgbouncer/pgbouncer.ini |
| Port in use | Port 6432 already used | lsof -i :6432 |
| userlist.txt permissions | Incorrect file permissions | chmod 600 /etc/pgbouncer/userlist.txt |
HAProxy Won’t Start
| Symptom | Possible Cause | Solution |
|---|---|---|
| Config syntax error | Invalid main configuration or service fragment | haproxy -Ws -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/conf.d -c -q |
| Port in use | Service port conflict | lsof -i :5433 |
Pigsty uses crontab to manage scheduled tasks for routine backups, freezing aging transactions, and reorganizing bloated tables and indexes.
| Operation | Quick Command | Description |
|---|---|---|
| Configure Cron Jobs | ./pgsql.yml -t pg_crontab -l <cls> |
Apply pg_crontab config |
| View Cron Jobs | crontab -l |
View as postgres user |
| Physical Backup | pg-backup [full|diff|incr] |
Execute backup with pgBackRest |
| Transaction Freeze | pg-vacuum [database...] |
Freeze aging transactions, prevent XID wraparound |
| Bloat Maintenance | pg-repack [database...] |
Online reorganize bloated tables and indexes |
For other management tasks, see: Backup Management, Monitoring System, HA Management.
Use the pg_crontab parameter to configure cron jobs for the PostgreSQL database superuser (pg_dbsu, default postgres).
Example Configuration
The following pg-meta cluster configures a daily full backup at 1:00 AM, while pg-test configures weekly full backup on Monday with incremental backups on other days.
Recommended Maintenance Schedule
| Task | Frequency | Timing | Description |
|---|---|---|---|
pg-backup |
Daily | Early morning | Full or incremental backup, depending on business needs |
pg-vacuum |
Weekly | Sunday early morning | Freeze aging transactions, prevent XID wraparound |
pg-repack |
Weekly/Monthly | Off-peak hours | Reorganize bloated tables/indexes, reclaim space |
The pg-backup, pg-vacuum, and pg-repack scripts automatically detect the current node role. Only the primary will actually execute; replicas will exit directly. Therefore, you can safely configure the same cron jobs on all nodes, and after failover, the new primary will automatically continue executing maintenance tasks.
Cron jobs are automatically written to the default location for the corresponding OS distribution when the pgsql.yml playbook executes (the pg_crontab task):
/var/spool/cron/postgres/var/spool/cron/crontabs/postgresEach playbook execution will fully overwrite the cron job configuration.
Execute the following command as the pg_dbsu OS user to view cron jobs:
If you’re not familiar with crontab syntax, refer to Crontab Guru for explanations.
pg-backup is Pigsty’s physical backup script based on pgBackRest, supporting full, differential, and incremental backup modes.
Basic Usage
Backup Types
| Type | Parameter | Description |
|---|---|---|
| Full Backup | full |
Complete backup of all data, only this backup needed for recovery |
| Differential | diff |
Backup changes since last full backup, recovery needs full + diff |
| Incremental | incr |
Backup changes since last any backup, recovery needs complete chain |
Execution Requirements
/etc/pgbackrest/pgbackrest.confCommon Cron Configurations
For more backup and recovery operations, see the Backup Management section.
pg-vacuum is Pigsty’s transaction freeze script for executing VACUUM FREEZE operations to prevent database shutdown from transaction ID (XID) wraparound.
Basic Usage
Command Options
| Option | Description | Default |
|---|---|---|
-h, --help |
Show help message | - |
-n, --dry-run |
Dry run mode, display only | false |
-a, --age |
Age threshold, tables exceeding need freeze | 100000000 |
-r, --ratio |
Aging ratio threshold, full freeze if exceeded (%) | 40 |
Logic
datfrozenxid age, skip database if below thresholdVACUUM FREEZE ANALYZEVACUUM FREEZE ANALYZE on tables exceeding age thresholdScript sets vacuum_cost_limit = 10000 and vacuum_cost_delay = 1ms to control I/O impact.
Execution Requirements
/tmp/pg-vacuum.lock to prevent concurrent executiontemplate0, template1, postgres system databasesCommon Cron Configuration
pg-repack is Pigsty’s bloat maintenance script based on the pg_repack extension for online reorganization of bloated tables and indexes.
Basic Usage
Command Options
| Option | Description | Default |
|---|---|---|
-h, --help |
Show help message | - |
-n, --dry-run |
Dry run mode, display only | false |
-t, --table |
Reorganize tables only | false |
-i, --index |
Reorganize indexes only | false |
-T, --timeout |
Lock wait timeout (seconds) | 10 |
-j, --jobs |
Parallel jobs | 2 |
Auto-Selection Thresholds
Script auto-selects objects to reorganize based on table/index size and bloat ratio:
Table Bloat Thresholds
| Size Range | Bloat Threshold | Max Count |
|---|---|---|
| < 256MB | > 40% | 64 |
| 256MB - 2GB | > 30% | 16 |
| 2GB - 8GB | > 20% | 4 |
| 8GB - 64GB | > 15% | 1 |
Index Bloat Thresholds
| Size Range | Bloat Threshold | Max Count |
|---|---|---|
| < 128MB | > 40% | 64 |
| 128MB - 1GB | > 35% | 16 |
| 1GB - 8GB | > 30% | 4 |
| 8GB - 64GB | > 20% | 1 |
Tables/indexes over 64GB are skipped with a warning and require manual handling.
Execution Requirements
pg_repack extension installed (installed by default in Pigsty)pg_table_bloat and pg_index_bloat views in monitor schema/tmp/pg-repack.lock to prevent concurrent executiontemplate0, template1, postgres system databasesNormal reads/writes are not affected during reorganization, but the final switch moment requires acquiring AccessExclusive lock on the table, blocking all access. For high-throughput workloads, recommend running during off-peak hours or maintenance windows.
Common Cron Configuration
You can confirm database bloat through Pigsty’s PGCAT Database - Table Bloat panel and select high-bloat tables and indexes for reorganization.
For more details see: Managing Relation Bloat
When using the pgsql-rm.yml playbook to remove a PostgreSQL cluster, it automatically deletes the postgres user’s crontab file.
Pigsty provides 575 extensions. Using extensions involves four steps: Download, Install, Configure, Enable.
For complete extension reference, see Extensions. For available extensions, see Extension Catalog.
| Action | Command | Description |
|---|---|---|
| Download Extensions | ./infra.yml -t repo_build |
Download extensions to local repo |
| Install Extensions | bin/pgsql-ext <cls> |
Install extension packages on cluster |
| Configure Extensions | pg edit-config <cls> -p |
Add to preload libs (requires restart) |
| Enable Extensions | psql -c 'CREATE EXT ...' |
Create extension objects in database |
| Update Extensions | ALTER EXTENSION UPDATE |
Update packages and extension objects |
| Remove Extensions | DROP EXTENSION |
Drop extension objects, uninstall pkgs |
demo/pgsql-ext.cast — /demo/pgsql-ext.cast
Extensions defined in pg_extensions are auto-installed during PostgreSQL cluster creation in the pg_extension task.
To install extensions on an existing cluster, add extensions to all.children.<cls>.pg_extensions, then execute:
Example: Install PostGIS, TimescaleDB and PGVector on cluster
Result: Installs extension packages on all cluster nodes. Pigsty auto-translates package aliases to actual package names for OS and PG version.
Before installing, ensure nodes have correct repos configured - extensions downloaded to local repo, or upstream repos configured.
If you don’t want to use Pigsty config to manage extensions, pass extension list directly on command line:
You can also use pig package manager CLI to install extensions on single node, with auto package alias resolution.
You can also use OS package manager directly (apt/dnf), but you must know the exact RPM/DEB package name for your OS/PG:
To install extensions, ensure node’s extension repos contain the extension:
repo_packages / repo_extra_packages when creating local repo, it’s already downloaded. Otherwise download first or configure upstream repos for online install.Pigsty’s default config auto-downloads mainstream extensions during installation. For additional extensions, add to repo_extra_packages and rebuild repo:
You can also let all nodes use upstream repos directly (not recommended for production), skipping download and installing from upstream extension repos:
Some extensions require preloading to shared_preload_libraries, requiring database restart after modification.
Use pg_libs as its default value to configure preload extensions, but this only takes effect during cluster init - later modifications are ineffective.
For existing clusters, refer to Modify Config to modify shared_preload_libraries:
Ensure extension packages are correctly installed before adding preload config. If extension in shared_preload_libraries doesn’t exist or fails to load, PostgreSQL won’t start.
Also, manage cluster config changes through Patroni - avoid using ALTER SYSTEM or pg_parameters to modify instance config separately.
If primary and replica configs differ, it may cause startup failure or replication interruption.
After installing packages, execute CREATE EXTENSION in database to use extension features.
Enable during cluster init
Declare extensions to enable in database definition via extensions array:
Manual enable
Result: Creates extension objects (functions, types, operators, index methods, etc.) in database, enabling use of extension features.
Extension updates involve two layers: package update and extension object update.
Update packages
Update extension objects
Backup database before updating extensions. Preloaded extensions may require PostgreSQL restart after update. Some extension version upgrades may be incompatible - check extension docs.
Removing extensions involves two layers: drop extension objects and uninstall packages.
Drop extension objects
Remove from preload
For preloaded extensions, remove from shared_preload_libraries and restart:
Uninstall packages (optional)
Using CASCADE to drop extensions also drops all objects depending on that extension (tables, indexes, views, etc.). Check dependencies before executing.
Common SQL queries for extension info:
View enabled extensions
View available extensions
Check if extension is available
View extension dependencies
View extension objects
psql shortcuts
To install directly from upstream, manually add repos.
Using Pigsty playbook
YUM repos (EL systems)
APT repos (Debian/Ubuntu)
Difference between extension name and package name
| Name | Description | Example |
|---|---|---|
| Extension name | Name used with CREATE EXTENSION |
vector |
| Package alias | Standardized name in Pigsty config | pgvector |
| Package name | Actual OS package name | pgvector_18* or postgresql-18-pgvector |
Preloaded extension prevents startup
If extension in shared_preload_libraries doesn’t exist or fails to load, PostgreSQL won’t start. Solutions:
shared_preload_libraries (edit /pg/data/postgresql.conf)Extension dependencies
Some extensions depend on others, requiring sequential creation or using CASCADE:
Extension version incompatibility
View extension versions supported by current PostgreSQL:
PostgreSQL version upgrades fall into two types: minor version upgrade and major version upgrade, with very different risk and complexity.
| Type | Example | Downtime | Data Compatibility | Risk |
|---|---|---|---|---|
| Minor upgrade | 17.2 → 17.3 | Seconds (rolling) | Fully compatible | Low |
| Major upgrade | 17 → 18 | Minutes | Requires data dir upgrade | Medium |
For detailed online migration process, see Online Migration documentation.
| Action | Description | Risk |
|---|---|---|
| Minor Version Upgrade | Update packages, rolling restart | Low |
| Minor Version Downgrade | Rollback to previous minor version | Low |
| Major Version Upgrade | Logical replication or pg_upgrade | Medium |
| Extension Upgrade | Upgrade extension packages and objects | Low |
Minor version upgrades (e.g., 17.2 → 17.3) are the most common upgrade scenario, typically for security patches and bug fixes. Data directory is fully compatible, completed via rolling restart.
Strategy: Recommended rolling upgrade: upgrade replicas first, then switchover to upgrade original primary - minimizes service interruption.
Step 1: Prepare packages
Ensure local repo has latest PostgreSQL packages and refresh node cache:
Step 2: Upgrade replicas
Upgrade packages on all replicas and verify version:
Restart all replicas to apply new version:
Step 3: Switchover
Execute switchover to transfer primary role to upgraded replica:
Step 4: Upgrade original primary
Original primary is now replica - upgrade packages and restart:
Step 5: Verify
Confirm all instances have consistent version:
In rare cases (e.g., new version introduces bugs), may need to downgrade PostgreSQL to previous version.
Step 1: Get old version packages
Step 2: Execute downgrade
Step 3: Restart cluster
Major version upgrades (e.g., 17 → 18) involve data format changes, requiring specialized tools for data migration.
| Method | Downtime | Complexity | Use Case |
|---|---|---|---|
| Logical Replication Migration | Seconds (switch) | High | Production, minimal downtime required |
| pg_upgrade In-Place Upgrade | Minutes~Hours | Medium | Test env, smaller data |
For production, we recommend logical replication migration: create new version cluster, sync data via logical replication, then blue-green switch. Shortest downtime and rollback-ready. See Online Migration.
Logical replication is the recommended approach for production major version upgrades. Core steps:
Step 1: Create new version cluster
Step 2: Configure logical replication
Step 3: Wait for sync completion
Step 4: Switch traffic
After confirming data sync complete: stop app writes to source → wait for final sync → switch app connections to new cluster → drop subscription, decommission source.
For detailed migration process, see Online Migration documentation.
pg_upgrade is PostgreSQL’s official major version upgrade tool, suitable for test environments or scenarios accepting longer downtime.
In-place upgrade causes longer downtime and is difficult to rollback. For production, prefer logical replication migration.
Step 1: Install new version packages
Step 2: Stop Patroni
Step 3: Run pg_upgrade
Step 4: Update links and start
Step 5: Post-processing
When upgrading PostgreSQL version, typically also need to upgrade related extensions.
Upgrade extension packages
Upgrade extension objects
After package upgrade, execute extension upgrade in database:
Before major version upgrade, confirm all extensions support target PostgreSQL version. Some extensions may require uninstall/reinstall - check extension documentation.
Pigsty uses pgBackRest for PostgreSQL backups. It supports full, differential, and incremental backups, parallel processing, encryption, and Silo/S3 object storage. Every PGSQL cluster is configured for backup and WAL archiving by default.
This chapter is the operational manual for backup configuration, management, recovery, and drills. For design concepts and tradeoffs, see Point-in-Time Recovery.
All backup and recovery operations ultimately invoke pgBackRest. Pigsty provides several wrapper layers:
| Layer | Interface | Form | Scope |
|---|---|---|---|
| Cluster orchestration | pg_pitr + pgsql-pitr.yml |
Ansible playbook | HA, etcd, and multi-node recovery |
| Instance orchestration | pig pitr |
CLI | Local-node recovery without the admin node |
| Command primitives | pig pb, pb, and pg-backup |
pgBackRest wrappers | Backup, inspection, expiry, and unmanaged restore |
| Engine | pgbackrest |
Native CLI | Underlying backup, archive, and restore engine |
| Section | Content |
|---|---|
| Mechanism | Stanzas, repositories, retention, timelines, and Pigsty wrapper mapping |
| Policy | Scheduling, recovery windows, and storage planning |
| Repository | Local, Silo, and external S3 repositories; encryption, versioning, and locking |
| Administration | Backup commands, inspection, expiration, and stanza management |
| Restore | Recovery targets, staged PITR, and complete parameter reference |
| Clone | Restore production history into another cluster and perform drills |
| Tutorial | A sandbox restore using pgBackRest primitives |
Pigsty makes every effort to provide a reliable PITR solution, but accepts no liability for data loss caused by restore operations. If you need assistance, consider professional services.
Before PITR, inspect pig pg list <target-cluster> and pig pb info, verify a recent usable backup and recovery window,
have the operator state the exact target cluster and recovery point, then run the target-scoped ./pgsql-pitr.yml -l <target-cluster> ... command.
pgsql-pitr.yml prints a plan but does not pause for approval. Production recovery also requires a maintenance window and an independently verified backup.
pg_crontab and select a repository with pgbackrest_repo.pg-backup and inspect recovery coverage with pb info.pg_pitr, then run pgsql-pitr.yml.The chart below combines the “Recovery Window” and “Backup Storage Usage” on a single timeline (0~108h) so they can be inspected together.
Under the same assumptions (database size 100GB, daily writes 10GB), it shows how both metrics evolve over 30 days with “weekly full + daily incremental” backups and 14-day full-backup retention.
The first question is when to backup your database - this is a tradeoff between backup frequency and recovery time. Since you need to replay WAL logs from the last backup to the recovery target point, the more frequent the backups, the less WAL logs need to be replayed, and the faster the recovery.
For production databases, it’s recommended to start with the simplest daily full backup strategy. This is also Pigsty’s default backup strategy, implemented via crontab.
Assume your database size is 100GB, daily writes are 10GB, and each full backup takes 1 hour. Under this daily-full local-repo strategy, recovery window and backup storage evolve as shown below:
The recovery window cycles between 25-49 hours, and storage usage is roughly 2 full backups plus around 2 days of WAL archives.
In practice, prepare at least 3~5 times the base database size as backup disk capacity for the default policy.
tooltip: { trigger: axis, formatter: $fn:tipMerged, axisPointer: { type: line, snap: true, label: { show: false } } }
axisPointer: { link: [ { xAxisIndex: [0, 1] } ] }
legend: { show: false, bottom: 10, itemGap: 18, data: ["Primary Backup", "Secondary Backup", "WAL Archive", "Transient Backup"] }
grid:
- { left: 82, right: "10%", top: 42, height: 218, containLabel: false }
- { left: 82, right: "10%", top: 286, height: 218, containLabel: false }
xAxis:
- type: category
gridIndex: 0
position: bottom
boundaryGap: false
data: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108]
name: Time h
nameLocation: end
nameGap: 10
nameTextStyle: { align: left, verticalAlign: top, padding: [8, 0, 0, 0] }
axisLabel: { interval: 11, formatter: $fn:fmtHour }
axisLine: { show: true, symbol: [none, arrow], symbolSize: [10, 14], lineStyle: { width: 1.6, color: "#4b5563" } }
axisTick: { show: true, length: 6 }
splitLine: { show: true, lineStyle: { type: dashed, width: 1, opacity: 0.28, color: "#9ca3af" } }
minorTick: { show: true, splitNumber: 12, length: 3 }
minorSplitLine: { show: true, lineStyle: { type: dotted, width: 1, opacity: 0.14, color: "#9ca3af" } }
- type: category
gridIndex: 1
position: top
boundaryGap: true
data: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108]
axisLabel: { show: false }
axisLine: { show: true, lineStyle: { width: 1.6, color: "#4b5563" } }
axisTick: { show: true, length: 6 }
splitLine: { show: true, lineStyle: { type: dashed, width: 1, opacity: 0.22, color: "#9ca3af" } }
yAxis:
- type: value
gridIndex: 0
min: 0
max: 52
interval: 5
name: Recovery Window h
nameLocation: end
nameRotate: 0
nameGap: 8
nameTextStyle: { align: left, verticalAlign: bottom, padding: [0, 0, 8, 4] }
axisLabel: { formatter: $fn:fmtWin }
axisLine: { show: true, symbol: [none, arrow], symbolSize: [10, 14], lineStyle: { width: 1.6, color: "#4b5563" } }
axisTick: { show: true, length: 6 }
splitLine: { show: true, lineStyle: { type: dashed, width: 1, opacity: 0.35, color: "#9ca3af" } }
minorTick: { show: true, splitNumber: 5, length: 3 }
minorSplitLine: { show: true, lineStyle: { type: dotted, width: 1, opacity: 0.18, color: "#9ca3af" } }
- type: value
gridIndex: 1
min: 0
max: 350
interval: 50
inverse: true
name: Backup Storage GB
nameLocation: end
nameRotate: 0
nameGap: 8
nameTextStyle: { align: left, verticalAlign: top, padding: [10, 0, 0, 4] }
axisLabel: { formatter: $fn:fmtGbTick }
axisLine: { show: true, symbol: [arrow, none], symbolSize: [10, 14], lineStyle: { width: 1.6, color: "#4b5563" } }
axisTick: { show: true, length: 6 }
splitLine: { show: true, lineStyle: { type: dashed, width: 1, opacity: 0.32, color: "#9ca3af" } }
series: [ { name: Recovery Window, type: line, smooth: false, symbol: none, showSymbol: false, xAxisIndex: 0, yAxisIndex: 0, lineStyle: { width: 3, color: "#f2a000" }, itemStyle: { color: "#f2a000" }, data: [[0,0],[1,0],[1,1],[2,2],[3,3],[4,4],[5,5],[6,6],[7,7],[8,8],[9,9],[10,10],[11,11],[12,12],[13,13],[14,14],[15,15],[16,16],[17,17],[18,18],[19,19],[20,20],[21,21],[22,22],[23,23],[24,24],[25,25],[26,26],[27,27],[28,28],[29,29],[30,30],[31,31],[32,32],[33,33],[34,34],[35,35],[36,36],[37,37],[38,38],[39,39],[40,40],[41,41],[42,42],[43,43],[44,44],[45,45],[46,46],[47,47],[48,48],[49,49],[49,25],[50,26],[51,27],[52,28],[53,29],[54,30],[55,31],[56,32],[57,33],[58,34],[59,35],[60,36],[61,37],[62,38],[63,39],[64,40],[65,41],[66,42],[67,43],[68,44],[69,45],[70,46],[71,47],[72,48],[73,49],[73,25],[74,26],[75,27],[76,28],[77,29],[78,30],[79,31],[80,32],[81,33],[82,34],[83,35],[84,36],[85,37],[86,38],[87,39],[88,40],[89,41],[90,42],[91,43],[92,44],[93,45],[94,46],[95,47],[96,48],[97,49],[97,25],[98,26],[99,27],[100,28],[101,29],[102,30],[103,31],[104,32],[105,33],[106,34],[107,35],[108,36]], markLine: { symbol: none, label: { show: false }, data: [ { xAxis: 0, lineStyle: { color: "#59a14f", type: "solid", width: 1.4, opacity: 0.75 } }, { xAxis: 24, lineStyle: { color: "#59a14f", type: "solid", width: 1.4, opacity: 0.75 } }, { xAxis: 48, lineStyle: { color: "#59a14f", type: "solid", width: 1.4, opacity: 0.75 } }, { xAxis: 72, lineStyle: { color: "#59a14f", type: "solid", width: 1.4, opacity: 0.75 } }, { xAxis: 96, lineStyle: { color: "#59a14f", type: "solid", width: 1.4, opacity: 0.75 } }, { xAxis: 1, lineStyle: { color: "#336791", type: "solid", width: 1.4, opacity: 0.8 } }, { xAxis: 25, lineStyle: { color: "#336791", type: "solid", width: 1.4, opacity: 0.8 } }, { xAxis: 49, lineStyle: { color: "#336791", type: "solid", width: 1.4, opacity: 0.8 } }, { xAxis: 73, lineStyle: { color: "#336791", type: "solid", width: 1.4, opacity: 0.8 } }, { xAxis: 97, lineStyle: { color: "#336791", type: "solid", width: 1.4, opacity: 0.8 } }, { yAxis: 25, label: { show: true, formatter: "lower 25h", position: "end", distance: 12, color: "#2563eb" }, lineStyle: { color: "#2563eb", type: "dashdot", width: 1.4, opacity: 0.75 } }, { yAxis: 49, label: { show: true, formatter: "upper 49h", position: "end", distance: 12, color: "#7c3aed" }, lineStyle: { color: "#7c3aed", type: "dashdot", width: 1.4, opacity: 0.75 } } ] } }, { name: Primary Backup, type: bar, stack: used, xAxisIndex: 1, yAxisIndex: 1, barWidth: 5, itemStyle: { color: "#59a14f" }, data: [0,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100] }, { name: Secondary Backup, type: bar, stack: used, xAxisIndex: 1, yAxisIndex: 1, barWidth: 5, itemStyle: { color: "#4e79a7" }, data: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100] }, { name: WAL Archive, type: bar, stack: used, xAxisIndex: 1, yAxisIndex: 1, barWidth: 5, itemStyle: { color: "#edc949" }, data: [0,0,0.42,0.83,1.25,1.67,2.08,2.5,2.92,3.33,3.75,4.17,4.58,5,5.42,5.83,6.25,6.67,7.08,7.5,7.92,8.33,8.75,9.17,9.58,10,10.42,10.83,11.25,11.67,12.08,12.5,12.92,13.33,13.75,14.17,14.58,15,15.42,15.83,16.25,16.67,17.08,17.5,17.92,18.33,18.75,19.17,19.58,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20] }, { name: Transient Backup, type: bar, stack: used, xAxisIndex: 1, yAxisIndex: 1, barWidth: 5, itemStyle: { color: "#9ca3af", opacity: 0.75 }, data: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,100,0,0,0,0,0,0,0,0,0,0,0,0] } ]You can optimize backup space usage by adjusting these parameters.
If using Silo / S3 as a centralized backup repository, storage is no longer limited by the local disk. In this case, consider using full + incremental backup with a 2-week retention policy:
With weekly full backups and time-based retention of 14 days, the steady-state recovery window is roughly 14–21 days. The exact window still depends on successful backup and WAL archival runs.
Assuming your database size is 100GB and writes 10GB of data per day, the backup size is as follows:
tooltip: { trigger: axis, formatter: $fn:tipMerged30, axisPointer: { type: line, snap: true, label: { show: false } } }
axisPointer: { link: [ { xAxisIndex: [0, 1] } ] }
legend: { show: false, bottom: 10, itemGap: 18, data: ["Primary Backup", "Secondary Backup", "Incremental Backup", "WAL Archive", "Transient Backup"] }
grid:
- { left: 82, right: "10%", top: 42, height: 218, containLabel: false }
- { left: 82, right: "10%", top: 302, height: 218, containLabel: false }
xAxis:
- type: value
gridIndex: 0
position: bottom
boundaryGap: false
min: 0
max: 31
interval: 1
name: Time
nameLocation: end
nameGap: 10
nameTextStyle: { align: left, verticalAlign: top, padding: [8, 0, 0, 0] }
axisLabel: { formatter: $fn:fmtDay30 }
axisLine: { show: true, symbol: [none, arrow], symbolSize: [10, 14], lineStyle: { width: 1.6, color: "#4b5563" } }
axisTick: { show: true, length: 6 }
splitLine: { show: true, lineStyle: { type: dashed, width: 1, opacity: 0.28, color: "#9ca3af" } }
minorTick: { show: true, splitNumber: 4, length: 3 }
minorSplitLine: { show: true, lineStyle: { type: dotted, width: 1, opacity: 0.14, color: "#9ca3af" } }
- type: category
gridIndex: 1
position: top
boundaryGap: true
z: 10
data: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]
axisLabel: { show: false }
axisLine: { show: true, lineStyle: { width: 1.6, color: "#4b5563" } }
axisTick: { show: true, alignWithLabel: true, length: 6 }
splitLine: { show: true, lineStyle: { type: dashed, width: 1, opacity: 0.22, color: "#9ca3af" } }
yAxis:
- type: value
gridIndex: 0
min: 0
max: 360
interval: 48
name: Recovery Window h
nameLocation: end
nameRotate: 0
nameGap: 8
nameTextStyle: { align: left, verticalAlign: bottom, padding: [0, 0, 8, 4] }
axisLabel: { formatter: $fn:fmtWin30 }
axisLine: { show: true, symbol: [none, arrow], symbolSize: [10, 14], lineStyle: { width: 1.6, color: "#4b5563" } }
axisTick: { show: true, length: 6 }
splitLine: { show: true, lineStyle: { type: dashed, width: 1, opacity: 0.35, color: "#9ca3af" } }
minorTick: { show: true, splitNumber: 4, length: 3 }
minorSplitLine: { show: true, lineStyle: { type: dotted, width: 1, opacity: 0.18, color: "#9ca3af" } }
- type: value
gridIndex: 1
min: 0
max: 600
interval: 50
inverse: true
z: 10
name: Storage GB
nameLocation: end
nameRotate: 0
nameGap: 8
nameTextStyle: { align: left, verticalAlign: top, padding: [10, 0, 0, 4] }
axisLabel: { formatter: $fn:fmtGbTick30 }
axisLine: { show: true, symbol: [arrow, none], symbolSize: [10, 14], lineStyle: { width: 1.6, color: "#4b5563" } }
axisTick: { show: true, length: 6 }
splitLine: { show: true, lineStyle: { type: dashed, width: 1, opacity: 0.32, color: "#9ca3af" } }
series:
- { name: Recovery Window, type: line, smooth: false, symbol: none, showSymbol: false, xAxisIndex: 0, yAxisIndex: 0, lineStyle: { width: 3, color: "#f28e2c" }, itemStyle: { color: "#f28e2c" }, data: [[1,24],[2,48],[3,72],[4,96],[5,120],[6,144],[7,168],[8,192],[9,216],[10,240],[11,264],[12,288],[13,312],[14,336],[14,168],[15,192],[16,216],[17,240],[18,264],[19,288],[20,312],[21,336],[21,168],[22,192],[23,216],[24,240],[25,264],[26,288],[27,312],[28,336],[28,168],[29,192],[30,216]], markLine: { symbol: none, label: { show: false }, data: [ { xAxis: 7, lineStyle: { color: "#336791", type: "solid", width: 1.4, opacity: 0.65 } }, { xAxis: 14, lineStyle: { color: "#336791", type: "solid", width: 1.4, opacity: 0.65 } }, { xAxis: 21, lineStyle: { color: "#336791", type: "solid", width: 1.4, opacity: 0.65 } }, { xAxis: 28, lineStyle: { color: "#336791", type: "solid", width: 1.4, opacity: 0.65 } }, { yAxis: 168, label: { show: true, formatter: "lower 7d", position: "end", distance: 12, color: "#2563eb" }, lineStyle: { color: "#2563eb", type: "dashdot", width: 1.4, opacity: 0.72 } }, { yAxis: 336, label: { show: true, formatter: "upper 14d", position: "end", distance: 12, color: "#7c3aed" }, lineStyle: { color: "#7c3aed", type: "dashdot", width: 1.4, opacity: 0.72 } } ] } }
- { name: Primary Backup, type: bar, stack: used, xAxisIndex: 1, yAxisIndex: 1, barWidth: 16, itemStyle: { color: "#59a14f" }, data: [100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100] }
- { name: Secondary Backup, type: bar, stack: used, xAxisIndex: 1, yAxisIndex: 1, barWidth: 16, itemStyle: { color: "#4e79a7" }, data: [0,0,0,0,0,0,0,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100] }
- { name: Incremental Backup, type: bar, stack: used, xAxisIndex: 1, yAxisIndex: 1, barWidth: 16, itemStyle: { color: "#76b7b2" }, data: [0,10,20,30,40,50,60,70,80,90,100,110,120,130,70,80,90,100,110,120,130,70,80,90,100,110,120,130,70,80] }
- { name: WAL Archive, type: bar, stack: used, xAxisIndex: 1, yAxisIndex: 1, barWidth: 16, itemStyle: { color: "#edc949" }, data: [10,20,30,40,50,60,70,80,90,100,110,120,130,140,80,90,100,110,120,130,140,80,90,100,110,120,130,140,80,90] }
- { name: Transient Backup, type: bar, stack: used, xAxisIndex: 1, yAxisIndex: 1, barWidth: 16, itemStyle: { color: "#9ca3af", opacity: 0.75 }, data: [0,0,0,0,0,0,0,0,0,0,0,0,0,110,0,0,0,0,0,0,110,0,0,0,0,0,0,110,0,0] }By default, Pigsty provides two default backup repository definitions: local and minio backup repositories.
local: Default option, uses local /pg/backup directory (symlink to pg_fs_backup: /data/backups)minio: Uses SNSD single-node MinIO cluster (supported by Pigsty, but not enabled by default)Pigsty provides three restore entry points. They share the same parameter semantics, but serve different scopes:
| Entry point | Use case | What it controls |
|---|---|---|
pgsql-pitr.yml |
Production cluster recovery | HA pause, multiple nodes, etcd cleanup, restore, and restart |
pig pitr |
A local database node | Single-instance orchestration without the admin node |
pig pb restore |
An instance not managed by Patroni | A direct pgBackRest restore wrapper |
For a hands-on sandbox drill, see Manual Recovery. To recover into another cluster without changing production, see Clone a PG Cluster.
pgsql-pitr.yml pauses HA, stops Patroni/PostgreSQL, overwrites the target data directory with pgbackrest --force restore,
then deletes the target cluster’s etcd prefix and rebuilds HA. It prints a plan but does not wait for confirmation.
Before any real restore, inspect the topology with pig pg list <target-cluster>, verify a recent usable backup and recovery window with pig pb info,
and have the operator state and confirm the exact target cluster and recovery point. Schedule a maintenance window and retain an independently verified backup for production recovery.
To roll pg-meta back to an earlier time, declare pg_pitr:
Run the same target through the safety gate before executing it:
You can pass the same object temporarily on the command line:
The -e value must be valid JSON: quote keys and string values, for example {"pg_pitr": {"time": "...", "archive": true}}.
Booleans are not quoted. Invalid quoting can fail parsing or silently produce the wrong value.
The playbook pauses Patroni HA, stops the cluster, performs a delta pgBackRest restore, starts PostgreSQL and waits for a consistent recovery state,
prints control data, removes old etcd metadata, and starts the cluster under Patroni again.
It prints the source, target, and restore command first, but has no interactive approval gate. A one-shot targeted recovery should therefore declare action: promote explicitly.
To inspect data at the target, use step-by-step execution with action: pause.
pg_pitr supports six recovery target forms. The four target values are mutually exclusive.
Recovery target types
With no target, recovery replays all archived WAL to the latest available state (Pigsty’s internal type is default).
immediate stops at the first consistent point, which is useful for obtaining a usable instance as quickly as possible or testing a backup.
Use a valid PostgreSQL TIMESTAMP; an explicit time zone is strongly recommended:
Create an unambiguous marker before a risky change with pg_create_restore_point:
If the offending transaction ID is known from monitoring or CSVLOG’s TXID field, use exclusive to stop before that transaction:
An LSN identifies a position in the WAL stream. It is also visible in Pigsty’s PG LSN dashboard panel.
Set timeline when the desired position is on a particular timeline; the default is latest.
Targets are inclusive by default, so the target transaction is replayed. exclusive: true excludes the exact target.
It applies only to time, xid, and lsn, and maps to PostgreSQL’s recovery_target_inclusive.
Recovery uses the target cluster’s own backup by default. Three fields can select another source:
cluster: the source stanza, including another cluster in a shared repositoryrepo: a temporary repository definition in the same format as a pgbackrest_repo entryset: a specific backup label; otherwise pgBackRest selects a suitable setFor example, recover pg-meta2 from pg-meta:
In an incident, use tags to retain an explicit human gate between stages. After confirming the backup, recovery point, and exact target, run the stages in order:
After down, confirm the processes are stopped. After pitr, inspect /pg/tmp/recovery.log and query the recovery state before checking narrowly authorized business data.
pg_controldata /pg/data reports checkpoint and timeline metadata; it does not by itself prove that a time, XID, or LSN target was reached.
With action: pause, promote only after validation, then run up. If the target is wrong, adjust pg_pitr and repeat pitr before up.
pause or shutdown creates a meaningful human gate only in this staged workflow; use action: promote explicitly for one-shot targeted recovery.
With backup: true, the playbook moves the current data directory to /pg/data-backup, but deletes any existing /pg/data-backup before doing so.
The staged workflow is supported; a restore using backup: true is not generally idempotent.
Declare the target, action, and treatment of existing data explicitly:
See Parameter Mapping for the corresponding pgBackRest options.
pig pitr
pig pitr performs a local-node workflow without Ansible: validate the target, stanza, and backup; stop Patroni/PostgreSQL; restore; optionally start PostgreSQL; and print follow-up guidance.
Use -b/--set for a backup set, -T/--target-timeline for a timeline, --target-action for the post-target action,
and -D/--data with --no-restart for a side restore. The command normally attempts a fast stop and aborts if that fails;
only explicit --force-stop permits immediate shutdown and a kill fallback.
For managed PGDATA it leaves Patroni stopped. Validate the instance before pig pt start.
It does not remove etcd metadata, rebuild replicas, or rejoin the instance to an HA cluster.
pig pb restore
For an instance not managed by Patroni (or one deliberately taken out of management), pig pb restore directly wraps pgbackrest restore.
It validates the environment, requires PostgreSQL to be stopped, displays the plan, and asks for confirmation.
It rejects a live Patroni-managed target because Patroni could restart a half-restored instance, and it rejects any running PostgreSQL target.
Arguments after --, such as --tablespace-map or --link-all, pass through to pgBackRest, but wrapped options such as target, stanza, and repository cannot be overridden there.
After restore:
Verify the recovery state and the smallest authorized set of application checks.
After a cross-cluster clone, complete stanza cleanup. Create a full backup on the new timeline as soon as practical:
If exploratory recovery used archive: false, restore archiving. Because archive_mode is a postmaster setting, first confirm the maintenance window, current primary, and replication state, then obtain explicit approval for the restart:
Cloning is one of the safest and most useful applications of recovery: leave production untouched and restore its historical state into another cluster. You can recover accidentally deleted data from the clone, validate backups in a drill, inspect a historical state, or reset a test environment to a production snapshot.
The target must be able to access the source backup repository, may be overwritten, and must use a compatible PostgreSQL major version. With a shared Silo/S3 repository, each cluster’s backups are isolated by a stanza and visible to targets holding the required credentials.
Inspect the target topology with pig pg list <target-cluster>, verify the source stanza’s recent backups and recovery window with pig pb info,
and have the operator confirm the exact source cluster, target cluster, and recovery point before performing the restore.
Existing data on the target is overwritten; production work still requires a maintenance window and an independently verified backup.
Assume the four-node sandbox contains pg-meta and pg-test, sharing a Silo repository.
To reset pg-test to the latest state of pg-meta, point pg_pitr to the pg-meta stanza:
Add a recovery target to clone any state inside the recovery window. For example, reset to 15:30 on December 26, 2025:
These cross-cluster examples set archive: false to keep the exploratory recovery from archiving under the target stanza.
After Patroni takes control, complete the stanza and archive cleanup below.
The target may also be a newly initialized empty cluster, such as pg-meta2. Create it through the normal cluster creation workflow, then perform cross-cluster PITR.
pgBackRest restore uses delta mode and rewrites only files that differ from the backup. Repeated drills, or a target already synchronized through a standby cluster, can therefore restore much faster than a first full restore.
For accidental deletion, validate the clone and use pg_dump to export only the affected tables or database back into production.
An in-place rollback of the entire production cluster should be the last resort, not the first response.
The clone contains the source cluster’s data, while the target stanza may still record the target’s old PostgreSQL system identifier. pgBackRest refuses a backup when the identifiers do not match, preventing the new cluster from contaminating the source history.
After validating the clone, complete these steps. Restarting the cluster is a service change: first inspect the primary and replication state, schedule the maintenance window, and obtain explicit approval.
Until this is complete, scheduled backups can fail the identity check, and a clone restored with archive: false produces no new WAL archive:
stanza-upgrade lets the new cluster continue writing under its existing stanza. If the clone should start a completely independent backup history, rebuild that stanza instead.
Declarative workflow:
Equivalent low-level workflow:
Delete only after checking recent backups, retaining any required independent recovery copy, and having the operator confirm the exact pg-test stanza.
Object-locked versions can remain and continue consuming storage; a successful deletion command does not prove that every underlying version has been physically erased.
A PITR clone is a static snapshot. Use a streaming-replication standby cluster for a continuously following online copy, or a delayed cluster for a fixed rollback window such as one hour.
The three methods complement each other: standby clusters provide a live copy, delayed clusters preserve a fixed delay, and PITR clones expose any historical state inside the recovery window without requiring a pre-existing online replica.
A clone is an end-to-end restore drill that does not touch production, although it does overwrite the designated drill target. Run one quarterly and after major backup changes:
See Manual Recovery for a sandbox exercise using pgBackRest primitives, or Fork an Instance for an XFS snapshot-based local test copy.
Pigsty’s backup and restore operations ultimately execute pgBackRest commands. Using them safely requires both pgBackRest’s model and the mapping from Pigsty’s orchestration layers to native options.
A stanza names one PostgreSQL backup configuration and isolates that cluster inside a repository. Pigsty maps it directly from pg_cluster: the pg-meta stanza stores data under backup/pg-meta/ and archive/pg-meta/, so several clusters can share one repository.
The stanza records the source system identifier and major version and checks them before a backup. That identity check is why a cross-cluster clone needs stanza-upgrade afterward. Pigsty creates the stanza during cluster initialization; stanza-upgrade updates it after a major-version change or clone.
A repository stores backup files and WAL archives. repo1-type selects POSIX, S3, Azure, GCS, or SFTP; repo1-path, repo1-cipher-*, and repo1-retention-* define location, encryption, and retention. Pigsty renders these from pgbackrest_repo; see Backup Repository.
| Type | Contents | Label suffix |
|---|---|---|
| Full | Complete database-cluster copy | F |
| Differential | Changes since the latest full | D |
| Incremental | Changes since the latest backup of any type | I |
Labels encode the chain. 20250715-013657F is a full backup; 20250715-013657F_20250715-013724D and ..._20250715-013730I depend on the full identified before the underscore. --set chooses the starting backup explicitly; otherwise pgBackRest selects the newest usable set before the target.
repo1-retention-full and repo1-retention-full-type (count or time) decide when full chains expire. Dependent differential/incremental backups and WAL needed only by that chain expire with the full. Pigsty enables expire-auto, and pig pb expire --plan previews a manual run.
Time retention is a minimum window, not “keep only fulls newer than N days.” An old full expires only when another retained full has reached that age. A 14-day setting with weekly fulls therefore commonly retains three full chains and roughly 14–21 days of history.
PostgreSQL invokes archive-push when a WAL segment fills or archive_timeout elapses. During recovery, restore_command calls archive-get. Pigsty enables asynchronous archiving through /pg/spool so a temporary repository delay does not block the primary directly.
Each promotion after recovery or failover creates a new timeline. Older timeline history remains in the repository, and --target-timeline chooses the recovery branch (latest by default). See the conceptual PITR mechanism.
restore Actually Does
restore first reconstructs the data directory. Pigsty enables --delta, so pgBackRest validates existing files and rewrites only mismatches. It then writes recovery state (recovery.signal, restore_command, and recovery_target_*). Actual WAL replay happens after PostgreSQL starts.
Consequently, a successful restore command is only half of PITR. --target-action controls what happens when replay reaches the target: pause, promote, or shutdown.
Run read-only info after full, differential, and incremental backups to inspect labels, size, WAL bounds, and references:
A representative sequence looks like:
| Layer | Interface | What it does |
|---|---|---|
| Cluster orchestration | pg_pitr + pgsql-pitr.yml |
Pause HA, stop nodes, render configuration, restore/replay, inspect control data, clean etcd, and rebuild HA |
| Instance orchestration | pig pitr |
Preflight, keep one target offline, restore, optionally start PostgreSQL, and leave Patroni stopped for inspection |
| Command primitive | pig pb, pb, pg-backup |
Supply stanza/DBSU context and call the corresponding pgBackRest command |
| Engine | pgbackrest |
Read /etc/pgbackrest/pgbackrest.conf and perform backup, archive, and restore operations |
pb is a login-shell function that reads the first stanza from the local configuration and forwards arguments:
pg-backup adds a primary-role check for scheduled use:
pig pb adds stanza detection, DBSU privilege handling, primary checks for backup, and plan/confirmation guards for destructive primitives. See Admin Commands.
pg_pitr field |
pig pitr option |
pgBackRest option | Meaning |
|---|---|---|---|
cluster |
--stanza |
--stanza |
Source cluster/stanza |
type plus time/xid/lsn/name |
corresponding target option | --type + --target |
Recovery target |
default |
--default |
no --type/--target |
Replay to archive end |
immediate |
--immediate |
--type=immediate |
Stop at the first consistent point |
exclusive |
--exclusive / -X |
--target-exclusive |
Stop before the target |
action |
--target-action |
--target-action |
pause, promote, or shutdown |
timeline |
--target-timeline / -T |
--target-timeline |
Target timeline |
set |
--set / -b |
--set |
Starting backup set |
db_include / db_exclude |
— | --db-include / --db-exclude |
Select databases in a physical restore |
link_map |
— | --link-map |
Remap directory or tablespace links |
process |
— | process-max |
Parallel restore processes |
data |
--data / -D |
--pg1-path |
Target data directory |
repo |
repository number only in pig pitr |
rendered repo1-* |
Override repository definition in the playbook |
A selective restore is still physical. Excluded databases receive sparse zeroed files so PostgreSQL can complete recovery, but those databases are inaccessible and must be removed explicitly afterward; this is not a logical subset like pg_dump.
The entry selected by pgbackrest_method is rendered to /etc/pgbackrest/pgbackrest.conf: underscores become hyphens and keys receive the repo1- prefix.
pgsql-pitr.yml renders a separate temporary /pg/conf/pitr.conf; PostgreSQL recovery output goes to /pg/tmp/recovery.log.
pg_crontab entries are installed for the postgres OS user on every cluster node. Because pg-backup checks the current role, only the primary backs up, and a promoted primary takes over future schedules.
See Backup Policy for frequency and retention design.
The pg_backup subtask installs/configures pgBackRest, creates the stanza, and—when pgbackrest_init_backup is enabled—attempts an initial full backup. /etc/pgbackrest/initial.done is written only after that backup succeeds.
| Path | Purpose |
|---|---|
/usr/bin/pgbackrest |
pgBackRest binary |
/etc/pgbackrest/pgbackrest.conf |
Main stanza and repository configuration |
/pg/backup |
Local repository path |
/pg/spool |
Asynchronous archive spool |
/pg/log/pgbackrest/ |
Backup, archive, and restore logs |
/pg/conf/pitr.conf |
Temporary PITR configuration |
/pg/tmp/recovery.log |
PostgreSQL recovery log |
pgbackrest_exporter listens on pgbackrest_exporter_port, 9854 by default, and exports backup metrics. Disable it with pgbackrest_exporter_enabled or customize it with pgbackrest_exporter_options.
Two parameters decide where backups are stored: pgbackrest_repo defines candidate repositories, while pgbackrest_method selects one. Repository keys are rendered deterministically as pgBackRest repo1-* options, so any supported pgBackRest repository option can be used directly.
Pigsty v4.5.0 renders only the entry selected by pgbackrest_method as repo1; keeping several candidate keys does not enable multi-repository backup.
Pigsty supplies two definitions: local and minio.
local is the default. /pg/backup points at pg_fs_backup, /data/backups by default.minio uses Silo from the MINIO module or another compatible S3 service. It is supported but not selected by default.The presets deliberately differ. local favors simple, fast restores with count-based retention and no encryption or bundling. minio enables AES-256-CBC encryption, bundles small files, uses block incremental backup, and retains full backups by time.
For a remote repository, replace both cipher_pass and s3_key_secret. pgBackRest and S3User.Backup are public example defaults. Losing the encryption passphrase makes the repository unrecoverable, so store it separately from the backups under controlled recovery procedures; see Deployment Security.
pgBackRest applies retention after each backup (expire-auto). When a full backup expires, dependent differential/incremental backups and the WAL needed only by that chain expire with it.
retention_full_type: count plus retention_full: 2 keeps the two newest full chains; a third can exist briefly while a new full completes.retention_full_type: time plus retention_full: 14 establishes a minimum time window. An old full does not expire until another full is at least 14 days old; with weekly full backups this usually leaves three chains and roughly 14–21 days of recovery history.See Backup Policy for recovery-window and space calculations, and Admin Commands for a safe expiration preview.
The MINIO module currently deploys Silo, an S3-compatible object store. It provides an independent disaster-recovery copy only when deployed outside the database host or site failure domain. Deploy it, then select the minio preset:
The preset uses the HTTPS endpoint sss.pigsty by default and validates it with /etc/pki/ca.crt. MINIO initialization creates the default pgsql bucket and pgbackrest user.
For serious production use, deploy and test a fault-tolerant multi-node/multi-drive object store; see MINIO Configuration. The preset name minio does not require the server to be managed by Pigsty: independently operated MinIO, RustFS, or another compatible implementation can use it, but that service’s installation, upgrades, certificates, and lifecycle remain outside the MINIO role’s support boundary.
For a single database node, an off-host cloud object store is often the most valuable repository. Define a new entry and select it:
pgBackRest also supports Azure, GCS, and SFTP repositories.
A centralized repository can serve several PostgreSQL clusters. Each stanza, mapped from pg_cluster, isolates one cluster’s backup and archive history. This also enables cross-cluster restore.
Cluster names must therefore be globally unique within a shared repository, even across otherwise separate deployment environments.
Object-store versioning can preserve earlier versions after an overwrite or deletion. It still shares the same storage system and control plane, so it does not replace an independent off-site or offline copy. Enable it for a bucket when it is created:
pgBackRest’s repo-target-time option can read the repository as it existed at an earlier time when the backend retains those versions.
Some S3-compatible services support Object Lock/WORM. A retained object version cannot be changed or permanently deleted until its retention period ends. A normal delete can still create a delete marker that hides the current object while historical versions remain and continue consuming capacity.
The lock flag enables versioning and lock capability only when Pigsty creates the bucket:
It does not set a default retention period. Configure GOVERNANCE or COMPLIANCE retention with mcli retention set or the storage console, then verify with mcli retention info. A sufficiently privileged principal can bypass GOVERNANCE; even root cannot shorten COMPLIANCE retention.
Locking changes expiration and stanza deletion: pgBackRest may expire objects logically while retained historical versions remain until their deadline. Test backup, expiration, delete-marker cleanup, and version recovery on a non-production bucket before enabling it.
After changing a repository definition or pgbackrest_method, rerender configuration, initialize the stanza, and create a recovery point in the new repository promptly:
Existing backups are not migrated automatically. While retained, the old repository can still be selected as a restore source through pg_pitr.repo.
Run backup commands as the database superuser (pg_dbsu, postgres by default) on a database node. You can use any of these entry points:
pig pb: the PIG CLI wrapper, with automatic stanza detection, DBSU switching, and safety checks; this is the recommended interfacepb: a login-shell function that supplies --stanza and forwards arguments to pgBackRestpgbackrest: the native command; see the pgBackRest command reference| PIG command | Alias | Native pgBackRest command | Purpose |
|---|---|---|---|
pig pb info |
i |
info |
Show backup and archive status |
pig pb list |
ls |
— | List repositories, stanzas, or backup sets |
pig pb backup [full/diff/incr] |
b |
backup |
Create a backup after checking the primary role |
pig pb restore |
r |
restore |
Low-level restore primitive; see Restore Operations |
pig pb expire |
e |
expire |
Expire backups according to retention (--plan previews) |
pig pb create |
c |
stanza-create |
Create a stanza |
pig pb upgrade |
u |
stanza-upgrade |
Upgrade a stanza after a major-version change or clone |
pig pb delete |
d |
stanza-delete |
Delete a stanza and all of its backups |
pig pb check |
ck |
check |
Verify configuration, repository access, and archiving |
pig pb start |
up |
start |
Re-enable pgBackRest operations |
pig pb stop |
dw |
stop |
Stop new pgBackRest operations |
pig pb log [list/show/tail] |
l |
— | Inspect pgBackRest logs |
If pgbackrest_enabled is true when the cluster is created, backup is enabled automatically. If it was disabled at creation time, or repository settings have changed, run the pg_backup subtask:
After cluster initialization, Pigsty attempts an initial full backup. It writes /etc/pgbackrest/initial.done only after the backup command succeeds; the playbook ignores a failed attempt and leaves no marker. This file only prevents the initialization task from repeating, so always verify actual repository state with pig pb info or pgbackrest info. Define scheduled backups with pg_crontab; see Backup Policy.
pig pb delete is the preferred interface when only a backup stanza must be removed. It asks for interactive confirmation; with a multi-stanza configuration, the target must also be explicit. Verify the exact target first:
When a primary instance (pg_role = primary) is removed, pgsql-rm.yml also tries to delete the cluster’s backup stanza by default. Every command below changes or deletes state; never execute one merely by copying the example:
Before execution, verify a recent usable backup, record the recovery requirement, and have the operator re-enter the exact cluster/stanza name. Set pg_rm_backup to false to preserve backups while removing the cluster.
pgsql-rm.yml -t pg_backup forcibly runs pgbackrest stanza-delete on the primary, removes the local repository directory in local mode, then removes the pgBackRest configuration and initial-backup marker. The task ignores some deletion errors, so a successful playbook result does not prove that repository objects were physically removed. Prefer pig pb delete when only the stanza needs deletion because it supplies a plan and confirmation guard.
With object versioning and object-lock retention, deletion may create a delete marker while locked historical versions continue consuming storage until their retention period expires.
Deleting backups can permanently destroy recovery options. Confirm the cluster/stanza, verify a recent backup and an alternative recovery copy, and retain the pig pb info output and deletion plan as an audit record.
You can trigger a backup outside the crontab schedule. Both pg-backup and pig pb backup check that the current instance is primary and exit on a replica:
Backup consumes disk I/O and network bandwidth. Pigsty limits parallelism to a small number of processes, but production runs should still be scheduled for low-traffic periods.
pb info shows backups and WAL archive status for the current stanza:
Backup labels ending in F, D, and I identify full, differential, and incremental backups. The portion before an underscore identifies the full backup anchoring that chain. The WAL archive range and the oldest usable full backup together bound the recovery window.
The pgbackrest_exporter service on port 9854 continuously exports metrics such as the latest backup time, type, size, and error status.
The configured retention policy is applied automatically after backups (expire-auto). Preview or run expiration manually with:
A stanza records a cluster’s backup identity, including its system identifier and major version. Manual management is occasionally required:
The usual manual upgrade case is post-clone cleanup: after restoring another cluster’s backup into a new cluster, update the stanza identity before new backups can be written.
check performs an archive-path check rather than being purely local or read-only; it verifies that WAL can reach the repository.
For pgsql-pitr.yml, PostgreSQL recovery output is written to /pg/tmp/recovery.log.
The legacy /pg/bin/pg-basebackup script creates a single-file physical backup using native pg_basebackup, an lz4-compressed tar stream, and /pg/backup by default. Use it only for a simple local copy when a pgBackRest repository is unavailable:
pg-basebackup -e uses the obsolete OpenSSL RC4 cipher and must not be treated as confidentiality protection. For encrypted backups, use a pgBackRest repository configured with AES-256 (cipher_type: aes-256-cbc).
Logical backups made with pg_dump cannot provide PITR, but they are appropriate for cross-major-version migration, partial exports, and long-term logical snapshots. Production recovery plans commonly use logical and physical backups together. See the PostgreSQL documentation.
Pigsty includes a built-in playbook pgsql-migration.yml that implements online database migration based on logical replication.
With pre-generated automation scripts, application downtime can be reduced to just a few seconds. However, note that logical replication requires PostgreSQL 10 or later to work.
Of course, if you have sufficient downtime budget, you can always use the pg_dump | psql approach for offline migration.
To use Pigsty’s online migration playbook, you need to create a definition file that describes the migration task details.
Refer to the task definition file example: files/migration/pg-meta.yml.
This migration task will online migrate pg-meta.meta to pg-test.test, where the former is called the Source Cluster (SRC) and the latter is called the Destination Cluster (DST).
Logical replication-based migration works on a per-database basis. You need to specify the database name to migrate, as well as the IP addresses of the source and destination cluster primary nodes and superuser connection information.
By default, the superuser connection strings on both source and destination sides are constructed using the global admin user and the respective primary IP addresses, but you can always override these defaults through the src_pg and dst_pg parameters.
Similarly, you can override the subscription connection string default through the sub_conn parameter.
This playbook does not actively perform cluster migration, but it generates the operation manual and automation scripts needed for migration.
By default, you will find the migration context directory at ~/migration/pg-meta.meta.
Follow the instructions in README.md and execute these scripts in sequence to complete the database migration!
Notes
If you’re worried about primary key conflicts when copying sequence numbers, you can advance all sequences forward by some distance when copying, for example +1000. You can use ./copy-seq with a parameter 1000 to achieve this.
You must implement your own ./re-routing script to route your application traffic from src to dst. Because we don’t know how your traffic is routed (e.g., dns, VIP, haproxy, or pgbouncer). Of course, you can also do this manually…
You can implement a ./disable-src script to restrict application access to the src cluster—this is optional: if you can ensure all application traffic is cleanly switched in ./re-routing, you don’t really need this step.
But if you have various access from unknown sources that can’t be cleanly sorted out, it’s better to use more thorough methods: change HBA rules and reload to implement (recommended), or simply stop the postgres, pgbouncer, or haproxy processes on the source primary.
This section provides step-by-step tutorials for common PostgreSQL tasks and scenarios.
This document lists potential failures in PostgreSQL and Pigsty, as well as SOPs for locating, handling, and analyzing issues.
Disk space exhaustion is the most common type of failure.
When the disk space where the database resides is exhausted, PostgreSQL will not work normally and may exhibit the following symptoms: database logs repeatedly report “no space left on device” errors, new data cannot be written, and PostgreSQL may even trigger a PANIC and force shutdown.
Pigsty includes a NodeFsSpaceFull alert rule that triggers when filesystem available space is less than 10%. Use the monitoring system’s NODE Instance panel to review the FS metrics panel to locate the issue.
You can also log into the database node and use df -h to view the usage of each mounted partition to determine which partition is full.
For database nodes, focus on checking the following directories and their sizes to determine which category of files has filled up the space:
/pg/data/base): Stores data files for tables and indexes; pay attention to heavy writes and temporary filespg/data/pg_wal): Stores PG WAL; WAL accumulation/replication slot retention is a common cause of disk exhaustion.pg/log): If PG logs are not rotated in time and large amounts of errors are written, they may also consume significant space.data/backups): When using pgBackRest or similar tools to save backups locally, this may also fill up the disk.If the issue occurs on the Pigsty admin node or monitoring node, also consider:
After identifying the directory consuming the most space, you can further use du -sh <directory> to drill down and find specific large files or subdirectories.
Disk exhaustion is an emergency issue requiring immediate action to free up space and ensure the database continues to operate.
When the data disk is not separated from the system disk, a full disk may prevent shell commands from executing. In this case, you can delete the /pg/dummy placeholder file to free up a small amount of emergency space so shell commands can work again.
If the database has crashed due to pg_wal filling up, you need to restart the database service after clearing space and carefully check data integrity.
PostgreSQL cyclically uses 32-bit transaction IDs (XIDs), and when exhausted, a “transaction ID wraparound” failure occurs (XID Wraparound).
The typical sign in the first phase is when the age saturation in the PGSQL Persist - Age Usage panel enters the warning zone.
Database logs begin to show messages like: WARNING: database "postgres" must be vacuumed within xxxxxxxx transactions.
If the problem continues to worsen, PostgreSQL enters protection mode: when remaining transaction IDs drop to about 1 million, the database switches to read-only mode; when reaching the limit of about 2.1 billion (2^31), it refuses any new transactions and forces the server to shut down to avoid data corruption.
PostgreSQL and Pigsty enable automatic garbage collection (AutoVacuum) by default, so the occurrence of this type of failure usually has deeper root causes. Common causes include: very long transactions (SAGE), misconfigured Autovacuum, replication slot blockage, insufficient resources, storage engine/extension bugs, disk bad blocks.
First identify the database with the highest age, then use the Pigsty PGCAT Database - Tables panel to confirm the age distribution of tables. Also review the database error logs, which usually contain clues to locate the root cause.
VACUUM FREEZE table_name; on tables identified with the largest relfrozenxid, prioritizing tables with the highest XID age. This can quickly reclaim large amounts of transaction ID space.VACUUM FREEZE database_name; to freeze and clean the entire database. After completion, restart the database in multi-user mode. This can lift the wraparound lock and make the database writable again. Be very careful when operating in single-user mode and ensure sufficient transaction ID margin to complete the freeze.PostgreSQL has a maximum connections configuration (max_connections). When client connections exceed this limit, new connection requests will be rejected. The typical symptom is that applications cannot connect to the database and report errors like
FATAL: remaining connection slots are reserved for non-replication superuser connections or too many clients already.
This indicates that regular connections are exhausted, leaving only slots reserved for superusers or replication.
Connection exhaustion is usually caused by a large number of concurrent client requests. You can directly review the database’s current active sessions through PGCAT Instance / PGCAT Database / PGCAT Locks. Determine what types of queries are filling the system and proceed with further handling. Pay special attention to whether there are many connections in the “Idle in Transaction” state and long-running transactions (as well as slow queries).
Kill queries: For situations where exhaustion has already blocked business operations, typically use pg_terminate_backend(pid) immediately for emergency pressure relief.
For cases using connection pooling, you can adjust the connection pool size parameters and execute a reload to reduce the number of connections at the database level.
You can also modify the max_connections parameter to a larger value, but this parameter requires a database restart to take effect.
An exhausted etcd quota will cause the PG high availability control plane to fail and prevent configuration changes.
Pigsty uses etcd as the distributed configuration store (DCS) when implementing high availability. etcd itself has a storage quota (default is about 2GB). When etcd storage usage reaches the quota limit, etcd will refuse write operations and report “etcdserver: mvcc: database space exceeded”. In this case, Patroni cannot write heartbeats or update configuration to etcd, causing cluster management functions to fail.
Versions between Pigsty v2.0.0 and v2.5.1 are affected by this issue by default. Pigsty v2.6.0 added auto-compaction configuration for deployed etcd. If you only use it for PG high availability leases, this issue will no longer occur in regular use cases.
Currently, TimescaleDB’s experimental storage engine Hypercore has been proven to have defects, with cases of VACUUM being unable to reclaim leading to XID wraparound failures. Users using this feature should migrate to PostgreSQL native tables or TimescaleDB’s default engine promptly.
Detailed introduction: PG New Storage Engine Failure Case (Chinese)
This tutorial drills PostgreSQL point-in-time recovery in Pigsty v4.5.0’s four-node sandbox. The main path runs pgsql-pitr.yml as down → pitr → up, giving the operator a separate validation gate before data overwrite, timeline promotion, and HA reconstruction.
For one current node, use pig pitr. For direct pgBackRest control, see the low-level pg-pitr utility.
Recovery stops Patroni/PostgreSQL and overwrites the target PGDATA with pgbackrest --force restore; the up stage also deletes the target cluster’s etcd prefix and rebuilds Patroni state. The playbook prints a plan but has no interactive confirmation. Before production use, the operator must state and confirm the exact cluster and recovery point, verify a recent usable backup that has been independently tested, run --check with exactly the same -l, variables, and tags, and schedule a maintenance window. This tutorial does not authorize running these commands in any production environment.
Use Vagrant or another disposable four-node lab and select the ha/full template, which includes a Silo backup repository:
ha/full defines the single-node pg-meta, three-node pg-test, and a Silo/pgBackRest repository. The rest of this tutorial uses the exact target pg-meta; do not copy that selector into another environment without resolving its inventory first.
Initial deployment and backup both change sandbox state. Production environments require their own deployment and backup approval process.
Start with read-only topology, backup-chain, and WAL-range checks:
info must show at least one usable backup with status: ok, and archived WAL must cover the intended target. check validates the current stanza and archive path, but it does not replace a real restore drill or independent-copy validation.
In the sandbox, run Pigsty’s heartbeat helper to create an easy-to-verify time series:
Record, then stop the workload:
pg-meta and target node.Inspecting real application tables requires separate authorization. This tutorial uses only sandbox heartbeat data.
Declare the target under pg-meta.vars in the sandbox inventory:
cluster is the source backup stanza and defaults to the target pg_cluster.action: pause pauses PostgreSQL at the target for a human validation gate.archive: true preserves archive settings.backup: true is not a safe-backup substitute: it deletes an existing <pg_data>-backup before moving current PGDATA, so this drill keeps it false.The same object can be supplied temporarily with -e, but preflight and all three stages must repeat the exact same valid JSON to prevent variable drift.
Before any stop or write action, check the complete workflow against the same target:
Confirm that Ansible resolves exactly pg-meta, then review the output for:
pg_data, port, and repository;archive and backup behavior.--check validates inventory, variables, and task selection. It cannot prove that a pgBackRest backup is restorable. Any change to target, backup, or variables requires a new preflight.
Only after the operator reconfirms exact target pg-meta, recovery point, and maintenance window, run:
down attempts to pause Patroni automatic failover, stops Patroni on every target member, and uses immediate shutdown if PostgreSQL remains running. Then verify every target node rather than trusting only the playbook result:
Expected results are inactive and “server is not running.” If any member remains active, stop and diagnose; do not enter restore.
Recheck pg_pitr and the target nodes before running the destructive stage:
This stage:
/pg/conf/pitr.conf and /pg/bin/pg-restore;backup;--force and delta=y;pg_controldata summary.Control data proves only that the directory has readable control state; it does not prove that a time, XID, or application boundary is correct. With action: pause, confirm WAL reached and paused near the target:
Then inspect only the smallest authorized data scope; in the sandbox, check heartbeat rows. If the target is wrong:
--check;pitr stage.Do not run up or allow replicas from the old timeline to rejoin.
Promote only after the operator accepts the recovered result and the creation of a new timeline:
The expected result is f. Promotion is not read-only validation and cannot be losslessly undone.
With every Patroni member still stopped and exact target still pg-meta, run:
up deletes the /pg/pg-meta/ prefix from etcd for the primary (the effective prefix also depends on pg_namespace and Citus settings), stops the manually started PostgreSQL, starts Patroni on the primary, then starts replicas one by one and resumes HA. The etcd deletion task tolerates errors, so a successful playbook result does not prove that stale DCS state was removed correctly.
Verify each layer; “service started” is not recovery completion:
Also confirm:
archive_mode, archive_command, and new-WAL archiving work;After the new timeline is stable, create and verify a new full backup under the applicable approval process:
If the recovery explicitly used archive: false, it wrote archive-mode=off. Reset that override and perform a controlled restart only after validating recovery and confirming a maintenance window; default archive: true does not require this step.
up starts replicas one at a time and waits for clone/recovery; monitor them to completion.pg_pitr.cluster is the source while -l is the destination being overwritten. Record and state both separately.archive: false so a test destination cannot write WAL into the source stanza. Enable its own archiving only after acceptance and post-clone stanza cleanup.link_map, data, port, and a temporary repo change the actual storage and data targets; include all of them in both --check and human review.Use
node_hugepage_countandnode_hugepage_ratioor/pg/bin/pg-tune-hugepage
If you plan to enable HugePages, consider using node_hugepage_count and node_hugepage_ratio, and apply with ./node.yml -t node_tune.
HugePages have pros and cons for databases. The advantage is that memory is managed exclusively, eliminating concerns about being reallocated and reducing database OOM risk. The disadvantage is that it may negatively impact performance in certain scenarios.
Before PostgreSQL starts, you need to allocate enough huge pages. The wasted portion can be reclaimed using the pg-tune-hugepage script, but this script is only available for PostgreSQL 15+.
If your PostgreSQL is already running, you can enable huge pages using the following method (PG15+ only):
Pigsty v4.5.0 provides two local shell utilities:
pg-fork copies a PostgreSQL data directory and gives the copy a separate port.pg-pitr invokes pgBackRest to restore a stopped data directory to a selected target.They are useful for sandbox drills, side-channel investigation, and temporary testing. They are not complete Patroni-cluster recovery orchestrators. Prefer pig pitr for a managed instance and staged pgsql-pitr.yml for a multi-node cluster.
pg-fork recursively removes an existing destination directory; pg-pitr overwrites the destination with backup data. Both can execute without a prompt in a non-interactive environment. Before a real run, verify source and destination absolute paths, ports, tablespaces, exact cluster/instance identity, and an independent recent backup that has been tested. A newly created CoW clone is not an independent backup.
pg-fork copies a PostgreSQL data directory on the current node. Run it as the database OS user—normally postgres, or at least a member of the postgres group:
| Parameter | Meaning | Default |
|---|---|---|
<FORK_ID> |
One digit from 1 to 9, used to derive the default directory and port |
Required |
-d, --data <path> |
Source data directory | $PG_DATA or /pg/data |
-D, --dst <path> |
Destination data directory | /pg/data<FORK_ID> |
-p, --port <port> |
Source instance port | $PG_PORT or 5432 |
-P, --dst-port <port> |
Destination instance port | <FORK_ID>5432 |
-s, --skip |
Skip the online-backup API and force cold-copy mode | No |
-y, --yes |
Skip interactive confirmation | No |
The script rejects equal normalized source and destination paths, but it cannot know whether a custom destination contains other important data. If the destination directory exists, it is recursively removed before copying.
By default, the script connects to the source port and uses one psql session to run:
CHECKPOINT;pg_backup_start();rm -rf <destination> followed by cp -a --reflink=auto;pg_backup_stop(wait_for_archive => false).If the source cannot be reached on the selected port, the script automatically falls back to a cold copy instead of aborting. -s also forces a cold copy. A cold copy is safe only after you independently confirm that the source instance is fully stopped; a postmaster.pid warning is only a clue, not proof of process state.
On the same filesystem, the implementation recognizes these as fast CoW modes: XFS with reflink enabled, Btrfs, Bcachefs, and OCFS2. Other filesystems or cross-filesystem destinations still use cp --reflink=auto but may fall back to a full copy. The script’s help text mentions ZFS more broadly than its detector; the v4.5.0 implementation does not classify ZFS as a confirmed fast-CoW mode.
After a successful copy, pg-fork: