postgresql - 扩展多维数据集的 pg_dump / pg_restore 错误
问题描述
由于公共模式中的一些扩展,我一直遇到转储和恢复我的一个数据库的问题。引发错误的扩展似乎是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
我自己编写的一些函数遇到了类似的不同问题,问题最终成为搜索路径,因此明确地将这些函数的搜索路径设置为公开解决了我的问题。我尝试了同样的方法,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"
包含数据的完整转储约为 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';
我想我很困惑……从逻辑上讲,这和我使用 tar 格式不一样吗?我知道问题在于,当pg_restore
到达该物化视图并尝试使用该功能ll_to_earth(float8, float8)
时,它会失败,因为该功能不在其搜索路径中或尚未恢复,但这是否表明扩展是首先要恢复?这可以解决吗?
这是我编写的脚本的一部分,它将在我的生产环境中转储数据库并每天在我的测试环境中恢复数据库,以便它们匹配。它工作了几个月,直到我开始使用这个扩展,我不知道如何纠正它。
解决方案
出于安全原因,pg_dump
设置为search_path
空,因此pg_catalog
如果在没有模式限定的情况下引用它们,则只会找到系统模式中的对象。
现在您的 SQL 函数使用earth
没有模式的数据类型(可能public
),因此您会收到错误消息。
您将不得不更改函数以使用public.earth
扩展对象等限定名称。或者,可能更好的是修复search_path
函数:
ALTER FUNCTION myfun SET search_path = public;
无论如何,这是一个好主意,因为否则如果用户更改,您的功能将停止工作search_path
。根据定义或使用函数的方式,这甚至可能构成安全问题(这就是为什么pg_dump
会这样)。
推荐阅读
- microsoft-dynamics - Microsoft Dynamics 2013 和 Microsoft Dynamics 365 使用相同的 Rest API?
- java - 正则表达式在嵌套引号的情况下选择内引号之间的所有文本
- c# - SearchQuery by Not in Uids MailKit
- amazon-web-services - 无法为 AWS Route 53 上的子域创建 CAA 记录
- angular - Angular 6 HttpClient 响应返回未定义
- html - @font-face 不会在 WordPress 中显示自定义字体
- java - Set 方法在扩展类中找不到符号?
- java - 通过 SharedPreference 更新 ImageView 重新创建活动?
- javascript - 单选按钮选中/取消选中基于另一个单选组选中/取消选中
- php - 有效地从字符串中删除所有数组值,如果数组值是字符串中单词的一部分,则整个单词也必须从字符串中删除