postgres docker 容器中的 pg_restore

Vai*_*mar 14 postgresql docker dockerfile

我正在尝试使用 shellscript 中的 pg_restore 恢复 PostgreSQL docker 容器中的数据库 taht 将从 docker 文件中调用。我收到以下错误“错误:取消 autovacuum 任务上下文:表 'tablename' 的自动分析”

Docker 文件:

    FROM postgres:9.3
    ENV POSTGRES_USER postgres
    ENV POSTGRES_PASSWORD Abcd1234
    ENV POSTGRES_DB Clarion1
    COPY DB.backup /var/lib/postgresql/backup/DB.backup
    COPY initialize.sh /docker-entrypoint-initdb.d/initialize.sh
Run Code Online (Sandbox Code Playgroud)

初始化.sh

    #!/bin/bash
    set -e
    set -x

    echo "******PostgreSQL initialisation******"
    pg_restore -C -d DB /var/lib/postgresql/backup/DB.backup
Run Code Online (Sandbox Code Playgroud)

日志:

    server started
    CREATE DATABASE
    /docker-entrypoint.sh: running /docker-entrypoint-initdb.d/initialize.sh
    ++ echo '******PostgreSQL initialisation******'
    ++ pg_restore -C -d Clarion1 /var/lib/postgresql/backup/Clarion53.backup
    ******PostgreSQL initialisation******
    ERROR:  canceling autovacuum task
Run Code Online (Sandbox Code Playgroud)

但是,如果我尝试从主机中的命令提示符从同一个备份文件恢复数据库,它工作正常。

Zeu*_*ton 28

这是一种从位于主机上的文件中恢复的方法:

docker exec -i container_name pg_restore -U postgres_user -v -d database_name < /dir_backup_outside_container/file_name.tar
Run Code Online (Sandbox Code Playgroud)


小智 8

结合投票最多的Heroku 的指南,我想出了这个:

docker exec -i mohe-bc_db_1 pg_restore --verbose --clean --no-acl --no-owner -U postgres -d mohe-bc_development < ~/Downloads/de8dc786-b133-4ae2-a040-dcf34f12c3de
Run Code Online (Sandbox Code Playgroud)

mohe-bc_db_1docker ps: NAMES 列显示的 pg 容器名称

postgres: pg 用户名

mohe-bc_development: 数据库名称

~/Downloads/de8dc786-b133-4ae2-a040-dcf34f12c3de: pg db dump 的文件路径

它有效:

pg_restore: connecting to database for restore
pg_restore: dropping CONSTRAINT webhooks webhooks_pkey
pg_restore: dropping CONSTRAINT schema_migrations schema_migrations_pkey
pg_restore: dropping CONSTRAINT ar_internal_metadata ar_internal_metadata_pkey
pg_restore: dropping DEFAULT webhooks id
pg_restore: dropping SEQUENCE webhooks_id_seq
pg_restore: dropping TABLE webhooks
pg_restore: dropping TABLE schema_migrations
pg_restore: dropping TABLE ar_internal_metadata
pg_restore: creating TABLE "public.ar_internal_metadata"
pg_restore: creating TABLE "public.schema_migrations"
pg_restore: creating TABLE "public.webhooks"
pg_restore: creating SEQUENCE "public.webhooks_id_seq"
pg_restore: creating SEQUENCE OWNED BY "public.webhooks_id_seq"
pg_restore: creating DEFAULT "public.webhooks id"
pg_restore: processing data for table "public.ar_internal_metadata"
pg_restore: processing data for table "public.schema_migrations"
pg_restore: processing data for table "public.webhooks"
pg_restore: executing SEQUENCE SET webhooks_id_seq
pg_restore: creating CONSTRAINT "public.ar_internal_metadata ar_internal_metadata_pkey"
pg_restore: creating CONSTRAINT "public.schema_migrations schema_migrations_pkey"
pg_restore: creating CONSTRAINT "public.webhooks webhooks_pkey"
Run Code Online (Sandbox Code Playgroud)


Ber*_*ard 6

我认为在初始化阶段无法完成备份还原。启动您的容器,然后上传数据库。

docker run -d --name mydb mypgimage
docker exec mydb sh -c "pg_restore -C -d DB /var/lib/postgresql/backup/DB.backup"
Run Code Online (Sandbox Code Playgroud)