SQL/MED是sql語言中管理外部數據的一個擴展標準。MED:management of external data。它通過定義一個外部數據包裝器和數據連接類型來管理外部數據。9.1開始提供對SQL/MED的支持,通過SQL/MED可以連接到各種異構數據庫或其他PostgreSQL數據庫。其相當于一套連接其他數據源的框架和標準。在SQL/MED標準中,實現了一下四類數據庫對象來訪問外部數據源:foreign data wrapper:外部數據包裝器,FDW。相當于定義外部數據驅動server:外部數據服務器,相當于定義一個外部數據源,需要制定外部數據源的FDWuser mapping:用戶映射,主要把外部數據源的用戶映射到本地用戶,用于控制權限foreign table:外部表,把外部數據源映射成數據庫中的一張外部表FDW: --使用之前,需要到crontab下,make make install創建FDW示例:、postgres=# create extension file_fdw;CREATE EXTENSIONpostgres=# create server file_fdw_server foreign data wrapper file_fdw;CREATE SERVERpostgres=# create foreign table passwd(postgres(# username text,postgres(# pass text,postgres(# uid int4,postgres(# gid int4,postgres(# gecos text,postgres(# home text,postgres(# shell textpostgres(# ) server file_fdw_serverpostgres-# options (format 'text', filename '/etc/passwd' ,delimiter ':', null '');CREATE FOREIGN TABLEpostgres=# select * from passwd limit 5; username | pass | uid | gid | gecos | home | shell ----------+------+-----+-----+--------+----------------+--------------- root | x | 0 | 0 | root | /root | /bin/bash bin | x | 1 | 1 | bin | /bin | /sbin/nologin daemon | x | 2 | 2 | daemon | /sbin | /sbin/nologin adm | x | 3 | 4 | adm | /var/adm | /sbin/nologin lp | x | 4 | 7 | lp | /var/spool/lpd | /sbin/nologin(5 rows)postgres=#
新聞熱點
疑難解答