How do I convert a binary pgdump (compressed) to a plain SQL file?

ぃ、小莉子 提交于 2019-12-20 10:17:24

问题


I do want to search for some data inside a database dump but these dumps are using the binary-compressed format (PGDMP header).

How can I convert these to SQL without restoring them?


回答1:


pg_restore, when run without a database name, outputs a text dump to stdout; you can send that elsewhere with -f or with I/O redirection.

pg_restore -f mydatabase.sql mydatabase.dump 



回答2:


The fastest method that I've used was:

pg_restore mybinaryfile.backup > mysqlfile.sql

No special flags, since pg_restore just spits it out to stdout.




回答3:


Note that if you run multiple clusters, the restore command may not like the default version...

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

In that case you have to specify the version, host and port as in:

pg_restore --cluster 9.1/localhost:5433 -f db.sql db.pgsql

(note that the host:port info is ignored with the -f option.)

The port (5433) can be determined using the pgsql command as in:

pgsql --port 5433 template1

When pgsql connects, it writes a comment such as:

psql (9.3.6, server 9.1.13)

This means you are running pgsql 9.3.6 and that port 5433 references server 9.1.13.

If you are not sure which ports are currently used, you may use the netstat command as in:

sudo netstat -a64np | grep LISTEN | grep postgres

The sudo is required for the -p option which prints the process name. That gives you a list of ports (usually TCP and UDP ports).

Finally, on a Debian/Ubuntu system, you can get a list of installed clusters with the dpkg -l command as in:

dpkg -l '*postgres*'

The list of entries that start with 'ii' (left most column) are currently installed. You, of course, have similar commands for other Unices to help you determine installed versions.



来源:https://stackoverflow.com/questions/21429335/how-do-i-convert-a-binary-pgdump-compressed-to-a-plain-sql-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!