Skip to content

Postgres Auto Dropping the DB Randomly - database "template0" is not currently accepting connections #1221

@Harryalways317

Description

@Harryalways317

Hi, I'm facing this error from multiple days, it happens on postgres inside docker.

image
ERROR: database "template0" is not currently accepting connections
FATAL: database "template0" can only be updated by autovacuum worker processes

It happens mostly after a hour,

the below is the service inside docker compose

  db:
    image: postgres
    restart: always
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: postgres
    ports:
      - "5432:5432"
    volumes:
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
      - database_data:/var/lib/postgresql/data

init.sql

-- Create the EC2 Fleet Instance Management table
CREATE TABLE IF NOT EXISTS ec2_fleet_instance_management (
    fleet_id VARCHAR PRIMARY KEY,
    instance_id VARCHAR,
    state VARCHAR,
    requested_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    fleet_group VARCHAR,
    instance_detail JSONB,
    instance_status VARCHAR,
    system_status VARCHAR,
    llm_status VARCHAR,
    public_ip_address VARCHAR
);

-- Create the Request History table
CREATE TABLE IF NOT EXISTS request_history (
    request_id VARCHAR PRIMARY KEY,
    instance_handled VARCHAR,
    request_details JSONB,
    response_details JSONB,
    requested_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    request_type VARCHAR,
    instance_detail JSONB,
    status_code VARCHAR,
    public_ip_address VARCHAR
);

-- Indexes for the EC2 Fleet Instance Management table for quicker search
CREATE INDEX IF NOT EXISTS idx_ec2_fleet_instance_management_on_fleet_group ON ec2_fleet_instance_management (fleet_group);
CREATE INDEX IF NOT EXISTS idx_ec2_fleet_instance_management_on_state ON ec2_fleet_instance_management (state);

-- Indexes for the Request History table for quicker search
CREATE INDEX IF NOT EXISTS idx_request_history_on_request_type ON request_history (request_type);
CREATE INDEX IF NOT EXISTS idx_request_history_on_requested_at ON request_history (requested_at);

the connection im making

def get_db_connection():
    conn = psycopg2.connect(
        dbname="postgres",
        user="postgres",
        password="*****",
        host="db",
        port="5432"
    )
    return conn

Any where i'm doing it wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions