::: tip New in 3.6.0 PostgreSQL Stats endpoints were added in version 3.6.0. :::
Exposes PostgreSQL statistics through HTTP endpoints for monitoring and debugging. Provides access to pg_stat_user_functions, pg_stat_user_tables, pg_stat_user_indexes, and pg_stat_activity.
{
"Stats": {
"Enabled": false,
"CacheDuration": "5 seconds",
"RateLimiterPolicy": null,
"ConnectionName": null,
"RequireAuthorization": false,
"AuthorizedRoles": [],
"OutputFormat": "html",
"SchemaSimilarTo": null,
"RoutinesStatsPath": "/stats/routines",
"TablesStatsPath": "/stats/tables",
"IndexesStatsPath": "/stats/indexes",
"ActivityPath": "/stats/activity"
}
}Returns data from pg_stat_user_functions including:
- Call counts
- Total execution time
- Self execution time
::: warning PostgreSQL Configuration Required
Routine statistics require track_functions to be enabled in PostgreSQL:
ALTER SYSTEM SET track_functions = 'all';
SELECT pg_reload_conf();Or set track_functions = 'all' in postgresql.conf and restart/reload.
:::
Returns data from pg_stat_user_tables including:
- Tuple counts (live, dead, inserted, updated, deleted)
- Table sizes
- Sequential and index scan counts
- Last vacuum and analyze timestamps
Returns data from pg_stat_user_indexes including:
- Index scan counts
- Tuples read and fetched
- Index definitions
- Index sizes
Returns data from pg_stat_activity showing:
- Active sessions
- Currently running queries
- Wait events
- Session state and duration
::: danger Security Warning
The activity endpoint shows currently running queries which may contain sensitive data (passwords in plaintext queries, personal information, etc.). Always enable RequireAuthorization in production.
:::
{
"Stats": {
"Enabled": true,
"OutputFormat": "html"
}
}Returns an HTML table that is Excel-compatible for direct browser copy-paste. Ideal for quick debugging and analysis.
{
"Stats": {
"Enabled": true,
"OutputFormat": "json"
}
}Returns a JSON array suitable for programmatic access and integration with monitoring tools.
::: tip New in 3.8.0
The format query string override was added in version 3.8.0.
:::
The configured OutputFormat can be overridden per-request using the format query string parameter. Valid values are html and json:
GET /stats/routines?format=json
GET /stats/tables?format=html
This allows a single stats deployment to serve both human-readable HTML and machine-readable JSON without changing the server configuration.
{
"Stats": {
"Enabled": true,
"RequireAuthorization": true
}
}Any authenticated user can access stats endpoints.
{
"Stats": {
"Enabled": true,
"RequireAuthorization": true,
"AuthorizedRoles": ["admin", "dba"]
}
}Only users with admin or dba roles can access stats endpoints.
::: tip
Stats endpoints can reveal sensitive information about your database including table sizes, query patterns, and active sessions. Always enable RequireAuthorization in production environments.
:::
Cache responses to reduce database load:
{
"Stats": {
"Enabled": true,
"CacheDuration": "10 seconds"
}
}The value uses PostgreSQL interval format:
"5 seconds"or"5s""1 minute"or"1min""30s"
Set to null to disable caching (queries the database on every request).
Query strings are ignored to prevent cache-busting.
Apply a rate limiter policy to prevent abuse:
{
"RateLimiterOptions": {
"Enabled": true,
"Policies": {
"stats-limit": {
"PermitLimit": 10,
"Window": "1 minute"
}
}
},
"Stats": {
"Enabled": true,
"RateLimiterPolicy": "stats-limit"
}
}Filter statistics by schema using PostgreSQL SIMILAR TO pattern:
{
"Stats": {
"Enabled": true,
"SchemaSimilarTo": "public|myapp%"
}
}This example includes:
- The
publicschema - Schemas starting with
myapp(e.g.,myapp,myapp_v1,myapp_archive)
When null, all schemas are included.
Query stats from a specific database or with different credentials:
{
"ConnectionStrings": {
"Default": "Host=primary;Database=myapp;Username=app;...",
"Stats": "Host=replica;Database=myapp;Username=readonly;..."
},
"Stats": {
"Enabled": true,
"ConnectionName": "Stats"
}
}Useful for:
- Using read-only credentials
- Querying a read replica
- Separating stats queries from application traffic
{
"Stats": {
"Enabled": true,
"RoutinesStatsPath": "/api/stats/functions",
"TablesStatsPath": "/api/stats/tables",
"IndexesStatsPath": "/api/stats/indexes",
"ActivityPath": "/api/stats/sessions"
}
}{
"Stats": {
"Enabled": true,
"OutputFormat": "html"
}
}{
"Stats": {
"Enabled": true,
"RequireAuthorization": true,
"AuthorizedRoles": ["admin"],
"CacheDuration": "30 seconds",
"OutputFormat": "json"
}
}{
"Stats": {
"Enabled": true,
"RequireAuthorization": true,
"AuthorizedRoles": ["monitoring"],
"OutputFormat": "json",
"CacheDuration": "10 seconds",
"RateLimiterPolicy": "monitoring"
}
}{
"Stats": {
"Enabled": true,
"RequireAuthorization": true,
"SchemaSimilarTo": "public|api%",
"OutputFormat": "html"
}
}- Rate Limiter - Configure rate limiting policies
- Authentication - Configure authentication for secured access
- Health Checks - Health check endpoints
- Logging - Configure logging for monitoring
- Connection - Database connection settings
