3

我已经像这样转储了 OpenERP 数据库:

pg_dump -Fc -xO -f o7db.dump o7db

源机器有:

$ pg_dump --version
pg_dump (PostgreSQL) 9.3.5

scp转储到目标机器(一个 OpenVZ 容器),其中 pg_restore 是:

$ pg_restore --version
pg_restore (PostgreSQL) 9.3.5

我像这样运行 pg_restore:

pg_restore -d o7db -xO -j3 o7db.dump

我能看到的唯一区别是两台机器上的 postgres 用户不一样(但这应该由 处理-O)。pg_restore 抱怨:

pg_restore: [archiver (db)] Error from TOC entry 8561; 0 1161831 TABLE DATA account_move_line manu
pg_restore: [archiver (db)] COPY failed for table "account_move_line": ERROR:  value too long for type character varying(64)
CONTEXT:  COPY account_move_line, line 172, column name: "<MASKED DATA HERE....>"

此错误针对多个表多次发出。之后,许多关于丢失元组的错误如下:

pg_restore: [archiver (db)] Error from TOC entry 6784; 2606 1182924 FK CONSTRAINT account_account_currency_id_fkey manu
pg_restore: [archiver (db)] could not execute query: ERROR:  insert or update on table "account_account" violates foreign key constraint "account_account_currency_id_fkey"
DETAIL:  Key (currency_id)=(1) is not present in table "res_currency".
     Command was: ALTER TABLE ONLY account_account
     ADD CONSTRAINT account_account_currency_id_fkey FOREIGN KEY (currency_id) REFERENCES re..

我不明白这是怎么可能的,因为源数据库似乎没问题。

恢复的数据库有许多空表(每个失败导致值太长):

 $ psql -d o7db -Ac "select * from account_move_line"  | tail -1
 (0 rows)

此外,我在同一台源机器上执行 pg_restore:

pg_restore -d o7db_restore -xO -j3 o7db.dump

一切都按预期工作。没有一个警告。

我应该怎么办?我究竟做错了什么?

4

1 回答 1

2

答案实际上是在Moving PostgreSQL database failed on non-ascii characters with 'value too long' 中给出的

目标服务器似乎使用不同的编码创建数据库,因此在恢复之前使用 UTF8 创建数据库可以解决问题。

归功于@habe(https://stackoverflow.com/users/216458/habe

因此,我已投票结束我的问题。

于 2014-09-03T14:02:12.873 回答