我遇到了一个问题,转储和恢复我的一个数据库,我想是因为公共模式中的一些扩展。抛出错误的扩展似乎是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对于我自己编写的一些函数,我遇到了类似的不同问题,最终问题是搜索路径,所以明确地将这些函数的搜索路径设置为public就解决了我的问题。我用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"
包含数据的完整转储大约为4 4gb,但我尝试仅使用-s和-F p转储模式,有趣的是,这是开始:
--
-- PostgreSQL database dump
--
-- Dumped from database version 12.2
-- Dumped by pg_dump version 12.2
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: cube; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS cube WITH SCHEMA public;
--
-- Name: EXTENSION cube; Type: COMMENT; Schema: -; Owner:
--
COMMENT ON EXTENSION cube IS 'data type for multidimensional cubes';
--
-- Name: earthdistance; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS earthdistance WITH SCHEMA public;
--
-- Name: EXTENSION earthdistance; Type: COMMENT; Schema: -; Owner:
--
COMMENT ON EXTENSION earthdistance IS 'calculate great-circle distances on the surface of the Earth';我猜我把by...logically搞糊涂了,这不是和我使用tar格式时一样吗?我知道问题在于,当pg_restore到达该物化视图并尝试使用函数ll_to_earth(float8, float8)时,它会失败,因为该函数要么不在它的搜索路径中,要么还没有恢复,但这不是意味着首先要恢复的是扩展吗?这个问题能解决吗?
这是我编写的脚本的一部分,该脚本将数据库转储到我的生产环境中,并每天恢复我的测试环境中的数据库,以使它们匹配。它工作了几个月,直到我开始使用这个扩展,我不知道如何纠正它。
发布于 2020-08-26 14:29:06
出于安全原因,pg_dump将search_path设置为空,因此如果在没有模式限定的情况下引用系统模式pg_catalog中的对象,则只能找到这些对象。
现在,您的SQL函数使用不带模式(可能是public)的数据类型earth,因此会得到错误消息。
您必须更改该函数,以便对扩展对象使用像public.earth这样的限定名称。或者,也可能是更好的方法,就是修复函数的search_path:
ALTER FUNCTION myfun SET search_path = public;无论如何,这是一个好主意,否则如果用户更改了search_path,您的函数将停止工作。根据您的函数的定义或使用方式,这甚至会构成一个安全问题(这就是pg_dump采用这种方式的原因)。
https://stackoverflow.com/questions/63586022
复制相似问题