我使用 pg_dump 和 pg_restore 对数据库进行每日备份,这些备份在我推送更新后最近停止工作。
我有一个函数validate_id,它是一个Case/When语句,可以快速检查一些存在完整性问题的数据。看起来像这样:
CREATE OR REPLACE FUNCTION validate_id(
_string text,
_type type
) RETURNS boolean AS
$$
SELECT
CASE WHEN (stuff) THEN TRUE
WHEN (other stuff) THEN TRUE
When (more stuff) THEN raise_err('Not an accepted type, the accepted types are: x y z')
ELSE FALSE
$$
LANGUAGE SQL;
Run Code Online (Sandbox Code Playgroud)
由于我添加了此功能,当我使用此命令转储时:
pg_dump -U postgres -h ipaddress -p 5432 -w -F t databaseName > backupsfolder/databaseName.tar
当我使用这个命令时:
pg_restore -U postgres -h localhost -p 5432 -d postgres -C …
我在转储和恢复我的一个数据库时遇到了问题,我认为是由于公共模式中的一些扩展所致。引发错误的扩展似乎是Cube扩展或EarthDistance扩展。这是我收到的错误:
pg_restore: [archiver (db)] Error from TOC entry 2983;
pg_restore: [archiver (db)] could not execute query: ERROR: type "earth" does not exist
LINE 1: ...ians($1))*sin(radians($2))),earth()*sin(radians($1)))::earth
QUERY: SELECT cube(cube(cube(earth()*cos(radians($1))*cos(radians($2))),earth()*cos(radians($1))*sin(radians($2))),earth()*sin(radians($1)))::earth
CONTEXT: SQL function "ll_to_earth" during inlining
Command was: REFRESH MATERIALIZED VIEW public.locationsearch
Run Code Online (Sandbox Code Playgroud)
我自己编写的一些函数也遇到了类似的不同问题,问题最终是搜索路径,因此明确地将这些函数的搜索路径设置为公开解决了我的问题。我尝试了同样的方法ll_to_earth,但似乎整个扩展都是问题。我真的不想尝试安装扩展,pg_catalog因为这似乎是不好的做法。
这是我典型的转储命令:
pg_dump -U postgres -h ipAddress -p 5432 -w -F t database > database.tar
其次是:
pg_restore -U postgres -h localhost -p 5432 -w -d postgres -C "database.tar"
-s包含数据的完整转储大约为 4GB,但我尝试仅使用和转储模式-F …