pg_analyze_database
Analyze PostgreSQL database configuration and performance
Query, change and administer a PostgreSQL database — schema, indexes, RLS, roles, query plans — with a security mode that decides how much of that is switched on.
LABSCO SUMMARY
Most database servers hand a model everything the connection role can do; this one splits the difference into two switches — security mode for writes and DDL, --allow-destructive for drops, resets and raw SQL — so exploring a production database and administering it are different configurations of the same install. The rest of the design follows from that: structured where predicates instead of string fragments, unknown fields rejected before a connection is opened, and per-call connection strings off by default so a tool call cannot point itself at a different database.
A PostgreSQL administration surface built as a small number of meta-tools: one tool per subject area, with an operation argument selecting what it does. It starts read-only, and writes, DDL and arbitrary SQL are unlocked by explicit flags.
A reachable PostgreSQL server and Node.js 18.0.0 or higher; it runs as npx @henkey/postgres-mcp-server, or from the Docker image. The connection string belongs to the server, not to the tools: --connection-string or POSTGRES_CONNECTION_STRING, and per-call connectionString arguments are refused unless you pass --allow-tool-connection-string. From 2.0.0 the server starts in readonly mode — mutations, DDL, role administration, import and export and arbitrary SQL need --security-mode write, admin or unsafe, and drops, resets, broad grants and arbitrary SQL additionally need --allow-destructive. String where clauses are rejected in favour of structured predicates, and unknown fields in a tool call fail before a connection is opened.
One command — npm install -g @henkey/postgres-mcp-server
USE CASES
Leave the default read-only mode on, give the server one connection string, and ask questions — selects, counts, schema and monitoring all work; nothing writes.
Get the plan with analyze and buffers, look at the slow query list and statistics next to it, then check whether the indexes involved are used at all.
Create the table, put its foreign keys and constraints in place with the right delete behaviour, and index the columns you will filter on.
Enable Row-Level Security, write the policy with its using and check expressions, and create the role it applies to with only the grants it needs.
Copy it directly between two connections with a filter, or export to CSV or JSON and import on the other side.
Look at live activity with locks, running queries and replication included, and run the issue-specific debugging pass alongside it.
Counted once with only startup setup. Other versions, modes or optional credentials may expose a different list.
pg_analyze_databaseAnalyze PostgreSQL database configuration and performance
pg_copy_between_databasesCopy data between two databases
pg_debug_databaseDebug common PostgreSQL issues
pg_execute_mutationExecute data modification operations (INSERT/UPDATE/DELETE/UPSERT) - operation="insert/update/delete/upsert" with table and data. Examples: operation="insert", table="users", data={"name":"John","email":"john@example.com"}
pg_execute_queryExecute SELECT queries and data retrieval operations - operation="select/count/exists" with query and optional parameters. Examples: operation="select", query="SELECT * FROM users WHERE created_at > $1", parameters=["2024-01-01"]
pg_execute_sqlExecute arbitrary SQL statements - sql="ANY_VALID_SQL" with optional parameters and transaction support. Examples: sql="CREATE INDEX ...", sql="WITH complex_cte AS (...) SELECT ...", transactional=true
pg_export_table_dataExport table data to JSON or CSV format
pg_import_table_dataImport data from JSON or CSV file into a table
pg_manage_commentsManage PostgreSQL object comments - get, set, remove comments on tables, columns, functions, and other database objects. Examples: operation="get" with objectType="table", objectName="users", operation="set" with comment text, operation="bulk_get" for discovery
pg_manage_constraintsManage PostgreSQL constraints - get, create foreign keys, drop foreign keys, create constraints, drop constraints. Examples: operation="get" to list constraints, operation="create_fk" with constraintName, tableName, columnNames, referencedTable, referencedColumns
pg_manage_functionsManage PostgreSQL functions - get, create, or drop functions with a single tool. Examples: operation="get" to list functions, operation="create" with functionName="test_func", parameters="" (empty for no params), returnType="TEXT", functionBody="SELECT 'Hello'"
pg_manage_indexesManage PostgreSQL indexes - get, create, drop, reindex, and analyze usage with a single tool. Examples: operation="get" to list indexes, operation="create" with indexName, tableName, columns, operation="analyze_usage" for performance analysis
pg_manage_queryManage PostgreSQL query analysis and performance - operation="explain" for EXPLAIN plans, operation="get_slow_queries" for slow query analysis, operation="get_stats" for query statistics, operation="reset_stats" for clearing statistics
pg_manage_rlsManage PostgreSQL Row-Level Security - enable/disable RLS and manage policies. Examples: operation="enable" with tableName="users", operation="create_policy" with tableName, policyName, using, check
pg_manage_schemaManage PostgreSQL schema - get schema info, create/alter tables, manage enums. Examples: operation="get_info" for table lists, operation="create_table" with tableName and columns, operation="get_enums" to list enums, operation="create_enum" with enumName and values
pg_manage_triggersManage PostgreSQL triggers - get, create, drop, and enable/disable triggers. Examples: operation="get" to list triggers, operation="create" with triggerName, tableName, functionName, operation="drop" with triggerName and tableName, operation="set_state" with triggerName, tableName, enable
pg_manage_usersManage PostgreSQL users and permissions - create, drop, alter users, grant/revoke permissions. Examples: operation="create" with username="testuser", operation="grant" with username, permissions, target, targetType
pg_monitor_databaseGet real-time monitoring information for a PostgreSQL database
BEFORE YOU INSTALL
18 tools when we connected. In the default readonly mode every tool is listed, but pg_execute_mutation, pg_execute_sql, pg_manage_schema, pg_manage_users, pg_import_table_data and others are refused at call time. An unknown enabledTools entry stops startup.
POSTGRES_CONNECTION_STRING in your environment
CONTEXT COST
Rated by the size of the 18 tool definitions that ride along on every turn, not by how many there are
INSTALLATION
npm install -g @henkey/postgres-mcp-serverhttps://cursor.com/install-mcp?name=postgresql-mcp&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBoZW5rZXkvcG9zdGdyZXMtbWNwLXNlcnZlciIsIi0tY29ubmVjdGlvbi1zdHJpbmciLCJwb3N0Z3Jlc3FsOi8vdXNlcjpwYXNzd29yZEBob3N0OnBvcnQvZGF0YWJhc2UiXX0=npx -y @smithery/cli install @HenkDz/postgresql-mcp-server --client claude{
"mcpServers": {
"postgresql-mcp": {
"command": "npx",
"args": [
"@henkey/postgres-mcp-server",
"--connection-string",
"postgresql://<YOUR_DB_USER>:<YOUR_DB_PASSWORD>@<YOUR_DB_HOST>:<YOUR_DB_PORT>/<YOUR_DB_NAME>"
]
}
}
}{
"mcpServers": {
"postgresql-mcp": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"POSTGRES_CONNECTION_STRING",
"henkey/postgres-mcp:latest"
],
"env": {
"POSTGRES_CONNECTION_STRING": "postgresql://<YOUR_DB_USER>:<YOUR_DB_PASSWORD>@<YOUR_DB_HOST>:<YOUR_DB_PORT>/<YOUR_DB_NAME>"
}
}
}
}