假设我们在 2 个不同的服务器上有 2 个数据库:
在数据库 A 上,创建了一个“city”表,该表使用“earthdistance”扩展名:
CREATE EXTENSION "uuid-ossp";
CREATE EXTENSION "cube"; -- required by earthdistance
CREATE EXTENSION "earthdistance";
CREATE TABLE "city" (
"id" UUID PRIMARY KEY DEFAULT uuid_generate_v1mc(),
"name" VARCHAR(254) DEFAULT '',
"lat" DOUBLE PRECISION NOT NULL,
"lon" DOUBLE PRECISION NOT NULL
);
CREATE INDEX "city_geo_idx" ON "city" USING gist(ll_to_earth(lat, lon));
INSERT INTO "city" VALUES(DEFAULT, 'Hong Kong', 22.313031, 114.170623);
在数据库 B 上,创建了对来自 A 的表“city”表的外部引用:
CREATE EXTENSION "uuid-ossp";
CREATE EXTENSION "postgres_fdw";
CREATE SERVER "foreign_a"
FOREIGN DATA WRAPPER "postgres_fdw"
OPTIONS (host 'https://A.com/db', port '5432', dbname 'a');
CREATE USER MAPPING FOR "postgres"
SERVER "foreign_a"
OPTIONS (user 'postgres', password 'postgres');
CREATE FOREIGN TABLE "city" (
"id" UUID,
"name" VARCHAR(254) DEFAULT ''
)
SERVER "foreign_a"
OPTIONS (schema_name 'public', table_name 'city');
在这个阶段,运行 aSELECT * FROM "city"
返回以下错误:
[2018-06-25 19:05:17] [42704] ERROR: type "earth" does not exist
[2018-06-25 19:05:17] Where: Remote SQL command: SELECT id, name FROM public.city
[2018-06-25 19:05:17] SQL function "ll_to_earth" during inlining
在数据库 B 上添加缺少的扩展名并不能解决问题:
CREATE EXTENSION "cube" SCHEMA "public";
CREATE EXTENSION "earthdistance" SCHEMA "public";
SELECT * FROM "city";
再次:
[2018-06-25 19:05:58] [42704] ERROR: type "earth" does not exist
[2018-06-25 19:05:58] Where: Remote SQL command: SELECT id, name FROM public.city
[2018-06-25 19:05:58] SQL function "ll_to_earth" during inlining
任何帮助是极大的赞赏!