Manage and query PostgreSQL databases over local connections. Use for: discovering saved PostgreSQL profiles, connecting to databases, listing and inspecting databases, running SQL queries, finding stored credentials, troubleshooting authentication and connection issues.
.pgpass, environment variables, or connection profileszsh or bashGoal: List all configured PostgreSQL connections and their details.
Steps:
mcp_postgresql_mc_pgsql_list_connection_profilesExample output:
Profile: "Local"
- ID: 7DF9E14E-4178-417B-B073-F4F9382645DD
- Host: 127.0.0.1
- Default DB: nutrivision
Goal: Establish an active connection to a specific database.
Steps:
mcp_postgresql_mc_pgsql_connect with the profile IDConnection ID format: mcp://<profile-id>[/<database-name>]
Example:
Connected: mcp://7DF9E14E-4178-417B-B073-F4F9382645DD/nutrivision
Goal: Enumerate all databases available on the PostgreSQL instance.
Steps:
mcp_postgresql_mc_pgsql_list_databases with the connection IDExample:
Databases:
- karigarverse
- nutrivision
- postgres
- redpetal
- upi_fraud_db
Goal: Execute read-only queries (SELECT, EXPLAIN, SHOW) against the connected database.
Steps:
mcp_postgresql_mc_pgsql_query with connection ID and formatted queryBest practices:
EXPLAIN prefix for performance analysisExample query: Get active user and current database
SELECT
current_user AS current_user,
session_user AS session_user,
current_database() AS current_database;
Example result:
current_user | session_user | current_database
-------------|--------------|------------------
proximus | proximus | nutrivision
Goal: Retrieve table structures, columns, indexes, and relationships.
Steps:
all — returns complete schema contexttables — list of all tablesviews — list of all viewsindexes — list of all indexesfunctions — list of all user-defined functionsmcp_postgresql_mc_pgsql_db_context with connection ID and object typeGoal: Locate credentials stored locally (without exposing sensitive passwords).
Steps:
.pgpass)cat ~/.pgpass
hostname:port:database:username:passwordenv | grep -i postgres
PGPASSWORD, PGUSER, PGHOST, PGPORT, PGDATABASEpsql -U <username> -d <database> -c "SELECT current_user, session_user;"
psql -U <username> -d <database> -c "\du"
Goal: Verify that a connection can be established without executing full queries.
Steps:
mcp_postgresql_mc_pgsql_connect (establishes connection)SELECT version(); to confirm full connectivitymcp_postgresql_mc_pgsql_disconnect with the connection IDGoal: Debug "permission denied" or "password required" errors.
Diagnosis checklist:
Can you connect to postgres database?
psql -U <username> -d postgres.pgpass or environment variables (step 6)Is the username correct?
whoami (your OS user)\du after connectingIs the password required?
~/.pgpass for pre-stored credentialslocalhost or 127.0.0.1), PostgreSQL may use peer or trust authentication (no password needed)Is the database accessible by this role?
\l (in psql)SELECT * FROM information_schema.role_table_grants WHERE grantee='<role>';Check PostgreSQL logs (if local server):
~/Library/Application Support/Postgres/var-*/postgres.log/opt/homebrew/var/postgres/server.log| Tool | Purpose |
|---|---|
mcp_postgresql_mc_pgsql_list_connection_profiles | Discover all saved connection profiles |
mcp_postgresql_mc_pgsql_connect | Establish connection to a database |
mcp_postgresql_mc_pgsql_list_databases | Enumerate databases on a server |
mcp_postgresql_mc_pgsql_query | Execute read-only SQL queries |
mcp_postgresql_mc_pgsql_db_context | Retrieve schema and object metadata |
mcp_postgresql_mc_pgsql_disconnect | Close connection |
| Terminal commands | Find credentials and test CLI access |
.pgpass filepsql -U proximus -d nutrivision -c "\du"db_context| Issue | Solution |
|---|---|
| Connection refused | Check host/port; verify PostgreSQL server is running |
| Authentication failed | Check .pgpass, env vars, or run psql from terminal |
| Database does not exist | List databases first; verify spelling and case sensitivity |
| Query returns empty | Add validation queries to check if data exists before filtering |
| Permission denied | Verify role has SELECT on the table; check role permissions with \dp or GRANT statements |