{"id":50699619,"url":"https://github.com/ralscha/postgresql-mcp","last_synced_at":"2026-06-09T08:32:48.468Z","repository":{"id":362922088,"uuid":"1261257686","full_name":"ralscha/postgresql-mcp","owner":"ralscha","description":"PostgreSQL mcp server","archived":false,"fork":false,"pushed_at":"2026-06-06T14:12:08.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-06T16:03:23.305Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ralscha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-06T12:55:48.000Z","updated_at":"2026-06-06T14:11:03.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ralscha/postgresql-mcp","commit_stats":null,"previous_names":["ralscha/postgresql-mcp"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ralscha/postgresql-mcp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralscha%2Fpostgresql-mcp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralscha%2Fpostgresql-mcp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralscha%2Fpostgresql-mcp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralscha%2Fpostgresql-mcp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ralscha","download_url":"https://codeload.github.com/ralscha/postgresql-mcp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralscha%2Fpostgresql-mcp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34098932,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-09T02:00:06.510Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-09T08:32:48.377Z","updated_at":"2026-06-09T08:32:48.462Z","avatar_url":"https://github.com/ralscha.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# postgresql-mcp\n\nAn [MCP (Model Context Protocol)](https://modelcontextprotocol.io/) server that gives AI assistants structured, read-optimized access to PostgreSQL databases. It exposes schema exploration, data profiling, relationship analysis, query explanation, and safe read/write operations through a standardized MCP interface.\n\n## Features\n\n- **24 MCP tools** covering schema search, table description, data profiling, relationship/dependency inspection, query explanation, connection testing, schema/extension/view/trigger listing, CREATE TABLE DDL generation, table sizing, and tiered write access\n- **Tiered access model** via `POSTGRESQL_ACCESS_LEVEL`: `READONLY` (default), `DML-RW` (adds insert/update/delete), `DDL-RW` (adds create/drop table/index)\n- **SQL-safe design** with double-quote identifier quoting, multipart name validation, and read-only query enforcement\n- **Read-only query guard** that rejects mutating statements (`INSERT`, `UPDATE`, `DELETE`, `CREATE`, `ALTER`, `DROP`, `TRUNCATE`, `COPY`, `VACUUM`, etc.) on the `read_data` tool\n- **Mutation confirmation** with preview mode that shows affected rows before executing writes when `POSTGRESQL_REQUIRE_CONFIRMATION` is enabled\n- **Explain plan** via `EXPLAIN (FORMAT JSON)` for understanding query performance\n- **Connection testing** that validates connectivity and reports latency\n- **Environment listing** showing current host, database, and access-level configuration\n\n## Installation\n\nDownload the latest release for your platform from the [Releases](https://github.com/ralscha/postgresql-mcp/releases) page.\n\n## Usage\n\n### Environment Variables\n\n| Variable | Required | Default | Description |\n|----------|----------|---------|-------------|\n| `POSTGRESQL_HOST` | Yes | — | PostgreSQL hostname or IP |\n| `POSTGRESQL_DATABASE` | Yes | — | Database name |\n| `POSTGRESQL_USER` | Yes | — | Login username |\n| `POSTGRESQL_PASSWORD` | Yes | — | Login password |\n| `POSTGRESQL_PORT` | No | `5432` | PostgreSQL port |\n| `POSTGRESQL_SSLMODE` | No | `prefer` | SSL mode: `disable`, `allow`, `prefer`, `require`, `verify-ca`, `verify-full` |\n| `POSTGRESQL_ACCESS_LEVEL` | No | `READONLY` | `READONLY`, `DML-RW`, or `DDL-RW` |\n| `POSTGRESQL_CONNECTION_TIMEOUT` | No | `30` | Connection timeout in seconds |\n| `POSTGRESQL_QUERY_TIMEOUT` | No | `120` | Query timeout in seconds |\n| `POSTGRESQL_MAX_ROWS_DEFAULT` | No | `1000` | Default row limit for queries |\n| `POSTGRESQL_REQUIRE_CONFIRMATION` | No | `true` | Require confirm flag for writes |\n| `POSTGRESQL_TRANSPORT` | No | `stdio` | MCP transport: `stdio` or `sse` |\n| `POSTGRESQL_HTTP_ADDR` | No | `:8080` | HTTP listen address when `POSTGRESQL_TRANSPORT=sse` |\n| `POSTGRESQL_SSE_PATH` | No | `/sse` | SSE endpoint path when `POSTGRESQL_TRANSPORT=sse` |\n\n### Running as an MCP Server\n\nBy default, the server communicates over stdio. Configure your MCP client to launch it:\n\n```json\n{\n  \"mcpServers\": {\n    \"postgresql\": {\n      \"command\": \"/path/to/bin/postgresql-mcp\",\n      \"env\": {\n        \"POSTGRESQL_HOST\": \"localhost\",\n        \"POSTGRESQL_DATABASE\": \"YourDatabase\",\n        \"POSTGRESQL_USER\": \"postgres\",\n        \"POSTGRESQL_PASSWORD\": \"YourPassword\",\n        \"POSTGRESQL_SSLMODE\": \"disable\",\n        \"POSTGRESQL_ACCESS_LEVEL\": \"READONLY\"\n      }\n    }\n  }\n}\n```\n\nTo serve MCP over SSE instead, set `POSTGRESQL_TRANSPORT=sse` and run the server as an HTTP process:\n\n```bash\nPOSTGRESQL_TRANSPORT=sse \\\nPOSTGRESQL_HTTP_ADDR=:8080 \\\nPOSTGRESQL_SSE_PATH=/sse \\\n/path/to/bin/postgresql-mcp\n```\n\nThen configure an SSE-capable MCP client to connect to:\n\n```text\nhttp://localhost:8080/sse\n```\n\n### Access Levels\n\n- **`READONLY`** (default) — Schema exploration, data reading, profiling, relationship inspection, query explanation, connection testing, schema listing, extensions, views, triggers, CREATE TABLE DDL generation, table sizing. 18 tools.\n- **`DML-RW`** — All read-only tools plus `insert_data`, `update_data`, `delete_data`. 21 tools.\n- **`DDL-RW`** — All DML tools plus `create_table`, `create_index`, `drop_table`. 24 tools.\n\nMutations (`update_data`, `delete_data`, `drop_table`) require a `\"confirm\": true` flag when `POSTGRESQL_REQUIRE_CONFIRMATION` is enabled (the default). Without confirmation, the server returns a preview of the affected rows instead.\n\n## MCP Tools\n\n### Read-Only (READONLY)\n\n| Tool | Description |\n|------|-------------|\n| `search_schema` | Search tables and columns by name pattern with pagination |\n| `describe_table` | Get columns, primary keys, foreign keys, and indexes for a table |\n| `list_table` | List tables, optionally filtered by schema and name |\n| `list_databases` | List all databases on the server |\n| `list_environments` | Show current connection and access-level configuration |\n| `profile_table` | Row count, null counts, distinct counts, min/max per column, with optional data samples |\n| `inspect_relationships` | List foreign keys going out of and into a table |\n| `inspect_dependencies` | Find objects (views, functions) that depend on a table |\n| `explain_query` | Get the JSON execution plan for a read-only query |\n| `read_data` | Execute a read-only SELECT query with row limits |\n| `test_connection` | Ping the server and return latency and server version info |\n| `validate_environment_config` | Validate that all environment variables are correctly configured |\n| `list_schemas` | List all user schemas with owner and description |\n| `list_extensions` | List installed PostgreSQL extensions with version |\n| `list_views` | List views with their SQL definitions |\n| `list_triggers` | List triggers with event, timing, and definition |\n| `show_create_table` | Generate the CREATE TABLE DDL for an existing table |\n| `table_size` | Table and index sizes, toast size, estimated row counts |\n\n### DML (DML-RW)\n\n| Tool | Description |\n|------|-------------|\n| `insert_data` | Insert one or more rows into a table |\n| `update_data` | Update rows matching a WHERE clause (with optional preview) |\n| `delete_data` | Delete rows matching a WHERE clause (with optional preview) |\n\n### DDL (DDL-RW)\n\n| Tool | Description |\n|------|-------------|\n| `create_table` | Create a table with column definitions, primary keys, and identity columns |\n| `create_index` | Create a standard or unique index on specified columns |\n| `drop_table` | Drop a table (with optional preview/confirmation) |\n\n## License\n\nMIT License. See [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fralscha%2Fpostgresql-mcp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fralscha%2Fpostgresql-mcp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fralscha%2Fpostgresql-mcp/lists"}