Database Query Monitor

Content Type: Module
Categories: Utility,Tracing,Connectors

Overview

Database Query Monitor is a production-grade Mendix module that gives developers and administrators real-time visibility into active database queries and the ability to terminate problematic sessions — all from within your Mendix application.

The Problem

Long-running or stuck database queries can silently degrade application performance, lock critical tables, and consume server resources. Without direct database access, Mendix developers often have no way to identify or stop these queries from the application layer.

The Solution

This module provides two Java Actions that connect to your database using standard JDBC credentials and return actionable diagnostics:

  • GetLongRunningQueries — Retrieves all active queries exceeding a configurable time threshold. Returns the process ID, elapsed duration, session state, full SQL text, database username, and application name.
  • KillQuery — Terminates a specific database session by its process ID securely and immediately.

Supported Databases

The module automatically detects the database engine from the JDBC connection URL and executes the appropriate dialect-specific query:

  • PostgreSQL (pg_stat_activity)
  • Microsoft SQL Server (Dynamic Management Views)
  • MySQL (Performance Schema with processlist fallback)
  • MariaDB (Performance Schema with processlist fallback)
  • Oracle Database (v$session / v$sql)

Security

All termination commands are protected against SQL injection through strict input validation — parameterized queries for PostgreSQL, integer parsing for SQL Server/MySQL/MariaDB, and regex validation for Oracle session identifiers.

MySQL/MariaDB Advanced Feature

Unlike standard process monitoring, this module extracts the parent-level stored procedure or function call (e.g., SELECT long_running_function()) rather than showing internal child statements (e.g., DO SLEEP()). It achieves this by querying Performance Schema at nesting level zero, with automatic fallback to the standard processlist if permissions are restricted.

Requirements

  • Place the appropriate JDBC driver JAR file in your project's userlib/ folder for your target database.
  • Ensure the database user has sufficient privileges to query active sessions and terminate connections.
  • Compatible with Mendix 9, 10, and 11.


Documentation

Typical usage scenario

Performance Monitoring & Diagnostics Use this module when you need to identify and resolve database performance bottlenecks directly from your Mendix application. Common scenarios include:

  • Production troubleshooting: An application is running slowly and you suspect a long-running or stuck database query is consuming resources. Use GetLongRunningQueries to instantly identify the problematic query, view its full SQL text, and determine how long it has been running.
  • DBA operations from Mendix: Administrators can monitor active database sessions and terminate unresponsive queries without needing direct database console access (e.g., pgAdmin, SQL Server Management Studio, or MySQL Workbench).
  • Scheduled health checks: Build a microflow that periodically calls GetLongRunningQueries and sends an email or logs a warning when any query exceeds a critical threshold.
  • Multi-database environments: Organizations running multiple database engines (e.g., PostgreSQL for one app and SQL Server for another) can use a single module to monitor all of them by simply providing different JDBC connection URLs.


Features and limitations

  • Supports 5 database engines: PostgreSQL, Microsoft SQL Server, MySQL, MariaDB, and Oracle Database.
  • Automatically detects the database type from the JDBC connection URL — no manual configuration needed.
  • Returns detailed query information: Process ID, Duration, State, Full SQL Text, Username, and Application Name.
  • MySQL/MariaDB: Extracts the parent-level stored procedure call instead of internal child statements using Performance Schema analysis, with automatic fallback to processlist.
  • SQL injection protected: Uses parameterized queries (PostgreSQL), strict integer parsing (SQL Server, MySQL, MariaDB), and regex validation (Oracle) for all termination commands.
  • Compatible with Mendix 9, 10, and 11.

Limitations

  • The module opens direct JDBC connections using the provided credentials. It does not use the Mendix runtime's internal connection pool.
  • SAP HANA is not currently supported.
  • The KillQuery action requires the database user to have elevated privileges (e.g., processadmin for SQL Server, SUPER for MySQL, ALTER SYSTEM for Oracle).
  • Oracle PID format must be in sid,serial# format (e.g., 123,45678).


Dependencies

JDBC Driver JAR Files

Place the required driver JAR file in your project's userlib/ folder based on your target database:

No other Mendix Marketplace modules are required.


Installation

  1. Download and import the module (.mpk) into your Mendix project via App Explorer > Import Module Package.
  2. Download the appropriate JDBC driver JAR file for your database (see Dependencies section above).
  3. Place the JAR file in your project's userlib/ folder.
  4. Clean your project deployment directory (Project > Clean Deployment Directory) and redeploy.
  5. The module provides two Java Actions: GetLongRunningQueries and KillQuery. Call them from your microflows by providing the JDBC URL, username, password, and threshold.


Configuration

Java Action Parameters

GetLongRunningQueries:

  • dbUrl — JDBC connection string (e.g., jdbc:postgresql://localhost:5432/mydb)
  • dbUsername — Database username with read access to system views
  • dbPassword — Database password
  • thresholdSeconds — Minimum query duration in seconds to filter results

KillQuery:

  • dbUrl — Same JDBC connection string
  • dbUsername — Database username with termination privileges
  • dbPassword — Database password
  • pid — Process ID returned by GetLongRunningQueries (for Oracle, use sid,serial# format)



Releases

Version: 1.0.0
Framework Version: 9.24.4
Release Notes:

Initial Release — Database Query Monitor v1.0.0

A production-grade Java Action module to monitor and terminate long-running database queries in real-time from your Mendix application.

Supported Databases:

  • PostgreSQL
  • Microsoft SQL Server
  • MySQL
  • MariaDB
  • Oracle Database

Key Features:

  • Automatically detects the database engine from the JDBC connection URL.
  • Retrieves active queries exceeding a configurable time threshold (in seconds).
  • Returns query details including PID, duration, state, SQL text, username, and application name.
  • Securely terminates long-running queries with SQL injection protection (parameterized queries, strict integer parsing, and regex validation).
  • MySQL/MariaDB: Extracts parent-level stored procedure calls using Performance Schema with automatic fallback to processlist.

Java Actions Included:

  • GetLongRunningQueries — Retrieves all active queries exceeding the threshold.
  • KillQuery — Terminates a specific database session by PID.

Requirements:

  • Place the appropriate JDBC driver JAR in your project's userlib/ folder for your target database.
  • Compatible with Mendix 9, 10, and 11.