admin管理员组文章数量:1278822
Context: I'm deploying a localhost version of a website to do some troubleshooting. It's a Django website running Mezzanine (yes it's very old, hence the debugging).
The website has a Postgres database which has been dumped via:
sudo -u postgres pg_dump --role "postgres" --format custom --blobs
--encoding UTF8 --verbose --no-unlogged-table-data --file /tmp/backup.bak
I have been able to restore this database on my own computer using pg_restore
, however when trying to compose docker containers, the database is created but my db_init
service does not seem to restore the database.
Here is the .yml
file I use:
version: '3'
services:
db:
image: postgres:13
environment:
POSTGRES_DB: pg_db
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres"]
interval: 10s
retries: 5
db_init:
image: postgres:13
container_name: pg_db_init
command: ["sh", "-c",
"./wait-for-it.sh db:5432 -- pg_restore --clean --if-exists \
--no-owner --no-privileges -h db -d pg_db -U postgres /backup.bak"]
environment:
POSTGRES_DB: pg_db
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
PGPASSWORD: postgres
volumes:
- ./backup.bak:/backup.bak
- ./wait-for-it.sh:/wait-for-it.sh
depends_on:
- db
web:
build: .
command: python3 manage.py runserver 0.0.0.0:8000
working_dir: /var/www/website.au
depends_on:
- db
environment:
- DJANGO_SETTINGS=project.settings
user: ${UID}:${GID}
volumes:
- .:/var/www/website.au
ports:
- "8000:8000"
tty: true
volumes:
postgres_data:
docker-compose.yml
file creates the service database, the service db_init
then tries to restore a dumped pg file into the database (yes it appears all the paths are successful) - all instances run.
No errors can be seen in the db_init
container.
Here's the tail of the db container log:
2025-02-25 17:22:30 2025-02-25 09:22:30.693 UTC [1] LOG: database system is ready to accept connections
2025-02-25 17:22:30 2025-02-25 09:22:30.913 UTC [72] ERROR: relation "shipping_shippingcountry" does not exist at character 47
2025-02-25 17:22:30 2025-02-25 09:22:30.913 UTC [72] STATEMENT: SELECT "shipping_shippingcountry"."code" FROM "shipping_shippingcountry" WHERE "shipping_shippingcountry"."enabled" = false ORDER BY "shipping_shippingcountry"."code" ASC
2025-02-25 17:22:32 2025-02-25 09:22:32.238 UTC [73] ERROR: relation "shipping_shippingcountry" does not exist at character 47
2025-02-25 17:22:32 2025-02-25 09:22:32.238 UTC [73] STATEMENT: SELECT "shipping_shippingcountry"."code" FROM "shipping_shippingcountry" WHERE "shipping_shippingcountry"."enabled" = false ORDER BY "shipping_shippingcountry"."code" ASC
These missing relations occur because the database hasn't restored any tables at all, which I checked by using the container's terminal, connecting to the Postgres database and using the \dt command
本文标签:
版权声明:本文标题:postgresql - setting up a postgres database in my docker-compose containers. Why isn't my .bak file restoring the databa 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741216272a2360102.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论