Managing PostgreSQL Statements
Section titled “ Managing PostgreSQL Statements”Unlock the full potential of your PostgreSQL environments with the Nodinite Database Monitoring Agent. This page shows you how to leverage custom PSQL scripts for proactive monitoring, instant alerts, and self-service management—empowering both integration experts and business users.
- ✅ Monitor PostgreSQL health and business data using your own PSQL logic
- ✅ Instantly receive alerts and automate remediation with Remote Actions
- ✅ Empower self-service for business users to execute pre-defined scripts
- ✅ Centralize monitoring and management for all your PostgreSQL resources
Bring your own PSQL logic and Nodinite will monitor and alert you whenever there is a problem detected!
To use this feature, provide AdHoc PSQL statements with your business logic as described in the examples on this page. As for SQL Server, a PostgreSQL SQL Statement holds one connection and a list of monitoring statements on its Monitoring Statements (n) tab. The Database Monitoring Agent creates one Resource for each enabled monitoring statement. Each monitoring statement returns its evaluated state, which you can monitor in Monitor Views and push external alerts using any of the Alarm Plugins.
PostgreSQL PSQL Statements are grouped by the Category PostgreSQL - SQL Statements.

Example: Monitor View displaying PostgreSQL SQL Statement resources grouped by category.
- Your custom-built PostgreSQL - SQL Statements are listed in Nodinite as Resources, where the Display Name of the monitoring statement becomes the Resource name. It must be unique within the configuration, also across its SQL Statements.
Each enabled monitoring statement is manifested as a Resource. The tabs and validation work as described on SQL Statements, with the differences under Monitoring Statements tab.
What are the key features for Monitoring SQL Statements?
Section titled “ What are the key features for Monitoring SQL Statements?”- State Evaluation – Monitor and evaluate the state based on your own PSQL logic. See PSQL/Stored procedure code examples further down in this guide.
- Actions – Support for the execution of Remote Actions
What is evaluated for SQL Statements?
Section titled “What is evaluated for SQL Statements?”The different possible evaluated states for your custom coded SQL Statements are provided in the table below:
| Icon | State | Status | Description | Actions |
|---|---|---|---|---|
| Unavailable | Resource not available | Evaluation of the 'SQL Statement' is not possible either due to network or security-related problems | Review prerequisites | |
| Error | Error state raised | SQL Statement reports that one or more major problems/errors were detected by raising an exception | Edit | |
| Warning | Warning state raised | SQL Statement reports that one or more minor problems were detected by raising an exception with state warning | Edit | |
| OK | Online | SQL Statement is valid, executes and reports that no problems were detected | Edit |
How do I add my own SQL Statements?
Section titled “ How do I add my own SQL Statements?”The Database Monitoring Agent automatically monitors each configured SQL Statement. You can add new and modify existing SQL Statements using the Remote Configuration dialogue for the Database Monitoring Agent.
Global configuration
Section titled “ Global configuration”From the PostgreSQL databases tab, configure global settings. Then click on the Size check tab.
A Nodinite Administrator can add new SQL Statements from the Remote Configuration dialogue, as detailed in Add or manage a Monitoring Agent.
From the PostgreSQL statements tab for the PostgreSQL Database Connection configuration, click the Add button.
Any number of SQL Statements can be provided, but make sure that each one is fast to execute or you may end up hogging the agent and probably resulting in various timeouts.

Example: Add button location for creating new PostgreSQL SQL Statement configurations.
Expand the accordion to edit available properties.

Example: PostgreSQL SQL Statement configuration properties panel.
Monitoring Statements tab
Section titled “ Monitoring Statements tab”New 7.13
A SQL Statement of a PostgreSQL Database configuration has the tabs General, Monitoring Statements (n), User Action Scripts (n), and Authentication. The Monitoring Statements tab lists one accordion per monitoring statement; click Add for another one.

The Monitoring Statements tab of a PostgreSQL SQL Statement: the same list as for SQL Server.
The fields and the save rules are the ones of SQL Server, with two differences:
- The Authentication tab has only the Connection String; there is no impersonation.
- Every monitoring statement needs an Execute Command, also a disabled one. On SQL Server, only the enabled monitoring statements of an enabled SQL Statement need one.
A Display Name used twice in one configuration, also across its SQL Statements, stops the save (PSQL-DUPLICATE-003).
The properties below describe one monitoring statement.
You can manage the following properties:
- Enabled
- ApplicationId
- Display Name
- Command Type
- Command Text
- Description
Enabled
Section titled “ Enabled”Flag to set if monitoring for this configuration is enabled or not.
ApplicationId
Section titled “ ApplicationId”Select the Id of which Application to associate this Resource (SQL Statement configuration) with.
Display Name
Section titled “ Display Name”You can manage the user-friendly Name. This setting must be unique for each SQL Statement configuration.
Command Type
Section titled “ Command Type”The Type of 'SQL Command', select one of the following:
- Text – For AdHoc PSQL Statements
Command Text
Section titled “ Command Text”Enter your Command text, see examples further down in this guide.
- Execute Command – the SQL command(s) to execute
An AdHoc PSQL query with your own custom logic.
Description
Section titled “ Description”Description – user-friendly description for SQL Statement resource
Actions
Section titled “ Actions”The following Actions are currently implemented:
Edit SQL Statement
Section titled “ Edit SQL Statement”Modify SQL Statement configuration directly from the Resource using Remote Actions.
You must click 'Save' or 'Save and close' for changes to persist. The new settings/thresholds are evaluated on the next synchronization.

Example: Save and Save and close button options.
Save and close saves and closes the dialogue.
Cancel closes the dialogue without saving any changes.
Examples
Section titled “ Examples”The outcome (State) from the logic in your PostgreSQL - SQL Statements is based on whether you raise an exception or not.
Internally, the Database Monitoring Agent executes the Execute Scalar method. This will pick up data from the first column at the first row, and set this as Log Text unless you raised an exception.
Select + throw (raiserror)
Section titled “Select + throw (raiserror)”The LogText presented for the PostgreSQL Statement configuration (The Resource) comes from your last SELECT statement (1st row, 1st column) or from the Exception. If you do not select anything the Log Text simply becomes empty.
| Return Code | Evaluated State | LogText |
|---|---|---|
| No exception raised | OK | From SELECT operation (1st column) |
| Throw exception | Error | From HINT text |
| Throw exception with SQLSTATE '01000' | Warning | From HINT text |
Text Example
Section titled “Text Example”Example of using the SQL Statement with Command Type set to Text. This example counts the rows in the actual table. Depending on your logic, different states can be returned.
DO $$ BEGINDECLARE counter integer;BEGINcounter:= 0; SELECT count(*) into counter FROM public."LogEvents" WHERE "ValidationFailed"=true; IF (counter=0) THEN -- OK --return query SELECT 'OK'; ELSEIF (counter<10) THEN -- WARNING RAISE EXCEPTION SQLSTATE '01000' USING HINT = 'Make sure to clean these up manually after inspection of the content within the ValidationFailedText column'; ELSE -- EXCEPTION RAISE EXCEPTION USING HINT = 'Make sure to clean these up manually after inspection of the content within the ValidationFailedText column'; END IF;END;END $$;Next Steps
Section titled “ Next Steps”Related Topics
Section titled “ Related Topics” Secure Custom Database Scripts and Actions
Azure SQL Statements
SQL Statements
Database Monitoring Agent
SQL Categories
Resources
Monitoring Agents
Monitor Views