PostgreSQL MCP Server
Server Configuration
Describes the environment variables required to run the server.
| Name | Required | Description | Default |
|---|---|---|---|
| HOST | No | HTTP bind address | 127.0.0.1 |
| PORT | No | HTTP server port (when TRANSPORT=http) | 3000 |
| PG_HOST | No | PostgreSQL host | localhost |
| PG_PORT | No | PostgreSQL port | 5432 |
| PG_USER | No | PostgreSQL user | postgres |
| TRANSPORT | No | Transport mode: stdio or http | stdio |
| PG_DATABASE | No | Database name | postgres |
| PG_PASSWORD | No | PostgreSQL password | |
| DATABASE_URL | No | Full connection string (overrides all PG_* vars) |
Capabilities
Features and capabilities supported by this server
| Capability | Details |
|---|---|
| tools | {
"listChanged": true
} |
Tools
Functions exposed to the LLM to take actions
| Name | Description |
|---|---|
| pg_list_databasesA | List all non-template databases accessible on the connected PostgreSQL server. Returns database name, encoding, collation, size, and connection limit. Returns: JSON: { databases: DatabaseInfo[], count: number } Markdown: formatted table Errors:
|
| pg_list_schemasA | List all user-defined schemas in the current database (excludes pg_catalog, information_schema, pg_toast). Returns schema name, owner, description, table count, and view count. Returns: JSON: { schemas: SchemaInfo[], count: number } Markdown: formatted table |
| pg_list_tablesA | List all tables (and optionally views) in a PostgreSQL schema with size and row estimates. Args:
Returns: JSON: { tables: TableInfo[], count: number, schema: string } Markdown: formatted table with size and row estimates Note: estimated_rows is approximate (pg_class.reltuples) — use pg_count_rows for exact count. |
| pg_describe_tableA | Full description of a table: columns, data types, constraints, indexes, and foreign keys. Args:
Returns: JSON: { table, schema, columns: ColumnInfo[], foreign_keys: ForeignKeyInfo[], check_constraints, indexes: IndexInfo[] } Markdown: multi-section formatted description Errors:
|
| pg_list_viewsA | List all views and materialized views in a PostgreSQL schema, including their definitions. Args:
Returns: JSON: { views: ViewInfo[], count: number, schema: string } Markdown: formatted table |
| pg_list_functionsA | List all user-defined functions, procedures, aggregates, and window functions in a schema. Args:
Returns: JSON: { functions: FunctionInfo[], count: number, schema: string } Markdown: formatted table with name, type, return type, arguments, language |
| pg_list_indexesA | List indexes in a schema, optionally filtered to a specific table. Args:
Returns: JSON: { indexes: IndexInfo[], count: number } Markdown: formatted table with name, table, type, uniqueness, size, definition |
| pg_list_extensionsA | List all extensions currently installed in the PostgreSQL database. Returns extension name, installed version, default version, and description. Returns: JSON: { extensions: ExtensionInfo[], count: number } Markdown: formatted table |
| pg_queryA | Execute a read-only SQL SELECT query against the PostgreSQL database. Only SELECT, WITH (CTE), TABLE, and EXPLAIN statements are allowed. Any attempt to execute INSERT, UPDATE, DELETE, DDL, or other mutating statements will be rejected. Args:
Returns: JSON: { rows: object[], row_count: number, column_names: string[] } Markdown: formatted table of results Examples:
Errors:
|
| pg_explainA | Show the execution plan for a SQL query using EXPLAIN or EXPLAIN ANALYZE. Use EXPLAIN to see the planned query strategy. Use EXPLAIN ANALYZE to actually execute the query and see real timing and row count statistics (costs real I/O). Args:
Returns: The query plan as text or JSON. Use 'json' format for programmatic parsing. Warning: EXPLAIN ANALYZE actually executes the query, including any side effects. |
| pg_executeA | Execute a non-SELECT SQL statement: INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, TRUNCATE, etc. For DROP, TRUNCATE, or DELETE without a WHERE clause, you must set confirm_destructive: true to confirm you understand these operations are irreversible. Args:
Returns: JSON: { command, rows_affected, duration_ms } Markdown: summary of executed statement Examples:
Warning: Mutations are not automatically wrapped in a transaction. Use BEGIN/COMMIT explicitly for multi-statement transactions. |
| pg_transactionA | Execute multiple SQL statements atomically in a single transaction. All statements succeed or all are rolled back. Ideal for multi-step operations that must be atomic (e.g., insert + update, schema migrations). Args:
Returns: JSON: { results: [{command, rows_affected}], total_duration_ms, rolled_back: false } On error: { error, rolled_back: true, failed_at_index: number } Examples: statements: ["INSERT INTO orders ...", "UPDATE inventory SET qty = qty - 1 WHERE ..."] |
| pg_sample_rowsA | Retrieve a sample of rows from a PostgreSQL table, with optional filtering and column selection. Args:
Returns: JSON: { table, schema, row_count, columns: string[], rows: object[] } Markdown: formatted table of results Security: table and schema names are validated against actual database objects before use. |
| pg_count_rowsA | Get exact row count for a table, optionally with a filter condition. Args:
Returns: JSON: { table, schema, count, where_clause } Markdown: formatted count with filter info Note: For large tables (>10M rows), pg_table_stats provides a faster estimated count. |
| pg_table_statsA | Get detailed statistics for tables: size, live/dead rows, vacuum/analyze info, scan counts. Useful for identifying bloated tables, missing vacuums, or underused indexes. Args:
Returns: JSON: { stats: TableStats[], count: number } Markdown: formatted table with size, rows, vacuum dates, scan counts Note: Requires pg_stat_user_tables access. Row counts are from pg_stat_user_tables (updated by autovacuum/analyze) — use pg_count_rows for exact counts. |
| pg_server_infoA | Get detailed PostgreSQL server information: version, connection details, memory settings, WAL configuration, and runtime parameters. Returns: JSON: { version, current_database, current_user, settings: {...}, uptime } Markdown: formatted multi-section report Useful for understanding the server environment, verifying connection details, and checking key configuration values. |
| pg_list_sequencesA | List all sequences in a schema with their configuration and current state. Args:
Returns: JSON: { sequences: SequenceInfo[], count: number } Markdown: table with name, type, range, increment, current value, and owning column Note: last_value reflects the last allocated value, not necessarily the next one to be issued. |
| pg_list_triggersA | List all triggers in a schema, optionally filtered by table. Args:
Returns: JSON: { triggers: TriggerInfo[], count: number } Markdown: table with trigger name, table, event, timing, orientation, and statement |
| pg_search_objectsA | Search across all database objects (tables, views, functions, indexes, sequences, constraints) by name pattern. Args:
Returns: JSON: { matches: SearchResult[], count: number } Markdown: grouped results by type Examples:
|
| pg_get_ddlA | Get the CREATE statement (DDL) for a table, view, materialized view, function, or index. Args:
Returns: JSON: { schema, object_name, object_type, ddl: string } Markdown: formatted SQL code block Useful for understanding table structure, reproducing objects in other environments, or code review. |
| pg_list_locksA | Show currently active locks in the database, including waiting queries. Useful for debugging lock contention, deadlocks, and long-running transactions. Args:
Returns: JSON: { locks: LockInfo[], blocking_pairs: [{blocker_pid, blocked_pid}] } Markdown: lock table with PID, query, lock type, relation, and wait status Note: Requires sufficient privileges to view pg_stat_activity. |
| pg_active_queriesA | List all currently running queries in the database (excludes idle connections and the MCP server itself). Args:
Returns: JSON: { queries: ActiveQuery[], count: number } Markdown: table with PID, user, state, wait event, duration, query text Useful for finding long-running queries, blocked transactions, and identifying performance bottlenecks. |
| pg_slow_queriesA | Analyze slow queries using the pg_stat_statements extension. Shows queries ranked by mean execution time. Requires the pg_stat_statements extension to be installed and enabled. Args:
Returns: JSON: { queries: SlowQuery[], count: number } Markdown: table with calls, mean/total time, % of total, cache hit %, query text Errors:
|
| pg_index_usageA | Show index scan counts and tuple statistics to identify unused or underused indexes. Indexes with 0 scans that are not primary keys waste storage and slow writes — candidates for removal. Args:
Returns: JSON: { indexes: IndexUsage[], count: number } Markdown: table sorted by scan count ascending (least used first) Note: Statistics reset on pg_stat_reset() or server restart. Low scans on a new server may not mean unused. |
| pg_bloat_reportA | Identify tables with high dead-tuple ratios that need VACUUM or AUTOVACUUM attention. Dead rows accumulate from UPDATE and DELETE operations. High dead% degrades query performance and wastes storage. Tables over ~20% dead tuples should be vacuumed. Args:
Returns: JSON: { tables: BloatInfo[], count: number } Markdown: table sorted by dead% descending, with last vacuum dates |
| pg_replication_statusA | Show the status of all streaming replication standbys connected to this primary, including replay lag. Only meaningful on a primary server with active streaming replication. Returns: JSON: { replicas: ReplicaInfo[], is_standby: boolean, lsn: string } Markdown: replica table with address, state, lag size, sync state Useful for monitoring replication health and identifying lagging standbys. |
| pg_list_typesA | List all user-defined types in a schema: enums, composite types, domains, and range types. Args:
Returns: JSON: { types: TypeInfo[], count: number } Markdown: table with type name, category, enum values (for enums), base type (for domains) Examples:
|
| pg_list_grantsA | Show all privileges granted on tables, views, sequences, and functions in a schema. Args:
Returns: JSON: { grants: GrantInfo[], count: number } Markdown: table with grantor, grantee, object, privilege type, and grantable flag Useful for security audits and understanding who has access to what. |
| pg_list_policiesA | List all Row Level Security (RLS) policies in a schema, including USING and WITH CHECK expressions. Args:
Returns: JSON: { policies: PolicyInfo[], count: number, rls_enabled_tables: string[] } Markdown: policy table with name, command, roles, permissive flag, and filter expressions Note: Also shows which tables have RLS enabled even if no policies are defined. |
| pg_list_partitionsA | List all partitioned tables and their child partitions with bounds, size, and row estimates. Args:
Returns: JSON: { partitions: PartitionInfo[], parent_tables: string[] } Markdown: grouped by parent table, showing each partition's bounds and size |
| pg_copy_csvA | Execute a SELECT query and return the results formatted as CSV with headers. Args:
Returns: CSV text with header row. Suitable for copy-paste into spreadsheets or piping to files. Errors:
|
| pg_kill_queryA | Cancel or terminate a PostgreSQL backend process by PID. Two modes:
Args:
Returns: Whether the signal was successfully sent. Note: You cannot cancel/terminate your own backend or superuser backends without superuser privileges. |
| pg_list_rolesA | List all PostgreSQL roles with their attributes, privileges, and group memberships. Returns both login roles (users) and group roles. Shows superuser status, replication, login capability, connection limits, password expiry, and role membership graph. Args:
Returns: JSON: { roles: RoleInfo[], count: number } Markdown: table with all role attributes + membership info Useful for access audits, permission reviews, and understanding role hierarchy. |
| pg_list_settingsA | Search and inspect PostgreSQL runtime settings from pg_settings. Args:
Returns: JSON: { settings: SettingInfo[], count: number } Markdown: table with name, current value, unit, source, context, description Common categories: Memory, Connections and Authentication, WAL, Query Tuning, Autovacuum, Logging, Lock Management, Replication, Resource Usage. Note: 'context' shows where the setting can be changed:
|
| pg_vacuumA | Execute VACUUM, VACUUM ANALYZE, or VACUUM FULL on a table to reclaim dead-tuple storage. Modes:
Args:
Returns: Duration and confirmation of completion. Warning: VACUUM FULL acquires an exclusive lock — all queries on the table will block until it completes. Use during maintenance windows only. |
| pg_connection_statsA | Show a summary of current connections grouped by database, user, application, and state. Useful for monitoring connection pool utilization, finding idle connections, and detecting connection leaks from specific applications. Args:
Returns: JSON: { summary: ConnectionStat[], total_connections: number, max_connections: string, usage_pct: number } Markdown: grouped connection count with waiting and max idle age Note: Excludes the MCP server's own backend connection from counts. |
Prompts
Interactive templates invoked by user choice
| Name | Description |
|---|---|
No prompts | |
Resources
Contextual data attached and managed by the client
| Name | Description |
|---|---|
No resources | |
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/foxter-io/mcp-postgresql'
If you have feedback or need assistance with the MCP directory API, please join our Discord server