AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题

问题[pg-restore](dba)

Martin Hope
Sajith P Shetty
Asked: 2022-09-02 21:42:53 +0800 CST

pg_restore 错误:模式“公共”已经存在(版本间恢复)

  • 0

这是一个特定场景,我们将从 Postgres 10 提取的自定义转储恢复到 Postgres 14。我们收到以下错误:

错误:架构“公共”已经存在

我了解可以忽略 ERROR 并成功恢复所有后续对象。但是,由于我们是从 JAVA 程序调用 pg_Restore ,因此错误是返回 0 以外的退出代码并退出程序。当然,我们可以调整 JAVA 代码,以便通过解析此错误消息,我们可以隐藏退出代码。但我们仍然认为这不是一个理想的解决方案。还有其他 PG 方法可以避免此错误吗?

尝试的选项:

  • 在还原之前删除并重新创建数据库。

  • 使用“-n public”实际上可以避免错误。但这会在恢复时忽略大对象。

  • 此处提出的解决方案 -答案

还没有运气!此错误或警告仅在还原旧版本转储时出现。

我们为什么不首先修复 pg_restore 源代码以在创建模式语句中使用“如果不存在”?

postgresql pg-restore
  • 1 个回答
  • 43 Views
Martin Hope
Sajith P Shetty
Asked: 2022-08-26 23:02:56 +0800 CST

pg_restore:“-n”选项不导入大对象

  • 0

我正在尝试使用 -n 选项从转储中导入数据库“demodb”。目的是仅导入称为“demoschema”的特定模式。在运行 pg_Restore 之前,我将 demodb 创建为空白数据库。我运行以下命令进行恢复:

pg_restore -d demodb -n demoschema dumpfile

现在的问题是还原后 pg_largeobject 表为空。如果我删除选项“-n demoschema”,pg_largeobject 也将被恢复。

如何使用选项“-n”并确保恢复像 pg_largeobject 这样的目录表?

postgresql pg-restore
  • 1 个回答
  • 31 Views
Martin Hope
flwd
Asked: 2022-01-11 08:38:41 +0800 CST

pg_restore 在详细模式下无限期挂起,输出为零

  • 0

我正在尝试在 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
  • 1 个回答
  • 1321 Views
Martin Hope
botenvouwer
Asked: 2021-01-15 15:21:07 +0800 CST

互联网连接丢失后 pg_restore 是否继续

  • 0

我知道查询会一直运行,直到它在与客户端的连接丢失时返回数据。但是,如果您使用 pg_restore。它是否上传还原文件,然后在服务器上进行还原?还是逐步恢复要求客户端保持连接。

我想知道这一点,因为我的员工使用的 vpn 会在一段时间后自动断开连接。并且恢复时间比超时 XD 更长。

当连接丢失时,我得到了pg_restore: error: error returned by PQputCopyData: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. 错误。

但是在服务器上,我可以看到该过程仍在使用中运行SELECT * FROM pg_stat_activity;

postgresql pg-restore
  • 1 个回答
  • 445 Views
Martin Hope
Richie Thomas
Asked: 2020-01-15 10:37:37 +0800 CST

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

  • 9

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

pg_restore tmp/latest.backup --verbose --clean --no-acl --no-owner --dbname hub_development --jobs=12

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

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

反过来,这个错误意味着应该有索引、主键等的表最终没有它们。例如,当在没有多核的情况下运行时,我们的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 | 
 updated_at         | timestamp without time zone |           | not null | 
 email              | character varying           |           | not null | 
 confirmation_token | character varying(128)      |           |          | 
 name               | character varying           |           | not null | ''::character varying
 user_type          | character varying           |           |          | 
 encrypted_password | character varying(128)      |           |          | 
 remember_token     | character varying(128)      |           |          | 
Indexes:
    "users_pkey" PRIMARY KEY, btree (id)
    "index_users_on_email" btree (email)
    "index_users_on_remember_token" btree (remember_token)
