docker-library / postgres

Docker Official Image packaging for Postgres
http://www.postgresql.org
MIT License
2.14k stars 1.11k forks source link

Please help, I have persisted it, but the table and data are not restored after restarting the container. #1255

Closed llnancy closed 1 week ago

llnancy commented 1 week ago

verion: postgres:15-alpine

Persistent mount (Similar to the following, I am sure that the persistent mounting of the data volume is successful):

volumeMounts:
- name: postgresql
  mountPath: /var/lib/postgresql

After restarting the container, the files in the directory are still there,

image

but the previous database and table are gone. Is there a way to restore it? How can I do it?

llnancy commented 1 week ago

Container log after restart

The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Shanghai
creating configuration files ... ok
running bootstrap script ... ok
sh: locale: not found
2024-07-01 11:53:41.292 CST [30] WARNING: no usable system locales were found
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
Success. You can now start the database server using:
pg_ctl -D /var/lib/postgresql/data -l logfile start
initdb: warning: enabling "trust" authentication for local connections
CREATE DATABASE
/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
waiting for server to shut down....2024-07-01 11:53:41.976 CST [36] LOG: received fast shutdown request
2024-07-01 11:53:41.977 CST [36] LOG: aborting any active transactions
2024-07-01 11:53:41.981 CST [36] LOG: background worker "logical replication launcher" (PID 42) exited with exit code 1
2024-07-01 11:53:41.982 CST [37] LOG: shutting down
2024-07-01 11:53:41.989 CST [37] LOG: checkpoint starting: shutdown immediate
2024-07-01 11:53:42.043 CST [37] LOG: checkpoint complete: wrote 920 buffers (5.6%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.013 s, sync=0.017 s, total=0.062 s; sync files=301, longest=0.008 s, average=0.001 s; distance=4235 kB, estimate=4235 kB
2024-07-01 11:53:42.049 CST [36] LOG: database system is shut down
done
server stopped
PostgreSQL init process complete; ready for start up.
2024-07-01 11:53:42.111 CST [1] LOG: starting PostgreSQL 15.6 on x86_64-pc-linux-musl, compiled by gcc (Alpine 13.2.1_git20231014) 13.2.1 20231014, 64-bit
2024-07-01 11:53:42.112 CST [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2024-07-01 11:53:42.112 CST [1] LOG: listening on IPv6 address "::", port 5432
2024-07-01 11:53:42.121 CST [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2024-07-01 11:53:42.139 CST [52] LOG: database system was shut down at 2024-07-01 11:53:42 CST
2024-07-01 11:53:42.148 CST [1] LOG: database system is ready to accept connections