+ postgresql server & pgadmin

This commit is contained in:
2026-10-13 19:02:35 +03:00
parent 9b3a69d296
commit 9516d0da25
7 changed files with 113 additions and 21 deletions

View File

@ -2,6 +2,9 @@
"mcpServers": { "mcpServers": {
"intai-mariadb": { "intai-mariadb": {
"url": "http://127.0.0.1:8765/sse" "url": "http://127.0.0.1:8765/sse"
},
"intai-postgres": {
"url": "http://127.0.0.1:8766/sse"
} }
} }
} }

View File

@ -43,3 +43,7 @@ INTAI_DOCKER_NETWORK=intai-docker_default
MCP_MARIADB_PORT=8765 MCP_MARIADB_PORT=8765
# Опционально: зафиксировать ревизию MariaDB/mcp при сборке образа (ветка или тег). # Опционально: зафиксировать ревизию MariaDB/mcp при сборке образа (ветка или тег).
# MARIADB_MCP_GIT_REF=main # MARIADB_MCP_GIT_REF=main
### MCP PostgreSQL (Cursor, Claude Code) ##################
# Host port for SSE; the same port must be in .cursor/mcp.json and .mcp.json of the project (url .../sse).
MCP_POSTGRES_PORT=8766

View File

@ -113,6 +113,24 @@ Optional MCP server so Cursor can query the `db` container over the Docker netwo
First image build can take a while (upstream MariaDB MCP dependencies). First image build can take a while (upstream MariaDB MCP dependencies).
### PostgreSQL, pgAdmin, Postgres MCP
Services `pgsql`, `pgadmin`, `mcp-postgres` are described in `docker-compose.base.yml`; copy them from
`docker-compose.postgres.yml.example` into your `docker-compose.yml` (volumes `database-pgsql` and `pgadmin` too).
`dc up -d pgsql pgadmin mcp-postgres`
- `pgsql` — official `postgres:18` image. Port `5432`, user, password and database `intai`.
Since 18 the data lives in `/var/lib/postgresql/<major>/docker`, so the volume is mounted at `/var/lib/postgresql`.
Another major version does not start on the same volume — dump and restore.
- `pgadmin` — pgAdmin 4 in desktop mode, no login: http://pgadmin.intai.localhost (or the port from the example). The `intai` server comes from `config/pgadmin/servers.json` on every start; the password (`intai`) is asked once, tick "Save password".
Register the server once: host `pgsql`, port `5432`, user `intai`, password `intai`.
- `mcp-postgres` — [Postgres MCP Pro](https://github.com/crystaldba/postgres-mcp), SSE on
`http://127.0.0.1:${MCP_POSTGRES_PORT:-8766}/sse`.
- `./bash/psql.sh [database] [user]` — psql inside the container.
Transfer of the intai database from MariaDB and its verification: `docs/PostgreSQL.md` in the intai project.
### Workspace ### Workspace
For execute composer update|install or nodejs operations, also yarn, npm and all node-builds. For execute composer update|install or nodejs operations, also yarn, npm and all node-builds.

16
bash/psql.sh Executable file
View File

@ -0,0 +1,16 @@
#!/bin/bash
# psql in the pgsql container. Usage: ./psql.sh [database] [user] — defaults: intai intai
SCRIPT_DIR="$(realpath $(dirname "$(readlink -f "$0")"))"
. $SCRIPT_DIR/_docker-cmd.sh || {
echo "no docker cmd is presented" && exit 1
}
CONTAINER=$(docker ps --filter "label=com.docker.compose.service=pgsql" --format '{{.ID}}' | head -n1)
if [[ -z "${CONTAINER}" ]]; then
echo "Unable to find container: pgsql"
exit 1
fi
$DOCKER_CMD exec -ti ${CONTAINER} psql -U "${2:-intai}" -d "${1:-intai}"

View File

@ -0,0 +1,13 @@
{
"Servers": {
"1": {
"Name": "intai",
"Group": "Servers",
"Host": "pgsql",
"Port": 5432,
"MaintenanceDB": "intai",
"Username": "intai",
"SSLMode": "prefer"
}
}
}

View File

@ -93,6 +93,33 @@ services:
PMA_HOST: db PMA_HOST: db
PMA_USER: root PMA_USER: root
PMA_PASSWORD: 123456 PMA_PASSWORD: 123456
# PostgreSQL 18, official image. Since 18 the data lives in /var/lib/postgresql/18/docker,
# so the volume (declared in the compose file that extends this service) is mounted at /var/lib/postgresql.
pgsql:
image: postgres:18
restart: always
environment:
POSTGRES_USER: intai
POSTGRES_PASSWORD: intai
POSTGRES_DB: intai
volumes:
- database-pgsql:/var/lib/postgresql
- ./hostfiles:/hostfiles
pgadmin:
image: dpage/pgadmin4:9
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: info@wpstudio.ru
PGADMIN_DEFAULT_PASSWORD: postgres
# desktop mode: no login page, a single local user
PGADMIN_CONFIG_SERVER_MODE: 'False'
PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED: 'False'
# the intai server is registered from servers.json on every start
PGADMIN_SERVER_JSON_FILE: /pgadmin4/servers.json
PGADMIN_REPLACE_SERVERS_ON_STARTUP: 'True'
volumes:
- pgadmin:/var/lib/pgadmin
- ./config/pgadmin/servers.json:/pgadmin4/servers.json:ro
inbucket: inbucket:
image: inbucket/inbucket image: inbucket/inbucket
restart: always restart: always
@ -154,3 +181,12 @@ services:
LOG_FILE: /tmp/mcp_server.log LOG_FILE: /tmp/mcp_server.log
ports: ports:
- "127.0.0.1:${MCP_MARIADB_PORT:-8765}:9001" - "127.0.0.1:${MCP_MARIADB_PORT:-8765}:9001"
# Postgres MCP Pro (https://github.com/crystaldba/postgres-mcp), SSE like mcp-mariadb.
mcp-postgres:
image: crystaldba/postgres-mcp:0.3.0
restart: unless-stopped
environment:
DATABASE_URI: postgresql://intai:intai@pgsql:5432/intai
command: [ "--transport=sse", "--sse-host=0.0.0.0" ]
ports:
- "127.0.0.1:${MCP_POSTGRES_PORT:-8766}:8000"

View File

@ -1,27 +1,29 @@
# PostgreSQL + pgAdmin 4 + Postgres MCP. Services are described in docker-compose.base.yml.
#
# Standalone: docker compose -f docker-compose.postgres.yml.example up -d
# Or copy the services into your docker-compose.yml next to db/pma (as intai does).
services: services:
dbpg: pgsql:
image: postgres extends:
restart: always file: docker-compose.base.yml
environment: service: pgsql
POSTGRES_PASSWORD: postgres
volumes:
- databasepg:/var/lib/postgresql/data
- ./hostfiles:/hostfiles
ports: ports:
- "5432:5432" - "5432:5432"
db-project: pgadmin:
image: postgis/postgis:14-3.3 extends:
environment: file: docker-compose.base.yml
- POSTGRES_DB=project_db service: pgadmin
- POSTGRES_USER=project_db_user depends_on:
- POSTGRES_PASSWORD=project_db_password - pgsql
ports: ports:
- "5434:5432" - "83:80"
healthcheck: mcp-postgres:
test: [ "CMD-SHELL", "pg_isready" ] extends:
interval: 10s file: docker-compose.base.yml
timeout: 5s service: mcp-postgres
retries: 5 depends_on:
- pgsql
volumes: volumes:
databasepg: database-pgsql:
pgadmin: