PostgreSQL Read-Only MCP Server
Used for configuration management, storing database credentials, SSH tunnel settings, and RDS connection information in a secure location outside the repository.
Required runtime environment for the MCP server, specifically version 24 or higher.
Required package manager for installing dependencies and building the MCP server.
Provides read-only access to PostgreSQL databases through tools for executing queries, listing tables, describing schemas, analyzing data quality, finding relationships, and generating query execution plans.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@PostgreSQL Read-Only MCP Servershow me the top 10 customers by total purchases"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
PostgreSQL Read-Only MCP Server
A secure MCP (Model Context Protocol) server that provides read-only access to PostgreSQL databases through an SSH tunnel.
Features
Secure SSH Tunnel: Connects to PostgreSQL through encrypted SSH tunnel
Read-Only Enforcement: All queries run in read-only transactions
Connection Pooling: Efficient database connection management
Query Timeout: 15-second timeout for all operations
Comprehensive Tools: Query, list tables, describe schemas, analyze data
Related MCP server: mcp-postgres
Configuration
Copy the example configuration file:
cp .env.example ~/.pg_mcp/.envEdit
~/.pg_mcp/.envwith your credentials:# PostgreSQL Database Configuration POSTGRES_DB=your_database POSTGRES_USER=readonly_user POSTGRES_PASSWORD=your_password # SSH Tunnel Configuration SSH_HOST=your-ec2-instance.amazonaws.com SSH_USER=ec2-user SSH_KEY_PATH=/path/to/ssh/key # RDS Configuration RDS_HOST=your-database.rds.amazonaws.comCreate a read-only database user:
CREATE USER readonly_mcp WITH PASSWORD 'secure_password'; GRANT CONNECT ON DATABASE your_database TO readonly_mcp; GRANT USAGE ON SCHEMA public TO readonly_mcp; GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly_mcp; ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonly_mcp;
Installation
pnpm install
pnpm run buildUsage
Start the MCP server:
./start_mcp.shFor development mode with hot reload:
./start_mcp.sh devAvailable MCP Tools
postgres_query: Execute read-only SQL queriespostgres_list_tables: List all tables with optional row countspostgres_describe_table: Get detailed schema informationpostgres_analyze_table: Analyze table for data quality issuespostgres_find_related: Find foreign key relationshipspostgres_explain_query: Get query execution plans
SSH Tunnel Management
The server implements a shared SSH tunnel system:
Multiple instances share a single tunnel
Reference counting prevents premature closure
Automatic reconnection on failure
Lock files in
/tmp/pg_mcp_tunnel/
Monitor tunnel status:
./check_tunnel.shSecurity
All queries validated for read-only operations
Enforced read-only transactions
15-second query timeout
SSH encryption for all connections
Credentials stored outside repository
Requirements
Node.js v24+
pnpm package manager
PostgreSQL database
SSH access to database server
This server cannot be deployed
Maintenance
Related MCP Connectors
Hosted MCP server for PostgreSQL diagnostics: slow queries, missing indexes, connection pressure.
Draxlr's remote MCP server connects AI assistants to your SQL databases and dashboards. Explore schemas, run read-only queries, manage saved queries and dashboards, and export results, all with row-level security so each user sees only their own data.
MCP server for querying and analyzing data from ad platforms, analytics tools, and spreadsheets
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA production-ready MCP server that enables safe, read-only SQL SELECT queries against PostgreSQL databases with built-in security validation. It features connection pooling, automatic row limits, and structured logging to ensure secure and reliable database interactions.51 npmISC
- AlicenseNot gradedqualityDmaintenanceRead-only PostgreSQL MCP server that enables running SELECT queries, listing tables and schemas, and describing columns, with built-in protection against writes and malicious SQL attacks.347 npmMIT
- AlicenseAqualityDmaintenanceA secure, read-only PostgreSQL MCP server that provides safe database introspection and querying capabilities.148 npmMIT
- AlicenseNot gradedqualityCmaintenanceA cross-platform MCP server for querying and introspecting PostgreSQL databases with SSH tunnel support, featuring multi-layered query safety and read-only enforcement.13 npmMIT