codekingpro/portable-devtools
114k
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>5.12. Foreign Data</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="ddl-partitioning.html" title="5.11. Table Partitioning" /><link rel="next" href="ddl-others.html" title="5.13. Other Database Objects" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">5.12. Foreign Data</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="ddl-partitioning.html" title="5.11. Table Partitioning">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="ddl.html" title="Chapter 5. Data Definition">Up</a></td><th width="60%" align="center">Chapter 5. Data Definition</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="ddl-others.html" title="5.13. Other Database Objects">Next</a></td></tr></table><hr /></div><div class="sect1" id="DDL-FOREIGN-DATA"><div class="titlepage"><div><div><h2 class="title" style="clear: both">5.12. Foreign Data <a href="#DDL-FOREIGN-DATA" class="id_link">#</a></h2></div></div></div><a id="id-1.5.4.14.2" class="indexterm"></a><a id="id-1.5.4.14.3" class="indexterm"></a><a id="id-1.5.4.14.4" class="indexterm"></a><p>3 <span class="productname">PostgreSQL</span> implements portions of the SQL/MED4 specification, allowing you to access data that resides outside5 PostgreSQL using regular SQL queries. Such data is referred to as6 <em class="firstterm">foreign data</em>. (Note that this usage is not to be confused7 with foreign keys, which are a type of constraint within the database.)8 </p><p>9 Foreign data is accessed with help from a10 <em class="firstterm">foreign data wrapper</em>. A foreign data wrapper is a11 library that can communicate with an external data source, hiding the12 details of connecting to the data source and obtaining data from it.13 There are some foreign data wrappers available as <code class="filename">contrib</code>14 modules; see <a class="xref" href="contrib.html" title="Appendix F. Additional Supplied Modules and Extensions">Appendix F</a>. Other kinds of foreign data15 wrappers might be found as third party products. If none of the existing16 foreign data wrappers suit your needs, you can write your own; see <a class="xref" href="fdwhandler.html" title="Chapter 59. Writing a Foreign Data Wrapper">Chapter 59</a>.17 </p><p>18 To access foreign data, you need to create a <em class="firstterm">foreign server</em>19 object, which defines how to connect to a particular external data source20 according to the set of options used by its supporting foreign data21 wrapper. Then you need to create one or more <em class="firstterm">foreign22 tables</em>, which define the structure of the remote data. A23 foreign table can be used in queries just like a normal table, but a24 foreign table has no storage in the PostgreSQL server. Whenever it is25 used, <span class="productname">PostgreSQL</span> asks the foreign data wrapper26 to fetch data from the external source, or transmit data to the external27 source in the case of update commands.28 </p><p>29 Accessing remote data may require authenticating to the external30 data source. This information can be provided by a31 <em class="firstterm">user mapping</em>, which can provide additional data32 such as user names and passwords based33 on the current <span class="productname">PostgreSQL</span> role.34 </p><p>35 For additional information, see36 <a class="xref" href="sql-createforeigndatawrapper.html" title="CREATE FOREIGN DATA WRAPPER"><span class="refentrytitle">CREATE FOREIGN DATA WRAPPER</span></a>,37 <a class="xref" href="sql-createserver.html" title="CREATE SERVER"><span class="refentrytitle">CREATE SERVER</span></a>,38 <a class="xref" href="sql-createusermapping.html" title="CREATE USER MAPPING"><span class="refentrytitle">CREATE USER MAPPING</span></a>,39 <a class="xref" href="sql-createforeigntable.html" title="CREATE FOREIGN TABLE"><span class="refentrytitle">CREATE FOREIGN TABLE</span></a>, and40 <a class="xref" href="sql-importforeignschema.html" title="IMPORT FOREIGN SCHEMA"><span class="refentrytitle">IMPORT FOREIGN SCHEMA</span></a>.41 </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ddl-partitioning.html" title="5.11. Table Partitioning">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ddl.html" title="Chapter 5. Data Definition">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ddl-others.html" title="5.13. Other Database Objects">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.11. Table Partitioning </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 5.13. Other Database Objects</td></tr></table></div></body></html>