Answers: <p>The problem is <code>2024-02-11 07:20:10.449 GMT [165] FATAL:  password authentication failed for user &quot;postgres&quot;</code>.</p>
  <ul>
  <li>Are you sure its the correct password?</li>
  <li>Your Volume is different from your Ubuntu machine to the VPS so check they are identical to rule out that issue.</li>
  <li>Check your <code>pg_hba.conf</code> on the line mentioned. You might have editited a line above or below and therefore the wrong permissions are set.</li>
  <li>You've not declared a <code>network:</code> section, is it on the same network as the thing your trying to connect to?</li>
  </ul>
  <p>If these don't fix the issue, add your response &amp; any other logs/errors and we will see fi we can get it sorted.</p>
  
Answers: CC BY-SA 4.0
Answers: 2024-02-17T23:15:23.993Z
Answers: 2024-02-17T23:15:23.993Z
Answers: Definity
Body: <p>I have a Docker Compose setup for a PostgreSQL container like below:</p>
  <pre><code>version: '3'
  services:
  
    #PostgreSQL Service
    um-db:
      image: postgres:15
      container_name: um-db
      tty: true
      ports:
        - &quot;5432:5432&quot;
      environment:
        POSTGRES_DB: user_management
        POSTGRES_USER: postgres
        POSTGRES_PASSWORD: password
        PGDATA: /var/lib/postgresql/data/pgdata
        SERVICE_TAGS: dev
        SERVICE_NAME: postgresql
      volumes:
        - um-dbdata16:/var/lib/postgresql/data
      networks:
        - um-app-network
  
  #Volumes
  volumes:
    um-dbdata16:
      driver: local
  </code></pre>
  <p>After running <code>docker-compose up -d --build</code>, the database gets built successfully. However, after some time, it automatically gets dropped. Here's a snippet of the log:</p>
  <pre><code>docker logs um-db
  2024-02-11 07:20:09.510 GMT [161] ERROR:  cannot drop the currently open database
  2024-02-11 07:20:09.510 GMT [161] STATEMENT:  DROP DATABASE postgres;
  2024-02-11 07:20:09.639 GMT [22] LOG:  checkpoint starting: immediate force wait
  2024-02-11 07:20:10.449 GMT [165] FATAL:  password authentication failed for user &quot;postgres&quot;
  2024-02-11 07:20:10.449 GMT [165] DETAIL:  Connection matched pg_hba.conf line 100: &quot;host all all all scram-sha-256&quot;
  </code></pre>
  <p>The same setup is working fine on my Ubuntu server locally, but when deployed to a VPS, this issue occurs. I have thoroughly searched the internet for a solution but couldn't find any useful resources. Please point me in the right direction so that I can solve this issue.</p>
  
Tags: <docker><docker-compose><postgresql>
Title: Postgresql container automatically dropping database after some time in Docker Compose setup
UserDisplayName: Sandeep Dhakal
ThreadText: # Postgresql container automatically dropping database after some time in Docker Compose setup
  
  (Asked by: username_0 on 2024-02-11)
  
  I have a Docker Compose setup for a PostgreSQL container like below:
  
  ```
  version: '3'
  services:
  
    #PostgreSQL Service
    um-db:
      image: postgres:15
      container_name: um-db
      tty: true
      ports:
        - "5432:5432"
      environment:
        POSTGRES_DB: user_management
        POSTGRES_USER: postgres
        POSTGRES_PASSWORD: password
        PGDATA: /var/lib/postgresql/data/pgdata
        SERVICE_TAGS: dev
        SERVICE_NAME: postgresql
      volumes:
        - um-dbdata16:/var/lib/postgresql/data
      networks:
        - um-app-network
  
  #Volumes
  volumes:
    um-dbdata16:
      driver: local
  
  ```
  
  After running `docker-compose up -d --build`, the database gets built successfully. However, after some time, it automatically gets dropped. Here's a snippet of the log:
  
  ```
  docker logs um-db
  2024-02-11 07:20:09.510 GMT [161] ERROR:  cannot drop the currently open database
  2024-02-11 07:20:09.510 GMT [161] STATEMENT:  DROP DATABASE postgres;
  2024-02-11 07:20:09.639 GMT [22] LOG:  checkpoint starting: immediate force wait
  2024-02-11 07:20:10.449 GMT [165] FATAL:  password authentication failed for user "postgres"
  2024-02-11 07:20:10.449 GMT [165] DETAIL:  Connection matched pg_hba.conf line 100: "host all all all scram-sha-256"
  
  ```
  
  The same setup is working fine on my Ubuntu server locally, but when deployed to a VPS, this issue occurs. I have thoroughly searched the internet for a solution but couldn't find any useful resources. Please point me in the right direction so that I can solve this issue.
  
  **Tags:** docker, docker-compose, postgresql
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-02-17. Score: 0
  
  The problem is `2024-02-11 07:20:10.449 GMT [165] FATAL: password authentication failed for user "postgres"`.
  
  * Are you sure its the correct password?
  * Your Volume is different from your Ubuntu machine to the VPS so check they are identical to rule out that issue.
  * Check your `pg_hba.conf` on the line mentioned. You might have editited a line above or below and therefore the wrong permissions are set.
  * You've not declared a `network:` section, is it on the same network as the thing your trying to connect to?
  
  If these don't fix the issue, add your response & any other logs/errors and we will see fi we can get it sorted.
  
  
  ---
  
  