[Python] PostgreSQL 15 protocol version error with Django and psycopg2 in Docker environment

Discussão em 'Python' iniciado por Stack, Dezembro 22, 2024.

  1. Stack

    Stack Membro Participativo

    I'm experiencing protocol version errors while running a Django application with PostgreSQL 15 in Docker containers:

    FATAL: unsupported frontend protocol 0.0: server supports 3.0 to 3.0
    FATAL: unsupported frontend protocol 255.255: server supports 3.0 to 3.0
    FATAL: no PostgreSQL user name specified in startup packet


    My setup:

    • Django 4.2.16
    • PostgreSQL 15
    • psycopg2-binary 2.9.10
    • Python 3.11.4

    Docker Compose configuration:

    services:
    postgres:
    image: postgres:14
    container_name: postgres
    volumes:
    - postgres_data:/var/lib/postgresql/data/
    environment:
    - POSTGRES_USER=${POSTGRES_USER}
    - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
    - POSTGRES_DB=${POSTGRES_DB}
    ports:
    - "5432:5432"

    backend:
    build:
    context: ./core
    dockerfile: Dockerfile.prod
    container_name: backend
    volumes:
    - ./core:/home/app/core
    - static_volume:/home/app/core/static
    - media_volume:/home/app/core/media
    expose:
    - "8000"
    environment:
    # role for entrypoint
    - ROLE=backend
    # basic settings
    - SECRET_KEY=${SECRET_KEY}
    - DEBUG=${DEBUG}
    # database configuration
    - PGDB_ENGINE=${PGDB_ENGINE}
    - PGDB_NAME=${PGDB_NAME}
    - PGDB_USER=${PGDB_USER}
    - PGDB_PASSWORD=${PGDB_PASSWORD}
    - PGDB_HOST=${PGDB_HOST}
    - PGDB_PORT=${PGDB_PORT}
    depends_on:
    - postgres
    restart: always

    nginx:
    image: nginx:stable-alpine
    container_name: nginx
    ports:
    - "80:80"
    - "443:443"
    volumes:
    - ./default.conf:/etc/nginx/conf.d/default.conf
    - static_volume:/home/app/core/static
    - media_volume:/home/app/core/media
    depends_on:
    - backend
    restart: always

    volumes:
    static_volume:
    media_volume:
    postgres_data:


    The error occurs when I run the docker-compose file, appearing at the end of the logs. Interestingly, downgrading image version to PostgreSQL 14 resolves the issue completely.

    What's particularly interesting is that VS Code marks the postgres:15 Docker image as "outdated", while it doesn't show this warning for postgres:14. This seems counterintuitive since version 15 is newer.

    What could be causing this protocol incompatibility between psycopg2 and PostgreSQL 15? Is there a way to resolve this while maintaining PostgreSQL 15?

    Steps I've tried: Clearing all Docker volumes Rebuilding containers

    Continue reading...

Compartilhe esta Página