Referenced by:
    TABLE "project_feedback_users" CONSTRAINT "fk_rails_08af49ba47" FOREIGN KEY (user_id) REFERENCES users(id)
    TABLE "client_reviews" CONSTRAINT "fk_rails_8fc606dbea" FOREIGN KEY (user_id) REFERENCES users(id)

多核运行时,表格如下所示:


hub_development=# \d 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 | 
 updated_at         | timestamp without time zone |           | not null | 
 email              | character varying           |           | not null | 
 confirmation_token | character varying(128)      |           |          | 
 name               | character varying           |           | not null | ''::character varying
 user_type          | character varying           |           |          | 
 encrypted_password | character varying(128)      |           |          | 
 remember_token     | character varying(128)      |           |          | 

基于此,我得出的结论是,创建表本身的同一个工作人员也不负责添加索引和外键,第二个工作人员试图在第一个工作人员之前运行,这导致了我观察到的错误.

当我删除--jobs=12标志时脚本工作正常,最坏的情况是我只是这样做。

但是,对于我自己的教育,我很想知道是否有一种解决方案可以保留我们使用多核并行化数据库还原的能力,同时避免无序的还原请求。

该错误提到由于存档中缺少数据偏移量而无法处理乱序恢复请求。添加这些数据偏移量会以我描述的方式解决问题吗?如果是这样,我将如何去做,这样做有什么缺点吗?

我不是数据库管理员,我在这里的知识有限,所以如果我没有提供足够的信息来回答这个问题,请告诉我。

我的 Postgres 本地版本是 12.1,数据来自 Heroku 上托管的 Rails 应用程序。这是结果heroku pg:info:

=== HEROKU_POSTGRESQL_BRONZE_URL, DATABASE_URL
Plan:                  Standard 0
Status:                Available
Data Size:             3.38 GB
Tables:                44
PG Version:            11.5
Connections:           22/120
Connection Pooling:    Available
Credentials:           1
Fork/Follow:           Available
Rollback:              earliest from 2020-01-10 18:17 UTC
Created:               2019-10-29 18:20 UTC
Region:                us
Data Encryption:       In Use
Continuous Protection: On
Maintenance:           not required
Maintenance window:    Wednesdays 18:00 to 22:00 UTC
Add-on:                postgresql-metric-02684
postgresql pg-restore
  • 3 个回答
  • 2461 Views
Martin Hope
Ricky Sixx
Asked: 2019-07-25 01:37:48 +0800 CST

OpenProject pg_restore - 输入文件似乎不是有效的存档

  • 1

我正在尝试恢复使用命令创建的 OpenProject 数据库

sudo openproject run backup

此命令创建了postgresql-dump-20190722131834.pgdump我尝试使用该命令恢复的文件

pg_restore --host=localhost --dbname=openproject postgresql-dump-20190722131834.pgdump

但它返回了我的错误

pg_restore: [archiver] input file does not appear to be a valid archive

我也尝试将--format=c选项添加到pg_restore命令,但错误更改为

pg_restore: [archiver] did not find magic string in file header

OpenProject 运行以创建 PostgreSQL 备份的脚本是:

dump_postgresql() {
  dst="${TARGET}/postgresql-dump-${timestamp}.pgdump"
  touch "$dst" && chmod 0640 "$dst"
  pg_dump -Fc $DATABASE_URL > $dst

  echo " done" >&2
  echo "$dst"
}

我还注意到pg_dump打印了很多这样的警告:

pg_dump: [custom archiver] WARNING: ftell mismatch with expected position -- ftell used

我正在尝试在运行 Ubuntu 18.04 和 PostgreSQL 10 的机器上恢复数据库。

这是命令的结果head postgresql-dump-20190722131834.pgdump(我把它放在屏幕截图中,因为有一些我无法复制粘贴的无效字符): 头部命令结果

postgresql pg-restore
  • 1 个回答
  • 8041 Views
Martin Hope
Zach Smith
Asked: 2019-07-17 05:38:07 +0800 CST

如何恢复通过旧版本的 postgres 创建的 postgres 数据库?

  • 2

