A CNPG-I plugin that automatically hibernates inactive CloudNativePG clusters to optimize resource usage and reduce costs.
This plugin monitors PostgreSQL database activity and automatically hibernates clusters after a configurable inactivity period.
- The plugin injects a sidecar HTTP server into each PostgreSQL pod. The server returns the number of open connections.
- The central plugin periodically requests the connection count from the primary pod.
- Successful responses with open connections reset the inactivity period. Errors or unavailable data do not count as inactivity.
- After consecutive zero-connection responses for the configured period, the plugin hibernates the cluster and suspends its scheduled backup.
flowchart LR
Plugin[Scale-to-zero plugin] -->|Request connection count| Sidecar[Primary pod sidecar]
Sidecar -->|Query connections| Postgres[PostgreSQL primary]
Sidecar -->|Return connection count| Plugin
Plugin -->|Hibernate cluster| Operator[CloudNativePG operator]
See the installation guide for prerequisites, deployment, configuration, verification, and troubleshooting.
The plugin consists of two container images:
- Plugin:
ghcr.io/xataio/cnpg-i-scale-to-zero - Sidecar:
ghcr.io/xataio/cnpg-i-scale-to-zero-sidecar
We publish different image tags for different use cases:
dev: local docker images built usingmake docker-build-dev
main: Latest development build from the main branchmain-<sha>: Specific commit builds from main branch
latest: Latest stable releasev1.0.0,v1.1.0, etc.: Specific version releases
Enable the plugin and scale-to-zero annotations on a CloudNativePG Cluster.
See the installation guide or the complete
cluster example.
Prometheus metrics are exposed by the plugin on the service port named
metrics. See the troubleshooting guide for log
and health checks.
This plugin uses the pluginhelper from cnpg-i-machinery to simplify the plugin's implementation.
See the development documentation for implementation details, build commands, and local testing with Tilt.
Currently, the plugin only monitors database activity on the primary instance. This means:
- Read-only workloads on replicas are not tracked - If your application connects directly to replica instances for read queries, this activity will not prevent hibernation
- Replica-only traffic - Clusters with active read traffic exclusively on replicas may be hibernated despite being in use
- Connection pooling to replicas - Applications using connection poolers that direct read traffic to replicas will not be detected as active
Workaround: Ensure critical read workloads also maintain at least one connection to the primary instance, or configure longer inactivity periods to account for replica-only usage patterns.
Future Enhancement: Replica activity monitoring may be added in future versions to provide more comprehensive activity detection across the entire cluster.
