标签: pg-restore

postgres - 没有角色的 pg_dump 和 pg_restore

我正在尝试在没有接收数据库上的适当角色的情况下恢复转储。

如前所述这里也是在这里,你需要有--no-owner作为一个选项,无论是在pg_dumppg_restore或两者兼而有之。

我使用以下命令行来创建我的转储:

"C:\Program Files\PostgreSQL\9.3\bin\pg_dump.exe" --no-owner -Ft --dbname=postgresql://avo******:AV0******?@127.0.0.1:5432/BI_DB > K:\BI\backup\sort\bck_%timestamp%.tar
Run Code Online (Sandbox Code Playgroud)

恢复线如下:

"C:\Program Files\PostgreSQL\9.3\bin\pg_restore.exe" --host localhost --port 5432 --username "postgres" --dbname "BI_TEST2" --no-password  --no-owner --role=postgres --exit-on-error --verbose "D:\D\avo\backup\bck_04042017_1410.tar"
Run Code Online (Sandbox Code Playgroud)

如您所见,两者都有--no-owner选择,但最终出现以下错误:

在此处输入图片说明

最让我烦恼的是下面的日志:

pg_restore: [programme d'archivage (db)] Erreur pendant le traitement de la TOC (« PROCESSING TOC ») :
pg_restore: [programme d'archivage (db)] Erreur à partir de l'entrée TOC 2633 ; 0 0 ACL adm avo******
pg_restore: [programme d'archivage (db)] could not …
Run Code Online (Sandbox Code Playgroud)

postgresql restore postgresql-9.3 pg-dump pg-restore

18
推荐指数
3
解决办法
2万
查看次数

pg_restore 到一个新的数据库

我正在使用 Heroku 的 Postgres 选项并从中下载了一个备份。我想将它恢复到一个新的数据库中,以便我可以查看它。我一直在尝试不同的命令,但收效甚微。我的第一次尝试:

$ sudo -u postgres psql < db/backups/myapp_2018-05-27.pg.dump 
The input is a PostgreSQL custom-format dump.
Use the pg_restore command-line client to restore this dump to a database.
Run Code Online (Sandbox Code Playgroud)

所以我尝试:

$ sudo -u postgres pg_restore -d myapp3 -C db/backups/myapp_2018-05-27.pg.dump
pg_restore: [archiver (db)] connection to database "myapp3" failed: FATAL:  database "myapp3" does not exist
Run Code Online (Sandbox Code Playgroud)

我真的不明白这个-C选项

-C --创建

在恢复之前创建数据库。如果还指定了 --clean,则在连接之前删除并重新创建目标数据库。

使用此选项时,以 -d 命名的数据库仅用于发出初始 DROP DATABASE 和 CREATE DATABASE 命令。所有数据都恢复到出现在存档中的数据库名称。

恢复到新数据库对我来说似乎是合乎逻辑的。我离题了……(也许这里已经正确解释

我尝试从另一个具有相同架构的较早版本的模板创建一个新数据库:

$ …
Run Code Online (Sandbox Code Playgroud)

postgresql restore pg-restore

14
推荐指数
2
解决办法
2万
查看次数

带有 `jobs` 标志的 `pg_restore` 导致 `pg_restore: 错误:一个工作进程意外死亡`

我有一个运行以下内容的脚本:

pg_restore tmp/latest.backup --verbose --clean --no-acl --no-owner --dbname hub_development --jobs=12
Run Code Online (Sandbox Code Playgroud)

这经常失败并出现以下错误:

error: could not find block ID 4584 in archive -- possibly due to out-of-order restore request, which cannot be handled due to lack of data offsets in archive

pg_restore: error: a worker process died unexpectedly
Run Code Online (Sandbox Code Playgroud)

反过来,这个错误意味着应该有索引、主键等的表最终没有它们。例如,在没有多核的情况下运行时,我们的users表如下所示,正如预期的那样:


                                           Table "public.users"
       Column       |            Type             | Collation | Nullable |              Default              
--------------------+-----------------------------+-----------+----------+-----------------------------------
 id                 | integer                     |           | not null | nextval('users_id_seq'::regclass)
 created_at         | timestamp without time zone |           | not null …
Run Code Online (Sandbox Code Playgroud)

postgresql pg-restore

9
推荐指数
1
解决办法
1366
查看次数

pg_restore --clean 不起作用,因为级联下降

DB-B我正在使用数据库 ( ) 的副本( DB-A),我通过每天运行来保持最新状态:

pg_restore -U postgres -d someDB --clean -j 2 -L WhatToImportList admin.dump
Run Code Online (Sandbox Code Playgroud)

但我开始注意到DB-B表中存在重复记录。经过进一步调查,似乎--clean没有将表删除,DB-B因为它需要对 my 中DB-B但不在 origin 中的其他表和视图进行级联删除DB-A

  1. 是否可以强制导入数据而不进行级联删除?我想保留所有自定义表格、视图和函数!
  2. DB-A如果不是,那么什么是一个好的复制策略,我可以从中导入数据,DB-B但保留分析所需的所有函数、视图和表DB-B

谢谢。

编辑:可能的解决方法:截断每个表,然后导入它们...但我必须在脚本中包含每个表。

Edit2:为了帮助未来的读者,这样可以生成所有必须截断的表的列表:

SELECT 'TRUNCATE ' || table_name || ';'
  FROM information_schema.tables
 WHERE table_schema='my_schema'
   AND table_type='BASE TABLE';
Run Code Online (Sandbox Code Playgroud)

postgresql pg-restore

8
推荐指数
0
解决办法
2810
查看次数

使用与源数据库相同的语言环境设置还原 PostgreSQL 数据库

我在Ubuntu 14.04 LTS生产机器上有一个 PostreSQL 9.x 数据库。我的开发机器是基于Windows 7的,提供 PostreSQL 9.y。

我想在我的开发机器上恢复 Ubuntu PostreSQL 数据库。

我注意到 Ubuntu 数据库使用以下语言环境设置:

  • 字符集编码=UTF8
  • 整理顺序,字符串排序顺序=en_US.UTF-8
  • 字符类型,字符分类=en_US.UTF-8

当我在没有指定语言环境的情况下在 Windows 机器上恢复数据库时,它将被设置为

  • 字符集编码=UTF8
  • 整理顺序,字符串排序顺序=German_Germany.1252
  • 字符类型,字符分类=German_Germany.1252

我的计划是让我的开发机器上的数据库尽可能类似于我的 Ubuntu 机器上的数据库。所以我的想法是首先在我的 Windows 机器上创建一个具有生产匹配语言环境的数据库,然后将我的 Ubuntu 数据库prod-db.backup备份文件恢复到该创建的数据库中:

createdb --host=localhost --username=postgres --encoding=Unicode --lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8 --owner=prod prod-db
pg_restore --host=localhost --username=postgres --format=custom prod-db.backup --dbname=prod-db
Run Code Online (Sandbox Code Playgroud)

这个想法不起作用,因为createdb在 Windows 上会抱怨错误无效的语言环境名称 en_US.UTF-8

我去了一个狩猎找到Windows区域名称相匹配的Ubuntu的语言环境名称,其中包括使用的解决方案template0中模板的数据库,不同的区域设置标识符,如实验en_US.UTF-8 …

postgresql pg-restore

7
推荐指数
1
解决办法
8979
查看次数

在 Postgres 9.6.2 数据库上执行 pg_restore 时,此错误意味着什么?

所以我有一个在 Heroku 上运行的 Rails 5.0.x 应用程序和 Postgres 9.6.1。我拉下来做一个pg_restore --exit-on-error --verbose --clean --no-acl --no-owner -h localhost -d database_development ~/Documents/Backups/myproduction.dump

我收到以下错误:

pg_restore: connecting to database for restore
pg_restore: dropping FK CONSTRAINT trial_versions fk_rails_f888baa05c
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 3091; 2606 16768 FK CONSTRAINT trial_versions fk_rails_f888baa05c u7dok58iar41mh
pg_restore: [archiver (db)] could not execute query: ERROR:  constraint "fk_rails_f888baa05c" of relation "trial_versions" does not exist
    Command was: ALTER TABLE ONLY "public"."trial_versions" DROP CONSTRAINT "fk_rails_f888baa05c";
Run Code Online (Sandbox Code Playgroud)

这个错误告诉我什么?我以前从未遇到过这个问题。这最近才开始发生,我需要先了解错误,然后才能开始对其进行故障排除。

postgresql pg-restore postgresql-9.6

7
推荐指数
1
解决办法
1万
查看次数

为什么我的 pg_restore 命令不起作用?

昨天,我使用以下命令创建了各种 PostgreSQL 数据库的备份:

pg_dump -Fc -d junk -h localhost -p 5434 -U postgres -W > z:\pg_dump\96_junk.dump
Run Code Online (Sandbox Code Playgroud)

我为每个数据库创建了单独的备份。

今天,我尝试使用以下命令将它们恢复到升级后的数据库服务器:

pg_restore -h localhost -p 5434 -U postgres -W -C -v z:\pg_dump\96_junk.dump
Run Code Online (Sandbox Code Playgroud)

当我pg_restore使用上面的命令运行时,数据库似乎已恢复。控制台屏幕显示一系列 SQL 语句和我希望看到的该数据库的其他消息,最后显示的输出是“PostreSQL 数据库转储完成”。

当我检查数据库时,数据库不存在。我究竟做错了什么?

使用版本信息

  • 使用版本9.6.0创建的备份

  • 尝试使用版本9.6.1进行恢复

postgresql backup restore pg-restore postgresql-9.6

6
推荐指数
1
解决办法
3万
查看次数

错误:类型金钱的输入语法无效

导入时出现此错误:

pg_restore: [archiver (db)] COPY failed for table "transaction_details":
ERROR:  invalid input syntax for type money: "$0.00"
Run Code Online (Sandbox Code Playgroud)

restore完成,但transaction_details桌子是空的。这是 Heroku 的 PostgreSQL Dump 数据库。

Heroku 上的 PostgreSQL 版本是 9.3.15,在我的系统上也是如此

我使用的命令:

pg_restore: [archiver (db)] COPY failed for table "transaction_details":
ERROR:  invalid input syntax for type money: "$0.00"
Run Code Online (Sandbox Code Playgroud)

有人可以提出解决方案吗?

postgresql money restore postgresql-9.3 pg-restore

6
推荐指数
1
解决办法
4281
查看次数

pg_restore 错误:“关系不存在”并创建新数据库

我已经备份了我想要恢复到新数据库中的特定表,使用:

call pg_dump -Fc -h server -d database -U user -p password -v -f dump.sql -t public.table1 -t public.table2
Run Code Online (Sandbox Code Playgroud)

我没有问题。

然后我想通过使用 pg_restore 创建一个新数据库来恢复转储:

call pg_restore --clean --create -d temp -h server -p password -U user dump.sql
Run Code Online (Sandbox Code Playgroud)

这给了我一个“数据库临时不存在”的错误。据我所知,这应该已经创建了数据库并恢复了它。

但是,我然后手动创建“临时”数据库并运行:

call pg_restore --clean --create -d temp -h server -p password -U user dump.sql
Run Code Online (Sandbox Code Playgroud)

这将贯穿始终,但不会创建表并给我一个错误“ relation table1”和“ relation table2”不存在,并且只为两个表创建相应的 id_sewuences。

我真正想要的是不必手动创建新数据库,并且备份中的所有表都通过 pg_restore 使用以下命令恢复到全新的数据库中:

call pg_restore --clean --create -d temp -h server -p password -U user dump.sql
Run Code Online (Sandbox Code Playgroud)

据我了解。

请帮助,非常令人沮丧

postgresql psql pg-dump exists pg-restore

6
推荐指数
1
解决办法
1万
查看次数

pg_restore 无限期地挂在终端中,详细模式下输出为零

我正在尝试恢复在全新安装的版本 14.1 上在版本 11.7 上创建的 PostgreSQL 备份。

运行 pg_restore 命令时,即使启用了详细日志记录,它也会无限期地挂在终端上,输出为零。尝试以不存在的用户身份进行连接甚至不会给出错误。通过 psql 连接工作正常,我可以毫无问题地执行命令。

使用以下命令创建转储: pg_dump -Fc -f file.pgdump -d mydb

我尝试将转储从另一台主机恢复到有问题的主机(将其恢复到其自己的 PostgreSQL 14.1 本地实例没有问题的主机),这导致了同样的问题。这是我正在使用的命令:pg_restore -f file.pgdump -U user -j 6 --verbose

事实上,我从pg_restore命令得到的反馈为零,这使得诊断变得相当困难。可能是什么问题?

postgresql pg-restore

6
推荐指数
1
解决办法
6983
查看次数