postgresqldockerconfigurationrecover

Recover deleted PostgreSQL config files


I was trying to delete pg_log folder (it was huge 3Gib) But i accidentally remove everything in data folder (by rm ./*):

enter image description here

Now all of the .conf files removed from data folder and i receiving this error in the log:

"Data page checksums are disabled"

The postgres was made by docker through docker hub (15-alpine)

I didn't touch any config files there.

Where can i find the default postgres config files? I think i can make it back to work by restoring the .conf files.


Solution

  • Steps to recover default config files using Docker image.

    1. Pull docker image for Postrgres:
    docker pull postgres:15-alpine
    
    1. Run container:
    docker run -e POSTGRES_HOST_AUTH_METHOD=trust postgres:15-alpine
    
    1. Keep current terminal open and open new terminal

    2. Connect to shell in docker container:

    docker ps
    
    CONTAINER ID   IMAGE                    COMMAND                  CREATED         STATUS         PORTS      NAMES
    aee1237294b8   postgres:15-alpine3.17   "docker-entrypoint.s…"   7 seconds ago   Up 6 seconds   5432/tcp   naughty_knuth
    

    copy container id from docker ps result and execute shell command:

    docker exec -it aee1237294b8 bash
    
    1. Go to data folder and archive it:
    cd /var/lib/postgresql/data/
    tar -zcf pgdata.tar.gz *
    
    1. Exit docker container shell:
    exit
    
    1. Copy archive from docker container:
    docker cp aee1237294b8:/var/lib/postgresql/data/pgdata.tar.gz ~/Downloads/pgdata.tar.gz
    

    as result I've downloaded config from postgres:15-alpine

    grab it from here: https://anarjafarov.me/pg.conf.zip

    and watch video instructions: https://www.youtube.com/watch?v=fgHtvwbQJDE