database 查看 postgresql 转储文件的简单方法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16224112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 08:56:38  来源:igfitidea点击:

Easy way to view postgresql dump files?

databasepostgresql-9.1pg-dump

提问by at.

I have a ton of postgresql dump files I need to peruse through for data. Do I have to install Postgresql and "recover" each one of them into new databases one by one? Or I'm hoping there's a postgresql client that can simply open them up and I can peek at the data, maybe even run a simple SQL query?

我有大量的 postgresql 转储文件,我需要仔细阅读数据。我是否必须安装 Postgresql 并将它们中的每一个“恢复”到新数据库中?或者我希望有一个 postgresql 客户端可以简单地打开它们并且我可以查看数据,甚至可以运行一个简单的 SQL 查询?

The dump files are all from a Postgresql v9.1.9 server.

转储文件全部来自 Postgresql v9.1.9 服务器。

Or maybe there's a tool that can easily make a database "connection" to the dump files?

或者也许有一种工具可以轻松地将数据库“连接”到转储文件?

UPDATE: These are not text files. They are binary. They come from Heroku's backup mechanism, this is what Heroku says about how they create their backups:

更新:这些不是文本文件。它们是二进制的。它们来自 Heroku 的备份机制,这就是Heroku 关于他们如何创建备份的说法

PG Backups uses the native pg_dump PostgreSQL tool to create its backup files, making it trivial to export to other PostgreSQL installations.

PG Backups 使用本机 pg_dump PostgreSQL 工具来创建其备份文件,从而可以轻松导出到其他 PostgreSQL 安装。

采纳答案by Igor Romanchenko

Try opening the files with text editor - the default dump format is plain text.

尝试使用文本编辑器打开文件 - 默认转储格式是纯文本。

If the dump is not plain text - try using pg_restore -l your_db_dump.filecommand. It will list all objects in the database dump (like tables, indexes ...).

如果转储不是纯文本 - 尝试使用pg_restore -l your_db_dump.file命令。它将列出数据库转储中的所有对象(如表、索引...)。

Another possible way (may not work, haven't tried it) is to grepthrough the output of pg_restore your_db_dump.filecommand. If I understood correctly the manual - the output of pg_restoreis just a sequence of SQL queries, that will rebuild the db.

另一种可能的方法(可能行不通,没试过)是grep通过pg_restore your_db_dump.file命令的输出。如果我正确理解手册 - 的输出pg_restore只是一系列 SQL 查询,这将重建数据库。

回答by jcuenod

This was what I was looking for:

这就是我要找的:

pg_restore db.bin > db.sql

Thanks @andrewtweber

谢谢@andrewtweber

回答by Aaron Gray

I had this same problem and I ended up doing this:

我遇到了同样的问题,我最终这样做了:

  1. Install Postgresql and PGAdmin3.
  2. Open PGAdmin3 and create a database.
  3. Right click the db and click restore.
  4. Ignore file type.
  5. Select the database dump file from Heroku.
  6. Click Restore.
  1. 安装 Postgresql 和 PGAdmin3。
  2. 打开 PGAdmin3 并创建一个数据库。
  3. 右键单击数据库,然后单击恢复。
  4. 忽略文件类型。
  5. 从 Heroku 中选择数据库转储文件。
  6. 单击恢复。

回答by AlexDev

In newer versions you need to specify the -fflag with a filename or '-' for stdout

在较新的版本中,您需要-f使用文件名或“-”为标准输出指定标志

pg_restore dump_file.bin -f -

回答by TonyTony

If you use pgAdmin on Windows, can just backup the file as plain text, there is one option when you do backup instead of pg_dump in command line prompt.

如果您在 Windows 上使用 pgAdmin,则可以将文件备份为纯文本,当您在命令行提示符下进行备份而不是 pg_dump 时,有一个选项。

回答by aleroot

Dump files are usually text file, if Not compressed, and you can open them with a text editor. Inside you will find all the queries that allow the reconstruction of the database ...

转储文件通常是文本文件,如果未压缩,您可以使用文本编辑器打开它们。在里面你会发现所有允许重建数据库的查询......