pg_foreign_server 是一个 系统目录 表,用于存储使用 CREATE SERVER 命令定义的 外部数据包装器 (FDW) 的服务器定义。
pg_foreign_server 在 PostgreSQL 8.4 中被添加。
psql 命令
\des 列出外部服务器。
按 PostgreSQL 版本定义
pg_foreign_server (PostgreSQL 19)
Table "pg_catalog.pg_foreign_server"
Column | Type | Collation | Nullable | Default
------------+-----------+-----------+----------+---------
oid | oid | | not null |
srvname | name | | not null |
srvowner | oid | | not null |
srvfdw | oid | | not null |
srvtype | text | C | |
srvversion | text | C | |
srvacl | aclitem[] | | |
srvoptions | text[] | C | |
Indexes:
"pg_foreign_server_oid_index" PRIMARY KEY, btree (oid)
"pg_foreign_server_name_index" UNIQUE CONSTRAINT, btree (srvname)
pg_foreign_server (PostgreSQL 18)
Table "pg_catalog.pg_foreign_server"
Column | Type | Collation | Nullable | Default
------------+-----------+-----------+----------+---------
oid | oid | | not null |
srvname | name | | not null |
srvowner | oid | | not null |
srvfdw | oid | | not null |
srvtype | text | C | |
srvversion | text | C | |
srvacl | aclitem[] | | |
srvoptions | text[] | C | |
Indexes:
"pg_foreign_server_oid_index" PRIMARY KEY, btree (oid)
"pg_foreign_server_name_index" UNIQUE CONSTRAINT, btree (srvname)
pg_foreign_server (PostgreSQL 17)
Table "pg_catalog.pg_foreign_server"
Column | Type | Collation | Nullable | Default
------------+-----------+-----------+----------+---------
oid | oid | | not null |
srvname | name | | not null |
srvowner | oid | | not null |
srvfdw | oid | | not null |
srvtype | text | C | |
srvversion | text | C | |
srvacl | aclitem[] | | |
srvoptions | text[] | C | |
Indexes:
"pg_foreign_server_oid_index" PRIMARY KEY, btree (oid)
"pg_foreign_server_name_index" UNIQUE CONSTRAINT, btree (srvname)
pg_foreign_server (PostgreSQL 16)
Table "pg_catalog.pg_foreign_server"
Column | Type | Collation | Nullable | Default
------------+-----------+-----------+----------+---------
oid | oid | | not null |
srvname | name | | not null |
srvowner | oid | | not null |
srvfdw | oid | | not null |
srvtype | text | C | |
srvversion | text | C | |
srvacl | aclitem[] | | |
srvoptions | text[] | C | |
Indexes:
"pg_foreign_server_oid_index" PRIMARY KEY, btree (oid)
"pg_foreign_server_name_index" UNIQUE CONSTRAINT, btree (srvname)
pg_foreign_server (PostgreSQL 15)
Table "pg_catalog.pg_foreign_server"
Column | Type | Collation | Nullable | Default
------------+-----------+-----------+----------+---------
oid | oid | | not null |
srvname | name | | not null |
srvowner | oid | | not null |
srvfdw | oid | | not null |
srvtype | text | C | |
srvversion | text | C | |
srvacl | aclitem[] | | |
srvoptions | text[] | C | |
Indexes:
"pg_foreign_server_oid_index" PRIMARY KEY, btree (oid)
"pg_foreign_server_name_index" UNIQUE CONSTRAINT, btree (srvname)
pg_foreign_server (PostgreSQL 14)
Table "pg_catalog.pg_foreign_server"
Column | Type | Collation | Nullable | Default
------------+-----------+-----------+----------+---------
oid | oid | | not null |
srvname | name | | not null |
srvowner | oid | | not null |
srvfdw | oid | | not null |
srvtype | text | C | |
srvversion | text | C | |
srvacl | aclitem[] | | |
srvoptions | text[] | C | |
Indexes:
"pg_foreign_server_oid_index" PRIMARY KEY, btree (oid)
"pg_foreign_server_name_index" UNIQUE CONSTRAINT, btree (srvname)
pg_foreign_server (PostgreSQL 13)
Table "pg_catalog.pg_foreign_server"
Column | Type | Collation | Nullable | Default
------------+-----------+-----------+----------+---------
oid | oid | | not null |
srvname | name | | not null |
srvowner | oid | | not null |
srvfdw | oid | | not null |
srvtype | text | C | |
srvversion | text | C | |
srvacl | aclitem[] | | |
srvoptions | text[] | C | |
Indexes:
"pg_foreign_server_name_index" UNIQUE, btree (srvname)
"pg_foreign_server_oid_index" UNIQUE, btree (oid)
pg_foreign_server (PostgreSQL 12)
Table "pg_catalog.pg_foreign_server"
Column | Type | Collation | Nullable | Default
------------+-----------+-----------+----------+---------
oid | oid | | not null |
srvname | name | | not null |
srvowner | oid | | not null |
srvfdw | oid | | not null |
srvtype | text | C | |
srvversion | text | C | |
srvacl | aclitem[] | | |
srvoptions | text[] | C | |
Indexes:
"pg_foreign_server_name_index" UNIQUE, btree (srvname)
"pg_foreign_server_oid_index" UNIQUE, btree (oid)
pg_foreign_server (PostgreSQL 11)
Table "pg_catalog.pg_foreign_server"
Column | Type | Collation | Nullable | Default
------------+-----------+-----------+----------+---------
srvname | name | | not null |
srvowner | oid | | not null |
srvfdw | oid | | not null |
srvtype | text | | |
srvversion | text | | |
srvacl | aclitem[] | | |
srvoptions | text[] | | |
Indexes:
"pg_foreign_server_name_index" UNIQUE, btree (srvname)
"pg_foreign_server_oid_index" UNIQUE, btree (oid)
pg_foreign_server (PostgreSQL 10)
Table "pg_catalog.pg_foreign_server"
Column | Type | Collation | Nullable | Default
------------+-----------+-----------+----------+---------
srvname | name | | not null |
srvowner | oid | | not null |
srvfdw | oid | | not null |
srvtype | text | | |
srvversion | text | | |
srvacl | aclitem[] | | |
srvoptions | text[] | | |
Indexes:
"pg_foreign_server_name_index" UNIQUE, btree (srvname)
"pg_foreign_server_oid_index" UNIQUE, btree (oid)
pg_foreign_server (PostgreSQL 9.6)
Table "pg_catalog.pg_foreign_server"
Column | Type | Modifiers
------------+-----------+-----------
srvname | name | not null
srvowner | oid | not null
srvfdw | oid | not null
srvtype | text |
srvversion | text |
srvacl | aclitem[] |
srvoptions | text[] |
Indexes:
"pg_foreign_server_name_index" UNIQUE, btree (srvname)
"pg_foreign_server_oid_index" UNIQUE, btree (oid)
pg_foreign_server (PostgreSQL 9.5)
Table "pg_catalog.pg_foreign_server"
Column | Type | Modifiers
------------+-----------+-----------
srvname | name | not null
srvowner | oid | not null
srvfdw | oid | not null
srvtype | text |
srvversion | text |
srvacl | aclitem[] |
srvoptions | text[] |
Indexes:
"pg_foreign_server_name_index" UNIQUE, btree (srvname)
"pg_foreign_server_oid_index" UNIQUE, btree (oid)
pg_foreign_server (PostgreSQL 9.4)
Table "pg_catalog.pg_foreign_server"
Column | Type | Modifiers
------------+-----------+-----------
srvname | name | not null
srvowner | oid | not null
srvfdw | oid | not null
srvtype | text |
srvversion | text |
srvacl | aclitem[] |
srvoptions | text[] |
Indexes:
"pg_foreign_server_name_index" UNIQUE, btree (srvname)
"pg_foreign_server_oid_index" UNIQUE, btree (oid)
pg_foreign_server (PostgreSQL 9.3)
Table "pg_catalog.pg_foreign_server"
Column | Type | Modifiers
------------+-----------+-----------
srvname | name | not null
srvowner | oid | not null
srvfdw | oid | not null
srvtype | text |
srvversion | text |
srvacl | aclitem[] |
srvoptions | text[] |
Indexes:
"pg_foreign_server_name_index" UNIQUE, btree (srvname)
"pg_foreign_server_oid_index" UNIQUE, btree (oid)
pg_foreign_server (PostgreSQL 9.2)
Table "pg_catalog.pg_foreign_server"
Column | Type | Modifiers
------------+-----------+-----------
srvname | name | not null
srvowner | oid | not null
srvfdw | oid | not null
srvtype | text |
srvversion | text |
srvacl | aclitem[] |
srvoptions | text[] |
Indexes:
"pg_foreign_server_name_index" UNIQUE, btree (srvname)
"pg_foreign_server_oid_index" UNIQUE, btree (oid)
pg_foreign_server (PostgreSQL 9.1)
Table "pg_catalog.pg_foreign_server"
Column | Type | Modifiers
------------+-----------+-----------
srvname | name | not null
srvowner | oid | not null
srvfdw | oid | not null
srvtype | text |
srvversion | text |
srvacl | aclitem[] |
srvoptions | text[] |
Indexes:
"pg_foreign_server_name_index" UNIQUE, btree (srvname)
"pg_foreign_server_oid_index" UNIQUE, btree (oid)
pg_foreign_server (PostgreSQL 9.0)
Table "pg_catalog.pg_foreign_server"
Column | Type | Modifiers
------------+-----------+-----------
srvname | name | not null
srvowner | oid | not null
srvfdw | oid | not null
srvtype | text |
srvversion | text |
srvacl | aclitem[] |
srvoptions | text[] |
Indexes:
"pg_foreign_server_name_index" UNIQUE, btree (srvname)
"pg_foreign_server_oid_index" UNIQUE, btree (oid)
pg_foreign_server (PostgreSQL 8.4)
Table "pg_catalog.pg_foreign_server"
Column | Type | Modifiers
------------+-----------+-----------
srvname | name | not null
srvowner | oid | not null
srvfdw | oid | not null
srvtype | text |
srvversion | text |
srvacl | aclitem[] |
srvoptions | text[] |
Indexes:
"pg_foreign_server_name_index" UNIQUE, btree (srvname)
"pg_foreign_server_oid_index" UNIQUE, btree (oid)
变更历史
自 PostgreSQL 8.4 添加以来,此表未被修改。
- PostgreSQL 8.4
- 添加 (提交 cae565e5)
示例
postgres=# CREATE SERVER fdw_test
FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (
host 'remotehost',
port '5432',
dbname 'postgres'
);
CREATE SERVER
postgres=# SELECT * FROM pg_foreign_server ;
-[ RECORD 1 ]------------------------------------------
oid | 16459
srvname | fdw_test
srvowner | 10
srvfdw | 16458
srvtype |
srvversion |
srvacl |
srvoptions | {host=remotehost,port=5432,dbname=postgres}
srvoptions 列中的值可以使用 pg_options_to_table() 提取,例如:
postgres=# SELECT option_name, option_value
FROM pg_foreign_server,
pg_options_to_table(srvoptions)
WHERE srvname = 'fdw_test';
option_name | option_value
-------------+--------------
host | remotehost
port | 5432
dbname | postgres
(3 rows)
参考资料
- PostgreSQL 文档: pg_foreign_server
