在 PG 8.4 上做了 pg_dump 并尝试在 PG 9.1 上恢复。
我的一些数据包含分号,例如:
351717»·0»2014-04-28 13:26:23.119418»·2014-04-28 13:26:23.119418»·94642.000»1»0.000»LEASE»
1997-03-17 21:00:00»MACA»·0.000»0.000»0.000»
In favour of JOHN SMITH and BETTY SMITH; as joint tenants, for the term of 30 years
commencing on 86-08-01.»·\N»·\N»·NOT_APPLICABLE»·\N»·f»f»\N»·\N»·\N»·\N»·\N»·\N»·0.00000»\N»
但是,psql restore 被分号阻塞,并且被换行符 (\N) 搞糊涂了;
ERROR: syntax error at or near "as"
LINE 1: as joint tenants, for the term of 30 years commencing on 86-...
^
invalid command \N
invalid command \N
invalid command \N
如何告诉 psql 正确解释这些数据?
谢谢, 蒂姆
最佳答案
@ Richard Huxton - 感谢您提供正确方向的提示。 -Fc 选项是我所需要的,并且使用 pg_restore 而不是将还原文件通过管道传输到 psql。
所以,我最终做了:
pg_dump polar -f polar_20140930 -Fc
通过做恢复
$ createdb polar
$ pg_restore -d polar_20140930 -d polar -Fc
而且效果很好。
作为较早的测试,仅供引用,我尝试使用 --column-inserts 标志:
pg_dump --column-inserts polar -f polar_20140929.sql
然后通过管道输出到 psql 进行恢复:
psql -e polar < polar_20140929.sql > polar_restore.txt
此方法也有效,但正如文档警告的那样,恢复操作耗时很长(80 MB 的 sql 转储需要将近 3 小时)。尽管如此,它还是解决了我使用“;”时遇到的问题。和“\N”。
所以,有两个解决方案,但 Richard 关于 -Fc 选项的指示是票证。
非常感谢, 蒂姆
关于postgresql - 如何让 PostgreSQL 恢复以接受数据中的 ";"和 "\N"作为字符串的一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26105715/