Max connections
Job details
Name: | Max connections |
Platform: | Postgres |
Category: | Capacity |
Description: | Checks the size of the log file. |
Long description: | |
Version: | 1.1 |
Default schedule: | 15m |
Requires engine install: | No |
Compatibility tag: | .[type=‘instance’]/instance[databasetype=‘postgres’] |
Parameters
Name | Default value | Description |
---|---|---|
warning_threshold | 30 | Number of sessions left until max_connections parameter is reached in order to generate warning |
alarm_threshold | 10 | Number of sessions left until max_connections parameter is reached in order to generate alarm |
Job Summary
- Purpose: The purpose of this job is to monitor the number of active sessions in a PostgreSQL database instance and compare it with the configured maximum number of connections (max_connections).
- Why: Monitoring the number of active sessions relative to the maximum allowed is crucial for maintaining database performance and availability. If the number of sessions approaches the maximum limit, system performance may deteriorate, leading to slow query responses or even denying new connections.
- Manual checking: You can check this manually in the PostgreSQL database by issuing the following SQL command:
SELECT COUNT(*) FROM pg_stat_activity;
Details of the Monitoring Job
The monitoring job specifically checks if the number of sessions connected to a PostgreSQL instance is nearing its max_connections parameter value. It classifies the status into two main thresholds:
- “Warning” when there are 30 or fewer sessions left before reaching the max_connections.
- “Alarm” when there are 10 or fewer sessions left before reaching the max_connections.
Logic Implementation
Using JavaScript, this job calculates the number of active sessions and triggers alerts based on the thresholds:
- It first fetches the current max_connections value and the total session count.
- It compares the current sessions against the thresholds to determine if a warning or alarm should be triggered.
- If sessions exceed the warning threshold, a warning message is generated.
- If sessions exceed the alarm threshold, an alarm message is generated.
- An informative message is provided if the sessions are within safe limits.
Reporting Template
The report provides a structured output:
- Title: “Max sessions status”
- Description: It checks and reports on the max sessions status.
- Schedule: Runs every 15 minutes by default.
Output Table
The output from this monitoring job is presented in a table format which includes:
Details |
---|
Connected sessions vs. Max sessions |
This table combines both the maximum number of sessions and the number of connected sessions, providing a clear view of the database’s capacity usage.
In summary, this job is vital for preventing database overloads and ensuring smooth operations by constantly monitoring and alerting on session usage relative to capacity.