Get the FREE Ultimate OpenClaw Setup Guide →

PostgreSQL

Official

MCP server for PostgreSQL database access - query and explore database schemas.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio modelcontextprotocol-server-postgres npx -y @modelcontextprotocol/server-postgres

How to use

The PostgreSQL MCP server enables seamless access to PostgreSQL databases, allowing you to query and explore database schemas effortlessly. With its built-in capabilities, you can execute read-only SQL queries to retrieve data without altering the database state, making it an essential tool for developers looking to integrate PostgreSQL databases into their applications.

Once connected to the PostgreSQL MCP server, you can utilize the query tool to execute your read-only SQL queries. This allows you to pull data from specific tables or explore database schemas by writing SQL commands. For optimal interaction, focus on well-structured SELECT statements to retrieve the information you need, ensuring to follow your database's schema conventions.

How to install

Prerequisites

Before installing the PostgreSQL MCP server, ensure that you have Node.js installed on your machine. You can verify your Node.js installation by running node -v in your terminal.

Option A: Quick Start with npx

To quickly start using the PostgreSQL MCP server, you can use the following command:

npx -y @modelcontextprotocol/server-postgres  

Option B: Global Install Alternative

If you prefer to install the package globally for easier access, run:

npm install -g @modelcontextprotocol/server-postgres  

After installation, you can start the server by running server-postgres in your terminal.

Additional notes

When configuring the PostgreSQL MCP server, make sure to set your database connection parameters correctly, such as DATABASE_URL, which typically includes the username, password, and database name. A common gotcha is forgetting to grant the necessary permissions to the user specified in your connection string, which can result in access errors when executing queries.

Available tools

query

Execute a read-only SQL query

Related MCP Servers

Sponsor this space

Reach thousands of developers