Skip to content

timescale/pg-aiguide / skills/schema-exploration

schema-exploration

Verified

Explore an existing PostgreSQL database before answering questions about its data or writing SQL. Use this skill whenever a user asks for a query or a data-backed answer against an unfamiliar schema (counts, missing or failed records, recent changes), asks where a business concept lives, or asks how tables, joins, views, routines, triggers, RLS, or extensions work. Find the relevant objects with read-only pg_catalog queries, then request approval before inspecting data-derived statistics or rows. Not a schema-design or migration guide.

references/triggers.md

View on GitHub
# Triggers on a relation

Inspect triggers only on a relevant relation. `$1` = schema name; `$2` = relation name. PostgreSQL 18 target; fields used are also available in PostgreSQL 14–17.

```sql
select
  t.tgname as trigger_name
, t.tgisinternal as internal
, t.tgenabled as enabled_mode
, pg_catalog.pg_get_triggerdef(t.oid, true) as definition
, fn.nspname as function_schema
, p.proname as function_name
, pg_catalog.pg_get_function_identity_arguments(p.oid) as function_identity_arguments
, pg_catalog.obj_description(t.oid, 'pg_trigger') as comment
from pg_catalog.pg_trigger t
join pg_catalog.pg_class c on c.oid = t.tgrelid
join pg_catalog.pg_namespace n on n.oid = c.relnamespace
join pg_catalog.pg_proc p on p.oid = t.tgfoid
join pg_catalog.pg_namespace fn on fn.oid = p.pronamespace
where n.nspname = $1
  and c.relname = $2
order by t.tgisinternal, t.tgname
;
```

`tgenabled`: `O` = origin/local mode, `R` = replica mode, `A` = always, `D` = disabled. `O` does not mean it always fires: session replication role matters. Internal triggers often implement FK constraints; do not mistake them for custom business logic. Use the definition to inspect event, timing, row/statement level, `WHEN`, transition tables, and column restrictions. Trigger naming order can affect execution when multiple triggers of the same kind fire; do not infer order from creation dates. Partitioned tables and their partitions can have cloned triggers: inspect the actual relation of interest. Read the target function using [routines](routines.md), never by causing a write. Definition and enabled state do not prove a trigger fired historically.
deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall