使用 pg_restore 从较新版本的 PostgreSQL 恢复

发布于 2024-10-10 05:51:35 字数 724 浏览 0 评论 0原文

我有一台运行 PostgreSQL v9.0 的(生产)数据库服务器和一台运行 PostgreSQL v8.4 的开发机器。我想转储生产数据库并在开发计算机上使用它。我无法升级开发机器上的 postgres。

在生产计算机上,我运行:

pg_dump -f nvdls.db -F p -U nvdladmin nvdlstats

在开发计算机上,我运行:

pg_restore -d nvdlstats -U nvdladmin nvdls.db

我收到此错误:

pg_restore: [archiver] unsupported version (1.12) in file header

无论我在转储时选择自定义、tar 或 plain_text 格式,都会发生这种情况。

我发现一个在线讨论建议我应该使用更新版本的pg_restore 在开发机器上。我通过简单地将 9.0 二进制文件复制到开发计算机来尝试此操作,但由于链接问题而失败(不出意外)。

我认为使用纯文本转储的目的是它是原始的、可移植的 SQL。显然不是。

如何将 9.0 DB 添加到 8.4 安装中?

I have a (production) DB server running PostgreSQL v9.0 and a development machine running PostgreSQL v8.4. I would like to take a dump of the production DB and use it on the development machine. I cannot upgrade the postgres on the dev machine.

On the production machine, I run:

pg_dump -f nvdls.db -F p -U nvdladmin nvdlstats

On the development machine, I run:

pg_restore -d nvdlstats -U nvdladmin nvdls.db

And I got this error:

pg_restore: [archiver] unsupported version (1.12) in file header

This occurs regardless of whether I choose the custom, tar, or plain_text format when dumping.

I found one discussion online which suggests that I should use a newer version of pg_restore on the dev machine. I tried this by simply copying the 9.0 binary to the dev machine, but this fails (not unexpectedly) due to linking problems.

I thought that the point of using a plain_text dump was that it would be raw, portable SQL. Apparently not.

How can I get the 9.0 DB into my 8.4 install?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

谎言 2024-10-17 05:51:35

pg_restore用于恢复以“自定义”格式获取的转储。

如果您执行“纯文本”转储,则必须使用 psql 来运行生成的 SQL 脚本:

psql -f nvdls.db dbname username 

pg_restore is only for restoring dumps taken in the "custom" format.

If you do a "plain text" dump you have to use psql to run the generated SQL script:

psql -f nvdls.db dbname username 
枫以 2024-10-17 05:51:35

不支持使用 pg_dump/pg_restore 从 9.0 移动到 8.4 - 仅支持向前移动。

但是,您通常可以获取数据(在仅数据转储中),并且在某些情况下您可以获得架构 - 但这主要是运气,这取决于您使用的功能。

您通常应该使用 pg_dump 和 pg_restore 的目标版本 - 这意味着在这种情况下您应该使用 8.4 中的二进制文件。但您应该使用 pg_dump 和 pg_restore 的相同版本。这两个工具都可以在网络上正常工作,因此不需要复制二进制文件。

正如 a_horse_with_no_name 所说,您最好在纯文本模式下使用 pg_dump - 这将允许您在必要时手动编辑转储。特别是,您可以制作一种仅模式转储(使用 -s)和一种仅数据转储 - 只有模式转储可能需要任何编辑。

Using pg_dump/pg_restore to move from 9.0 to 8.4 is not supported - only moving forward is supported.

However, you can usually get the data across (in a data-only dump), and in some cases you can get the schema - but that's mostly luck, it depends on which features you're using.

You should normally use the target version of pg_dump and pg_restore - meaning in this case you should use the binaries from 8.4. But you should use the same version of pg_dump and pg_restore. Both tools will work fine across the network, so there should be no need to copy the binaries around.

And as a_horse_with_no_name says, you may be better off using pg_dump in plaintext mode - that will allow you to hand-edit the dump if necessary. In particular, you can make one schema only dump (with -s) and one data only dump - only the schema dump is likely to require any editing.

美男兮 2024-10-17 05:51:35

如果 9.0 数据库包含任何 bytea 列,那么更大的问题还在等待着。

这些列将由 pg_dump 使用“十六进制”表示形式导出,并显示在转储文件中,如下所示:

SELECT pg_catalog.lowrite(0, '\x0a2')

9.0 以下的任何版本的 postgres 后端都无法理解 bytea 的十六进制表示形式,并且我找不到告诉 9.0 端的 pg_dump 不要使用它的选项。将数据库或整个服务器的默认“bytea_output”设置设置为 ESCAPE 似乎会被 pg_dump 忽略。

我想可以对转储文件进行后处理,并实际上将每个十六进制编码的 bytea 值更改为转义值,但是无法追踪地破坏通常存储在 bytea 中的内容(图像、PDF 等)的风险并不存在。让我兴奋。

If the 9.0 database contains any bytea columns, then bigger problems await.

These columns will be exported by pg_dump using the "hex" representation and appear in your dump file like:

SELECT pg_catalog.lowrite(0, '\x0a2')

Any version of the postgres backend below 9.0 can't grok the hex representation of bytea, and I can't find an option to tell pg_dump on the 9.0 side to not use it. Setting the default "bytea_output" setting to ESCAPE for either the database or the whole server is seemingly ignored by pg_dump.

I suppose it would be possible to post-process the dump file and actually change every hex-encoded bytea value to an escaped one, but the risk of untraceably corrupting the kind of things normally stored in a bytea (images, PDFs etc) does not excite me.

隱形的亼 2024-10-17 05:51:35

我通过将 postgresql 从 8.X 升级到 9.2.4 解决了这个问题。如果您在 Mac OS-X 上使用brew,请使用 -

brew upgrade postgresql

完成此操作后,只需确保新的 postgres 安装位于路径的顶部即可。它看起来像这样(取决于版本安装路径)-

export PATH=/usr/local/Cellar/postgresql/9.2.4/bin:$PATH

I solved this by upgrading postgresql from 8.X to 9.2.4. If you're using brew on Mac OS-X, use -

brew upgrade postgresql

Once this is done, just make sure your new postgres installation is at the top of your path. It'll look something like (depending on the version installation path) -

export PATH=/usr/local/Cellar/postgresql/9.2.4/bin:$PATH
你好,陌生人 2024-10-17 05:51:35

我有同样的问题。我使用 pgdump 和 psql 来导出/导入数据库。

1.设置PGPASSWORD

export PGPASSWORD='h0ld1tn0w';

2.使用pg_dump导出DB

pg_dump -h <<host>> -U <<username>> <<dbname>> > /opt/db.out 

/opt/db.out是转储路径。您可以自己指定。

3.然后重新设置另一台主机的PGPASSWORD。如果主机相同或密码相同,则不需要。

4.在另一台主机上导入数据库

psql -h <<host>> -U <<username>> -d <<dbname>> -f /opt/db.out

如果用户名不同,则在 db.out 文件中查找并替换为您的本地用户名。并确保替换用户名而不是数据。

I had same issue. I used pgdump and psql for export/import DB.

1.Set PGPASSWORD

export PGPASSWORD='h0ld1tn0w';

2.Export DB with pg_dump

pg_dump -h <<host>> -U <<username>> <<dbname>> > /opt/db.out 

/opt/db.out is dump path. You can specify of your own.

3.Then set again PGPASSWORD of you another host. If host is same or password is same then this is not required.

4.Import db at your another host

psql -h <<host>> -U <<username>> -d <<dbname>> -f /opt/db.out

If username is different then find and replace with your local username in db.out file. And make sure on username is replaced and not data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文