我正在尝试使用pg_dumpall和psql迁移到新的数据库服务器和次要版本凹凸(10.1> 10.4),但是还原过程中充满了语法错误,似乎与源之间的不匹配有关和目标预期格式。
经过反复试验,我发现这主要与在SQL转储中使用新行有关。
错误:
psql:dbops / app_full_backup_edit.sql:106:错误:语法错误 输入行1的结尾:... N app_core.generate_object_id()返回 字符变化
例如,pg_dumpall将存储过程导出为:
CREATE FUNCTION app_core.generate_object_id() RETURNS character varying
LANGUAGE plpgsql
AS $$
DECLARE
time_component bigint;
machine_id bigint := FLOOR(random() * 16777215);
process_id bigint;
seq_id bigint := FLOOR(random() * 16777215);
result varchar:= '';
BEGIN
SELECT FLOOR(EXTRACT(EPOCH FROM clock_timestamp())) INTO time_component;
SELECT pg_backend_pid() INTO process_id;
result := result || lpad(to_hex(time_component), 8, '0');
result := result || lpad(to_hex(machine_id), 6, '0');
result := result || lpad(to_hex(process_id), 4, '0');
result := result || lpad(to_hex(seq_id), 6, '0');
RETURN result;
END;
$$;
ALTER FUNCTION app_core.generate_object_id() OWNER TO postgres;
..但是psql在接受以下格式之前不会接受它(更改后删除换行符,并移动语言声明):
CREATE FUNCTION app_core.generate_object_id() RETURNS character varying AS $$
DECLARE
time_component bigint;
machine_id bigint := FLOOR(random() * 16777215);
process_id bigint;
seq_id bigint := FLOOR(random() * 16777215);
result varchar:= '';
BEGIN
SELECT FLOOR(EXTRACT(EPOCH FROM clock_timestamp())) INTO time_component;
SELECT pg_backend_pid() INTO process_id;
result := result || lpad(to_hex(time_component), 8, '0');
result := result || lpad(to_hex(machine_id), 6, '0');
result := result || lpad(to_hex(process_id), 4, '0');
result := result || lpad(to_hex(seq_id), 6, '0');
RETURN result;
END;
$$ LANGUAGE plpgsql;
ALTER FUNCTION app_core.generate_object_id() OWNER TO postgres;
我用于转储和还原的命令是:
还原
psql -f dbops/app_full_backup_edit.sql -S postgres -U postgres -h localhost -p 5432 -v ON_ERROR_STOP=1 postgres
转储
pg_dumpall -f dbops/app_full_backup.sql -S postgres -U postgres -h localhost -p 5432
源数据库为V10.1,目标数据库为V10.5-使用CLI工具V10.5(尝试迁移到相同版本但有相同错误的数据库)。
关于为什么会发生这种情况以及如何解决的任何建议?