我试图恢复我的转储文件,但它导致了一个错误:
psql:psit.sql:27485: invalid command \N
有解决办法吗?我找了,但没有得到明确的答案。
我试图恢复我的转储文件,但它导致了一个错误:
psql:psit.sql:27485: invalid command \N
有解决办法吗?我找了,但没有得到明确的答案。
当前回答
我遵循了所有这些例子,它们都失败了,出现了我们正在谈论的错误:
在Postgres中将一个表从一个数据库复制到另一个数据库
有效的是使用-C的语法,请看这里:
pg_dump -C -t tableName "postgres://$User:$Password@$Host:$Port/$DBName" | psql "postgres://$User:$Password@$Host:$Port/$DBName"
此外,如果两者之间有不同的模式,我发现改变一个dB的模式以匹配其他的表副本是必要的,例如:
DROP SCHEMA public;
ALTER SCHEMA originalDBSchema RENAME TO public;
其他回答
Postgres使用\N作为NULL值的替代符号。但是所有psql命令都以反斜杠\符号开始。当复制语句失败,但转储的加载仍在继续时,您可以获得这些消息。这条消息是假警报。如果希望看到COPY语句失败的真正原因,则必须搜索此错误之前的所有行。
可以切换psql到“第一个错误停止”模式,并找到错误:
psql -v ON_ERROR_STOP=1
在我的例子中,问题是在我的目标计算机上缺少磁盘空间。简单地增加本地存储为我解决了它。
希望这能帮助到一些人;)
我遵循了所有这些例子,它们都失败了,出现了我们正在谈论的错误:
在Postgres中将一个表从一个数据库复制到另一个数据库
有效的是使用-C的语法,请看这里:
pg_dump -C -t tableName "postgres://$User:$Password@$Host:$Port/$DBName" | psql "postgres://$User:$Password@$Host:$Port/$DBName"
此外,如果两者之间有不同的模式,我发现改变一个dB的模式以匹配其他的表副本是必要的,例如:
DROP SCHEMA public;
ALTER SCHEMA originalDBSchema RENAME TO public;
可以使用INSERTS语句和——INSERTS参数生成转储。
In my recent experience, it's possible to get this error when the real problem has nothing to do with escape characters or newlines. In my case, I had created a dump from database A with pg_dump -a -t table_name > dump.sql and was trying to restore it to database B with psql < dump.sql (after updating the proper env vars, of course) What I finally figured out was that the dump, though it was data-only (the -a option, so that the table structure isn't explicitly part of the dump), was schema-specific. That meant that without manually modifying the dump, I couldn't use a dump generated from schema1.table_name to populate schema2.table_name. Manually modifying the dump was easy, the schema is specified in the first 15 lines or so.