我有一个文件db.backup,我想恢复到 PostgreSQL 版本 11。

当我尝试通过 Azure Data Studio 安装时,出现错误:

恢复:pg_restore: [archiver] 文件头中不支持的版本 (1.13)

然后我发现运行pg_restore我实际上可以读取文件:

pg_restore /..db.backup -U postgres > db-restore.sql

我可以看到该文件是人类可读的。但是我更愿意从备份中恢复数据库。

我怎样才能做到这一点?我尝试安装旧版本的 PostgreSQL 服务器,但我不知道如何安装旧版本的 PSQL(还)。这会有帮助吗?

是否有一些标志可以添加到恢复命令中以便恢复工作?

- 编辑

的输出pg_restore --version,即那个版本pg_restore给了我上面提到的错误信息:

pg_restore (PostgreSQL) 11.4 (Ubuntu 11.4-1.pgdg18.04+1)

postgresql pg-restore
  • 1 个回答
  • 6669 Views
Martin Hope
Reinstate Monica
Asked: 2018-08-31 15:19:23 +0800 CST

用 pg_restore 替换数据库

  • 1

我正在尝试用现有数据库替换现有数据库pg_restore并遇到问题。如果这个问题很简单,我很抱歉。

具体来说,我的 Postgres 安装设置如下:

  • postgres拥有的数据库root
  • d拥有的数据库u
  • restore拥有的数据库u(稍后会详细介绍)

我创建了一个像pg_dump --format=custom .... 我现在正试图d用该转储的内容替换。具体来说,我正在运行类似pg_restore -cC --dbname=$DB --exit-on-error --format=custom --username=$USER.

但似乎无论 和 的什么组合$DB,$USERPostgres 都无法恢复。从错误消息(如下)来看,Postgres 似乎希望用户同时root是d. 我已阅读手册页并尝试了各种组合但无济于事。

我究竟做错了什么?


具体来说,如果$DB是d,不管$USER,我得到

错误:无法删除当前打开的数据库

命令是:DROP DATABASE d;

很公平。所以让我们尝试$DB=postgres一下$USER=root:

错误:必须是数据库 d 的所有者

命令是:DROP DATABASE d;

$DB=postgres好的,让我们尝试一下$USER=u:

错误:必须是角色“root”的成员

命令是:ALTER DATABASE d OWNER TO root;

嗯?也许这与登录?postgres所拥有的root? 让我们尝试$DB=restore(专门为此目的创建)和$USER=u:

错误:必须是角色“root”的成员

命令是:ALTER DATABASE d OWNER TO root;

postgresql pg-restore
  • 1 个回答
  • 1861 Views
Martin Hope
Rogerlr
Asked: 2018-05-24 11:06:49 +0800 CST

如何使用 PG_RESTORE 恢复功能

  • 3

我做了我的数据库的备份:

-bash-4.2$ pg_dump -d mydb --format=custom -f /tmp/dump 
-bash-4.2$ 

下面检查,我在那里看到了我的功能:

-bash-4.2$ pg_restore -l /tmp/dump | grep -i addconf
233; 1255 39949 FUNCTION public addconfiguration(text) mydb
247; 1255 39950 FUNCTION public addconfiguration2(text) mydb
273; 1255 39951 FUNCTION public addconfiguration3(text) mydb

然后我尝试使用 Postgres pg_restore指令恢复一个函数:

-bash-4.2$ pg_restore -d postgres --function=addconfiguration2(text) -v /tmp/dump 
-bash: syntax error near unexpected token `('

我也尝试不使用括号和 arg,但它没有用:

-bash-4.2$ pg_restore -d postgres --function=addconfiguration2 -v /tmp/dump 
pg_restore: connecting to database for restore
pg_restore: implied data-only restore

在尝试之后,我验证了该函数是否是使用\df内部 psql 创建的,但没有成功。

如何使用 pg_restore 恢复函数?

postgresql pg-restore
  • 1 个回答
  • 3044 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve