PostgreSQL:从转储还原数据库 - 语法错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1797954/
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
PostgreSQL: database restore from dump - syntax error
提问by Hoff
I'm trying to restore a PostgreSQL database by executing the SQL that pg_dump created, on an empty database.
我正在尝试通过在空数据库上执行 pg_dump 创建的 SQL 来恢复 PostgreSQL 数据库。
I'm getting this error:
我收到此错误:
ERROR: syntax error at or near "\"
LINE 5211: \.
lines 5210 and 5211 read:
第 5210 和 5211 行内容如下:
COPY auth_group (id, name) FROM stdin;
\.
It works fine on my Linux server, where I use this command:
它在我的 Linux 服务器上运行良好,我在其中使用以下命令:
psql -U dbname < dumpfile.sql
psql -U dbname < dumpfile.sql
but on Windows, I'm not sure how to do the same, so I've been trying to run the dumpfile's sql from pgAdminIII query utility.
但是在 Windows 上,我不确定如何做同样的事情,所以我一直在尝试从 pgAdminIII 查询实用程序运行转储文件的 sql。
What the recommended way of importing a db from a dump on Windows? Or: how can that syntax issue be resolve?
从 Windows 上的转储导入数据库的推荐方法是什么?或者:如何解决语法问题?
Any help is much appreciated!
任何帮助深表感谢!
Martin
马丁
回答by John Paulett
The -f filename
argument on psqlwill read in the file, so you don't have to pipe it in. psql should be included in PostgreSQL's bin directory in windows. Like so:
psql-f filename
上的参数将读入文件,因此您不必通过管道将其导入。psql 应包含在 Windows 中 PostgreSQL 的 bin 目录中。像这样:
psql -d dbname -U username -f dumpfile.sql
You may have to include a full path to the psql executable if it is not on your path, and possible add ".exe" to psql, so it is "psql.exe".
如果 psql 可执行文件不在您的路径上,您可能必须包含该 psql 可执行文件的完整路径,并且可能将“.exe”添加到 psql,因此它是“psql.exe”。
Also make sure you are not going down in version numbers, I've run into syntax issues before (e.g don't export an 8.4 database and try to load it into an 8.1 database). If so, you may have to manually edit the dump file.
还要确保您的版本号没有下降,我之前遇到过语法问题(例如,不要导出 8.4 数据库并尝试将其加载到 8.1 数据库中)。如果是这样,您可能需要手动编辑转储文件。
回答by Kai Huppmann
try with psql -d dbname -U user -fdumpfile.sql
尝试使用 psql -d dbname -U user -fdumpfile.sql