1

Hello for some reason my postgres keeps restarting basically this is my docker compose:

version: "3.7"
services:
  db:
    image: postgres:12
    restart: always
    container_name: "db"
    ports:
      - "${DB_PORT}:5432"
    volumes:
      - ./pgdata:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: ${DB_USER}
      POSTGRES_PASSWORD: ${DB_PASS}
      POSTGRES_DB: ${DB_NAME}

  api:
    image: server_emasa
    container_name: api
    restart: always
    depends_on:
      - db
    ports:
      - "${SERVER_PORT}:${SERVER_PORT}"

and for some reason my postgres is restarting I tried using the docker compose logs to check and got this:

db     | PostgreSQL Database directory appears to contain a database; Skipping initialization
db     | 
db     | 2020-03-26 05:37:18.475 UTC [1] LOG:  starting PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db     | 2020-03-26 05:37:18.475 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db     | 2020-03-26 05:37:18.475 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db     | 2020-03-26 05:37:18.558 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db     | 2020-03-26 05:37:18.625 UTC [1] LOG:  could not open directory "pg_tblspc": No such file or directory
db     | 2020-03-26 05:37:18.646 UTC [26] LOG:  database system was interrupted; last known up at 2020-03-23 23:46:31 UTC
db     | 2020-03-26 05:37:18.879 UTC [26] LOG:  could not open directory "pg_tblspc": No such file or directory
db     | 2020-03-26 05:37:18.879 UTC [26] LOG:  could not open directory "pg_tblspc": No such file or directory
db     | 2020-03-26 05:37:18.879 UTC [26] FATAL:  could not open directory "pg_replslot": No such file or directory
db     | 2020-03-26 05:37:18.880 UTC [1] LOG:  startup process (PID 26) exited with exit code 1
db     | 2020-03-26 05:37:18.880 UTC [1] LOG:  aborting startup due to startup process failure
db     | 2020-03-26 05:37:18.881 UTC [1] LOG:  database system is shut down

3 Answers 3

1

I also had a similar problem after restarting my postgresql container:

LOG:  could not open directory "pg_tblspc/memory/...": Not a directory

The reason of the error is probably because of data corruption in database.

You can solve the issue by deleting contents of pg_tblspc/ directory (make sure to backup all of them) or you can also try by recovering the latest backup of your database (if there's one).

Sign up to request clarification or add additional context in comments.

Comments

-1

The error refers to postgresql not being able to find critical files, but is not attempting to create them because your pgdata directory contains some files.

Try not to bind your pgdata directory to the docker container, just remove the volumes section in your docker-compose file

3 Comments

I didn't understand, could you explain it better? Would I need to remove my volume from the docker-compose?
Docker containers have their own disk space, there is no need to share a volume between your local machine and the container.
You are not correct. You sometime need to persist data, that's why we sometimes need to bind docker volume to local disk space
-1

first remove associated docker volume and data folder then: POSTGRES_DB: ${DB_NAME} will not work, use like this:

 environment:
   - 'POSTGRES_DB=med_db'
   - 'POSTGRES_USER:postgres'
   - 'POSTGRES_PASSWORD:pass'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.