Skip to content
Nov 3, 2026 - Version 2026.10 has been released
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Internal Function

An optional read-only function that gives Datasentinel access to planner statistics and execution plans without granting SELECT on application tables.

The datasentinel_analytics function gives Datasentinel a safe, read-only window on information that the monitoring user cannot read on its own. No SELECT privilege on application tables is needed.

Objective

The function lets Datasentinel:

  • Read column statistics from the pg_stats view.

  • Read extended statistics definitions from the pg_statistic_ext catalog.

  • Produce the execution plan of a query, without ever running it.

The function is optional. Datasentinel uses it automatically when it is installed. With local agents, upgrade them to version 4.0.0 or later.

Without the function, Datasentinel skips these advanced insights:

  • Table and index bloat estimates.

  • Column statistics.

  • Extended statistics.

  • Live execution plans, in Live360 and AI Connector.

These details enrich the reports and AI Connector analyses. Every other monitoring metric keeps working as normal.

Statistics are collected hourly, with both the agent-based and agentless methods. Before each collection, Datasentinel checks that the function is present in the database and that the monitoring user can execute it. The first hourly pass is not uploaded: the data appears on the platform after the second full hour.

What the function does

The function does not access or return application data (such as table contents).

It only returns metadata and statistics: null fraction, number of distinct values, column width, correlation, and the number of most common values (never the values themselves). Extended statistics are returned as definitions only.

It supports three actions:

Action
Returns

colstats

Column statistics from pg_stats, for all tables or for one table

extstats

Extended statistics definitions (CREATE STATISTICS), for all tables or for one table

explain

The execution plan of one statement, in text format

The explain action is locked down inside the function:

  • It always runs EXPLAIN (ANALYZE off, FORMAT text). The statement is planned, never executed, and the caller cannot add any option.

  • It accepts a single statement. A text with a second statement after a ; is rejected.

  • A generic plan can be requested on PostgreSQL 16 and later.

The function is SECURITY DEFINER: it runs with the privileges of the role that installed it. For this reason, the SQL file revokes the execute privilege from PUBLIC, and the installer grants it only to the datasentinel role.

Extended statistics require PostgreSQL 10 or later.

Deployment

The agent package ships three files in its root directory:

File
Purpose

datasentinel_analytics.sql

The function definition and the REVOKE ... FROM PUBLIC

deploy_datasentinel_function.sh

Installs the function in every application database and grants EXECUTE to datasentinel

remove_datasentinel_function.sh

Removes the function from every application database

Use the files from the agent version you run: they are updated with the agent.

With agentless connections, no agent package is downloaded. The same three files are published in the datasentinel_analytics directory of the public Datasentinel toolkit repository on GitHub. On an on-premises platform, the toolkit is also installed in the home directory of the datasentinel user on the platform server.

Install

Run the installer on the PostgreSQL host, from the directory that holds the SQL file. The optional argument is the PostgreSQL port (default 5432).

The script connects through the local socket with psql, as the current OS user. Set PGHOST, PGUSER and the other PG* variables to connect differently, for example from a remote machine in an agentless setup:

On a cloud-managed instance, where no superuser is available, run the script as the master user.

Run the script again:

  • after creating a new database, which does not get the function otherwise;

  • after an agent upgrade that changes the SQL file.

The script uses CREATE OR REPLACE, so running it again is safe.

Check

In each database, run:

Expected result: one row, with prosecdef, ds_can_execute true and public_can_execute false.

Uninstall

The function is removed from every application database. Datasentinel detects its absence at the next hourly collection, and every other metric keeps working.

Last updated