You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+30-8Lines changed: 30 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,15 +4,16 @@ A [CNPG-I](https://github.com/cloudnative-pg/cnpg-i) plugin that automatically h
4
4
5
5
## Overview
6
6
7
-
This plugin monitors PostgreSQL database activity and automatically scales clusters down to zero replicas when they've been inactive for a configurable period. It injects a monitoring sidecar into the primary PostgreSQL pod that tracks database connections and query activity, then hibernates the cluster by setting the `cnpg.io/hibernation` annotation when the inactivity threshold is reached.
7
+
This plugin monitors PostgreSQL database activity and automatically scales clusters down to zero replicas when they've been inactive for a configurable period. It injects a monitoring sidecar into all pods of the PostgreSQL cluster. Only the primary pod actively monitors database connections and manages hibernation, while replica pods run the sidecar in passive mode until promoted to primary.
8
8
9
9
### How It Works
10
10
11
-
1.**Sidecar Injection**: Automatically adds a monitoring sidecar to the primary PostgreSQL pod
12
-
2.**Activity Monitoring**: The sidecar periodically checks for active database connections and recent queries
13
-
3.**Automatic Hibernation**: When the cluster is inactive for the configured duration, it sets the hibernation annotation
14
-
4.**Scheduled Backup Management**: Automatically pauses scheduled backups when the cluster is hibernated to prevent backup failures
15
-
5.**Resource Optimization**: Inactive clusters are scaled to zero, freeing up cluster resources
11
+
1.**Sidecar Injection**: Automatically adds a monitoring sidecar to all PostgreSQL pods in the cluster
12
+
2.**Primary-Only Monitoring**: Only the primary pod actively monitors database connections and query activity
13
+
3.**Passive Replicas**: Replica pods run the sidecar container but remain in passive mode (no monitoring)
14
+
4.**Automatic Hibernation**: When the cluster is inactive for the configured duration, the primary sidecar sets the hibernation annotation
15
+
5.**Scheduled Backup Management**: The primary pod automatically pauses scheduled backups when the cluster is hibernated to prevent backup failures
16
+
6.**Switchover Handling**: During switchovers, the new primary automatically takes over monitoring duties while the old primary becomes passive
16
17
17
18
## Installation
18
19
@@ -176,7 +177,8 @@ These resource configurations apply to all sidecar containers injected by the pl
176
177
The plugin provides logging to help monitor its operation:
177
178
178
179
- Sidecar injection events are logged during pod creation
179
-
- Activity monitoring status is logged at each check interval
180
+
- Activity monitoring status is logged at each check interval (primary pod only)
181
+
- Primary/replica role transitions are logged when pods change status
180
182
- Hibernation events are logged when clusters are scaled down
And monitor the sidecar logs in the PostgreSQL pods:
190
192
191
193
```shell
192
-
kubectl logs <pod-name> -c scale-to-zero
194
+
# View logs from the primary pod's sidecar (active monitoring)
195
+
kubectl logs <primary-pod-name> -c scale-to-zero
196
+
197
+
# View logs from replica pods' sidecars (passive mode)
198
+
kubectl logs <replica-pod-name> -c scale-to-zero
193
199
```
194
200
201
+
**Note**: Primary pod sidecars will show active monitoring logs, while replica pod sidecars will show minimal passive mode logs.
202
+
195
203
## Development
196
204
197
205
For local development and building from source:
@@ -214,3 +222,17 @@ make kind-deploy-dev
214
222
This plugin uses the [pluginhelper](https://github.com/cloudnative-pg/cnpg-i-machinery/tree/main/pkg/pluginhelper) from [`cnpg-i-machinery`](https://github.com/cloudnative-pg/cnpg-i-machinery) to simplify the plugin's implementation.
215
223
216
224
For additional details on the plugin implementation, refer to the [development documentation](doc/development.md).
225
+
226
+
## Limitations
227
+
228
+
### Primary-Only Activity Tracking
229
+
230
+
Currently, the plugin only monitors database activity on the **primary instance**. This means:
231
+
232
+
- **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
233
+
- **Replica-only traffic** - Clusters with active read traffic exclusively on replicas may be hibernated despite being in use
234
+
- **Connection pooling to replicas** - Applications using connection poolers that direct read traffic to replicas will not be detected as active
235
+
236
+
**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.
237
+
238
+
**Future Enhancement**: Replica activity monitoring may be added in future versions to provide more comprehensive activity detection across the entire cluster.
0 commit comments