Skip to content

Data import fails during database initialize process #596

@ant-

Description

@ant-

I'm trying to dockerize Django application with PostgreSQL database.
I'm stuck on data import during database initialization process.
To build a database container I do:
docker-compose up --build db

The process is starting and all seems to be well except some warnings like checkpoint happens too often and ERROR: canceling autovacuum task db_1_2e5b04cd80b3 | CONTEXT: automatic analyze of table

At the end I'm seeing the following:

db_1_2e5b04cd80b3 | waiting for server to shut down...LOG:  received fast shutdown request
db_1_2e5b04cd80b3 | .LOG:  aborting any active transactions
db_1_2e5b04cd80b3 | FATAL:  terminating autovacuum process due to administrator command
db_1_2e5b04cd80b3 | LOG:  autovacuum launcher shutting down
db_1_2e5b04cd80b3 | LOG:  shutting down
db_1_2e5b04cd80b3 | LOG:  database system is shut down
db_1_2e5b04cd80b3 |  done
db_1_2e5b04cd80b3 | server stopped
db_1_2e5b04cd80b3 | 
db_1_2e5b04cd80b3 | PostgreSQL init process complete; ready for start up.
db_1_2e5b04cd80b3 | 
db_1_2e5b04cd80b3 | LOG:  database system was shut down at 2019-07-04 13:12:44 UTC
db_1_2e5b04cd80b3 | LOG:  MultiXact member wraparound protections are now enabled
db_1_2e5b04cd80b3 | LOG:  database system is ready to accept connections
db_1_2e5b04cd80b3 | LOG:  autovacuum launcher started

But there is no any problems within importing data after container startup, like so:
psql -U postgres -h localhost woorder < 2-data.sql

docker-compose.yml

version: '3'

services:
  db:
    build:
      context: ./
      dockerfile: Dockerfile_db
    restart: always
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=postgres
      - PGDATA=/var/lib/postgresql/data
    volumes:
      - ./postgres-data:/var/lib/postgresql/data
      - .:/project
      - ./db-init-scripts:/docker-entrypoint-initdb.d
    ports:
      - 5432:5432
  backend:
    build: .
    command: python /backend/manage.py runserver 0.0.0.0:8081
    restart: always
    env_file:
      - .env
    volumes:
      - .:/backend
    ports:
      - 8081:8081
    depends_on:
      - db
    links:
      - db

1-schema.sql

CREATE USER woorder WITH PASSWORD 'pass';
CREATE DATABASE woorder;
GRANT ALL PRIVILEGES ON DATABASE woorder TO woorder;
ALTER ROLE woorder SET client_encoding TO 'utf8';
ALTER ROLE woorder SET default_transaction_isolation TO 'read committed';
ALTER ROLE woorder SET timezone TO 'UTC';

There is a 2-data.sql file which is 2.1Gb SQL dump under db-init-scripts directory.

Dockerfile

FROM python:3.6
ENV PYTHONUNBUFFERED 1
RUN mkdir /backend
WORKDIR /backend
ADD requirements.txt /backend/
RUN pip install -r requirements.txt
RUN pip install https://github.com/jasperlittle/django-rest-framework-docs/archive/master.zip
ADD . /backend/

Dockerfile_db

FROM postgres:9.6

RUN mkdir -p "$PGDATA" && chmod 700 "$PGDATA"

The question is why the import fails during database initialization?

UPDATE
I forgot to mention that saying "import fails" I mean that there are no data in the database, but it runs. As I said if I'll execute import after container goes up everything is ok.

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