我想在数据库转储文件中搜索一些数据,但这些转储文件使用了二进制压缩格式(PGDMP
头)。
如何在不还原转储文件的情况下将其转换为SQL?
我想在数据库转储文件中搜索一些数据,但这些转储文件使用了二进制压缩格式(PGDMP
头)。
如何在不还原转储文件的情况下将其转换为SQL?
pg_restore
在没有数据库名称的情况下,会将文本转储输出到标准输出(stdout),您可以通过-f
或I/O重定向将其发送到其他位置。
pg_restore -f mydatabase.sql mydatabase.dump
请注意,您必须确保没有设置PGDATABASE
环境变量,否则它将尝试连接到该数据库。
我使用过的最快方法是:
pg_restore -f mybinaryfile.backup > mysqlfile.sql
没有特殊的标志,因为pg_restore只是将其输出到标准输出(stdout)。
-f
:pg_restore -f mybinaryfile.backup > mysqlfile.sql
。 - Alexpg_restore -f - --table=users my-backup.dump > users.sql
。 - psmithpg_restore --cluster 9.1/localhost:5433 -f db.sql db.pgsql
pgsql
命令确定端口号(5433),如下所示:pgsql --port 5433 template1
pgsql
连接时,它会写入一个注释,例如:
这意味着您正在运行 pgsql 9.3.6,并且端口 5433 引用服务器 9.1.13。psql (9.3.6, server 9.1.13)
netstat
命令,例如:sudo netstat -a64np | grep LISTEN | grep postgres
sudo
命令才能使用-p
选项来打印进程名称,从而获得端口列表(通常是TCP和UDP端口)。dpkg -l
命令获取已安装的集群列表,如下所示:dpkg -l '*postgres*'
以 "ii" 开头的条目(最左列)是当前已安装的。当然,您也可以使用其他Unix命令来帮助确定已安装的版本。
pg_restore: [archiver] input file does not appear to be a valid archive
。我可以向您保证,这些转储文件是使用相同版本的postgresql 8.4.17制作的。 - sorin