Query, explore, and manage the workspace PostgreSQL database. Use this skill when you needs to inspect schemas, list tables, browse data, run SQL queries, create or alter tables, insert/update/delete rows, or perform any database operation.
The workspace has a PostgreSQL 17 database (clwdb). Interact with it using the bundled Python scripts in scripts/.
All scripts are self-contained (only need psycopg2, pre-installed in sandbox). Connection env vars (POSTGRES_HOST, POSTGRES_PORT, POSTGRES_DB, POSTGRES_USER, POSTGRES_PASSWORD) are injected automatically.
All scripts connect directly via psycopg2 — no external library dependencies. Run them in the sandbox with python3.
| Script | Purpose | Usage |
|---|---|---|
db_introspect.py | Full database report (all schemas, tables, columns) | python3 scripts/db_introspect.py |
list_schemas.py | List schemas | python3 scripts/list_schemas.py |
list_tables.py | List tables + row counts | python3 scripts/list_tables.py [schema] |
describe_table.py | Columns, types, indexes, foreign keys | python3 scripts/describe_table.py <table> [schema] |
preview_table.py | Quick data peek | python3 scripts/preview_table.py <table> [limit] [schema] |
run_query.py | Run any SQL, formatted output | python3 scripts/run_query.py "<sql>" |
db_stats.py | DB size, table sizes, connections | python3 scripts/db_stats.py |
search_data.py | Search text across all tables | python3 scripts/search_data.py <term> [schema] |
export_csv.py | Export table or query to CSV | python3 scripts/export_csv.py <table> [file] [schema] |
import_csv.py | Import CSV into table (auto-creates) | python3 scripts/import_csv.py <csv> <table> [schema] |
Default schema is always public unless specified.
python3 scripts/db_introspect.py — get the full picturepython3 scripts/describe_table.py <table> — drill into a tablepython3 scripts/preview_table.py <table> — see sample datapython3 scripts/run_query.py "SELECT id, name FROM public.users WHERE active = true LIMIT 20"
python3 scripts/run_query.py "CREATE TABLE IF NOT EXISTS public.events (id SERIAL PRIMARY KEY, name TEXT NOT NULL, payload JSONB, created_at TIMESTAMPTZ DEFAULT NOW())"
python3 scripts/import_csv.py /workspace/data.csv events
Auto-creates the table if it doesn't exist. Appends rows if it does.
python3 scripts/export_csv.py users /workspace/users_backup.csv
python3 scripts/export_csv.py --sql "SELECT * FROM public.orders WHERE total > 100" /workspace/big_orders.csv
python3 scripts/search_data.py "[email protected]"
Searches all text columns across all tables in the schema.
python3 scripts/db_stats.py
%s placeholders + params). Never interpolate user input directly into SQL strings.run_query.py caps output at 500 rows. For larger exports use scripts/export_csv.py or paginate with OFFSET.psycopg2 directly with explicit conn.commit() / conn.rollback().public as the default schema unless the strictly neccessary.