The metadb.table_update table stores information about table updates, including when each table was last successfully updated and how long the update took. This is particularly useful for monitoring external SQL execution and periodic table transformations.
This table tracks updates for tables created by external SQL execution and some transform operations. It does not track every individual record insert/update from streaming sources.
Check when tables were last updated to ensure data is current:
select schema_name || '.' || table_name as full_table_name, last_update, now() - last_update as time_since_updatefrom metadb.table_updateorder by last_update desc;
Find Stale Tables
Identify tables that haven’t been updated recently:
select schema_name, table_name, last_update, age(now(), last_update) as agefrom metadb.table_updatewhere last_update < now() - interval '24 hours'order by last_update;
Track Update Performance
Find tables that take a long time to update:
select schema_name, table_name, elapsed_real_time, elapsed_real_time / 60.0 as elapsed_minutesfrom metadb.table_updatewhere elapsed_real_time > 30order by elapsed_real_time desc;
Generate Update Report
Create a summary report of all table updates:
select schema_name, count(*) as tables, max(last_update) as most_recent_update, avg(elapsed_real_time) as avg_update_time_seconds, max(elapsed_real_time) as max_update_time_secondsfrom metadb.table_updategroup by schema_nameorder by schema_name;
Check Specific Table Status
Get update information for a specific table:
select last_update, elapsed_real_time, now() - last_update as time_since_update, case when last_update > now() - interval '1 hour' then 'Fresh' when last_update > now() - interval '24 hours' then 'Current' else 'Stale' end as freshness_statusfrom metadb.table_updatewhere schema_name = 'folio' and table_name = 'user_group';
This table is closely integrated with Metadb’s external SQL feature. When external SQL files include the --metadb:table directive, Metadb updates this table after the SQL executes:
-- In your external SQL file:--metadb:table library_patronsdrop table if exists library_patrons;create table library_patrons asselect * from patron_transform;
After this SQL runs, metadb.table_update will contain:
schema_name: The schema where the table was created
table_name: library_patrons
last_update: Timestamp when the SQL completed
elapsed_real_time: How many seconds the SQL took to execute
The --metadb:table directive should not include a schema name. Tables are created in the schema designated for external SQL execution.
You can track performance over time by querying this table regularly:
-- Create a history tablecreate table admin.table_update_history asselect current_timestamp as snapshot_time, *from metadb.table_update;-- Periodically insert snapshotsinsert into admin.table_update_historyselect current_timestamp, *from metadb.table_update;-- Analyze trendsselect table_name, snapshot_time::date as date, avg(elapsed_real_time) as avg_seconds, count(*) as update_countfrom admin.table_update_historywhere table_name = 'library_patrons'group by table_name, snapshot_time::dateorder by date desc;
-- Find tables that haven't updated in expected timeframeselect schema_name || '.' || table_name as table_name, last_update, age(now(), last_update) as overdue_byfrom metadb.table_updatewhere last_update < now() - interval '2 hours'order by last_update;
The metadb.table_update table is managed automatically by Metadb. Do not insert, update, or delete rows manually. The system updates this table after successful table update operations.