1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!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 V1.79.1" /><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 xmlns="http://www.w3.org/TR/xhtml1/transitional" 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 13.4 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></hr></div><div class="sect1" id="DDL-FOREIGN-DATA"><div class="titlepage"><div><div><h2 class="title" style="clear: both">5.12. Foreign Data</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>
<span class="productname">PostgreSQL</span> implements portions of the SQL/MED
specification, allowing you to access data that resides outside
PostgreSQL using regular SQL queries. Such data is referred to as
<em class="firstterm">foreign data</em>. (Note that this usage is not to be confused
with foreign keys, which are a type of constraint within the database.)
</p><p>
Foreign data is accessed with help from a
<em class="firstterm">foreign data wrapper</em>. A foreign data wrapper is a
library that can communicate with an external data source, hiding the
details of connecting to the data source and obtaining data from it.
There are some foreign data wrappers available as <code class="filename">contrib</code>
modules; see <a class="xref" href="contrib.html" title="Appendix F. Additional Supplied Modules">Appendix F</a>. Other kinds of foreign data
wrappers might be found as third party products. If none of the existing
foreign data wrappers suit your needs, you can write your own; see <a class="xref" href="fdwhandler.html" title="Chapter 56. Writing a Foreign Data Wrapper">Chapter 56</a>.
</p><p>
To access foreign data, you need to create a <em class="firstterm">foreign server</em>
object, which defines how to connect to a particular external data source
according to the set of options used by its supporting foreign data
wrapper. Then you need to create one or more <em class="firstterm">foreign
tables</em>, which define the structure of the remote data. A
foreign table can be used in queries just like a normal table, but a
foreign table has no storage in the PostgreSQL server. Whenever it is
used, <span class="productname">PostgreSQL</span> asks the foreign data wrapper
to fetch data from the external source, or transmit data to the external
source in the case of update commands.
</p><p>
Accessing remote data may require authenticating to the external
data source. This information can be provided by a
<em class="firstterm">user mapping</em>, which can provide additional data
such as user names and passwords based
on the current <span class="productname">PostgreSQL</span> role.
</p><p>
For additional information, see
<a class="xref" href="sql-createforeigndatawrapper.html" title="CREATE FOREIGN DATA WRAPPER"><span class="refentrytitle">CREATE FOREIGN DATA WRAPPER</span></a>,
<a class="xref" href="sql-createserver.html" title="CREATE SERVER"><span class="refentrytitle">CREATE SERVER</span></a>,
<a class="xref" href="sql-createusermapping.html" title="CREATE USER MAPPING"><span class="refentrytitle">CREATE USER MAPPING</span></a>,
<a class="xref" href="sql-createforeigntable.html" title="CREATE FOREIGN TABLE"><span class="refentrytitle">CREATE FOREIGN TABLE</span></a>, and
<a class="xref" href="sql-importforeignschema.html" title="IMPORT FOREIGN SCHEMA"><span class="refentrytitle">IMPORT FOREIGN SCHEMA</span></a>.
</p></div><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navfooter"><hr></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 13.4 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 5.13. Other Database Objects</td></tr></table></div></body></html>
|