Skip to main content

mdblog()

Returns recent log messages from the Metadb system. You can optionally specify a time interval to filter logs.

Signature

interval
interval
The time period to retrieve logs from (e.g., ‘1 hour’, ‘30 minutes’). If omitted, returns logs from the past 24 hours.
Return Type
table
Returns a table with the following columns:
log_time
timestamptz(3)
The timestamp when the log entry was created (with millisecond precision)
error_severity
text
The severity level of the log message: INFO, WARNING, ERROR, or FATAL (ordered from least to most severe)
message
text
The log message content

Usage

-- Logs from past hour
select * from mdblog('1 hour');

-- Logs from past 24 hours (default)
select * from mdblog();

-- Logs from past 30 minutes
select * from mdblog('30 minutes');

Example Output

          log_time          | error_severity |              message              
----------------------------+----------------+-----------------------------------
 2024-03-11 10:15:23.456-05 | INFO           | Stream processor started
 2024-03-11 10:20:45.123-05 | WARNING        | High memory usage detected
 2024-03-11 10:25:10.789-05 | ERROR          | Connection timeout to Kafka broker
(3 rows)

Use Cases

Check recent errors when investigating system problems:
select * from mdblog('1 hour')
where error_severity in ('ERROR', 'FATAL')
order by log_time desc;
Monitor warning messages to catch potential issues early:
select log_time, message
from mdblog('24 hours')
where error_severity = 'WARNING';
Search logs for specific events or patterns:
select * from mdblog('1 hour')
where message like '%snapshot%'
order by log_time;
Log entries are also stored in the metadb.log table. Use mdblog() for quick access to recent entries, or query metadb.log directly for more advanced filtering.

ps()

Returns information about currently running query processes, similar to the Unix ps command.

Signature

Return Type
table
Returns a table with the following columns:
dbname
text
The database name the query is running against
username
text
The user executing the query
state
text
The current state of the process (e.g., ‘active’, ‘idle’, ‘idle in transaction’)
realtime
text
The elapsed wall-clock time the query has been running
query
text
The SQL query text being executed

Usage

select * from ps();

Example Output

  dbname  | username | state  | realtime |              query               
----------+----------+--------+----------+----------------------------------
 metadb   | admin    | active | 00:01:23 | select * from library.patron__
 metadb   | analyst  | idle   | 00:00:00 | 
(2 rows)

Use Cases

See which queries are currently executing:
select username, realtime, query
from ps()
where state = 'active';
Identify queries that have been running for an extended period:
select * from ps()
where state = 'active'
order by realtime desc;
See what each user is currently doing:
select username, count(*) as connections, 
       count(*) filter (where state = 'active') as active_queries
from ps()
group by username;
The ps() function shows processes across all databases. Filter by dbname if you only want to see activity in a specific database.

Severity Levels

Log messages in mdblog() use the following severity levels (from least to most severe):
INFO
Informational messages about normal operations (e.g., “Stream processor started”)
WARNING
Warnings about potential issues that don’t prevent operation (e.g., “High memory usage”)
ERROR
Errors that affect specific operations but don’t crash the system (e.g., “Connection timeout”)
FATAL
Critical errors that may cause system shutdown or data loss

metadb.log Table

Query the complete log history

System Info Functions

Get version and user information

metadb.table_update

Track table update statistics

Build docs developers (and LLMs) love