Endpoints
Schema Operations
Retrieve database schema tree structure
POST
Overview
Fetches the complete schema tree for a PostgreSQL database, including schemas, tables, views, materialized views, and row count estimates. Automatically filters out system schemas (pg_catalog, information_schema).
Request
PostgreSQL server hostname or IP address
PostgreSQL server port number
PostgreSQL username for authentication
PostgreSQL user password
Target database name to fetch schema from
SSL connection mode (
disable, require, prefer)Response
Returns an array containing a single DatabaseInfo object with the schema tree.Database name
Array of SchemaInfo objects
Schema name (e.g.,
public, myschema)Array of TableInfo objects in this schema
Table or view name
Object type:
table, view, or materialized_viewParent schema name
Estimated row count from
pg_class.reltuples (may be undefined for views)Examples
Fetch Schema Tree
Error: Missing Required Fields
Error: Database Connection Failed
Schema Filtering
System schemas are automatically excluded:pg_catalog- PostgreSQL system cataloginformation_schema- SQL standard information schema
/app/api/schema/tree/route.ts:4-6:
Table Type Detection
The endpoint uses PostgreSQL’spg_class.relkind to accurately determine object types:
| relkind | Type | Description |
|---|---|---|
r | table | Regular table |
v | view | View |
m | materialized_view | Materialized view |
p | table | Partitioned table |
/app/api/schema/tree/route.ts:74-82:
Row Count Estimates
Row counts are estimates from PostgreSQL’s statistics, not exact counts:Row counts are estimates updated by
ANALYZE. Run VACUUM ANALYZE for more accurate statistics.Query Optimization
The endpoint executes three optimized queries:- Schemas Query: Fetches schema names from
information_schema.schemata - Tables Query: Retrieves table metadata from
information_schema.tables - Statistics Query: Gets row estimates and relkind from
pg_class
/app/api/schema/tree/route.ts:24-55:
TypeScript Interfaces
From/types/database.ts:1-9:
/types/database.ts:11-19:
Use Cases
- Schema Explorer: Display database structure in tree view
- Table Browser: Navigate schemas and tables
- Data Dictionary: Generate documentation of database objects
- Query Builder: Populate table/column dropdowns
Performance
Typical execution time: 50-200ms for databases with:- 10-50 schemas
- 100-500 tables
- Proper statistics maintained