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>CREATE SERVER</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="sql-createsequence.html" title="CREATE SEQUENCE" /><link rel="next" href="sql-createstatistics.html" title="CREATE STATISTICS" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">CREATE SERVER</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-createsequence.html" title="CREATE SEQUENCE">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><th width="60%" align="center">SQL Commands</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-createstatistics.html" title="CREATE STATISTICS">Next</a></td></tr></table><hr /></div><div class="refentry" id="SQL-CREATESERVER"><div class="titlepage"></div><a id="id-1.9.3.82.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">CREATE SERVER</span></h2><p>CREATE SERVER — define a new foreign server</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
3 CREATE SERVER [ IF NOT EXISTS ] <em class="replaceable"><code>server_name</code></em> [ TYPE '<em class="replaceable"><code>server_type</code></em>' ] [ VERSION '<em class="replaceable"><code>server_version</code></em>' ]
4 FOREIGN DATA WRAPPER <em class="replaceable"><code>fdw_name</code></em>
5 [ OPTIONS ( <em class="replaceable"><code>option</code></em> '<em class="replaceable"><code>value</code></em>' [, ... ] ) ]
6 </pre></div><div class="refsect1" id="id-1.9.3.82.5"><h2>Description</h2><p>
7 <code class="command">CREATE SERVER</code> defines a new foreign server. The
8 user who defines the server becomes its owner.
10 A foreign server typically encapsulates connection information that
11 a foreign-data wrapper uses to access an external data resource.
12 Additional user-specific connection information may be specified by
13 means of user mappings.
15 The server name must be unique within the database.
17 Creating a server requires <code class="literal">USAGE</code> privilege on the
18 foreign-data wrapper being used.
19 </p></div><div class="refsect1" id="id-1.9.3.82.6"><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">IF NOT EXISTS</code></span></dt><dd><p>
20 Do not throw an error if a server with the same name already exists.
21 A notice is issued in this case. Note that there is no guarantee that
22 the existing server is anything like the one that would have been
24 </p></dd><dt><span class="term"><em class="replaceable"><code>server_name</code></em></span></dt><dd><p>
25 The name of the foreign server to be created.
26 </p></dd><dt><span class="term"><em class="replaceable"><code>server_type</code></em></span></dt><dd><p>
27 Optional server type, potentially useful to foreign-data wrappers.
28 </p></dd><dt><span class="term"><em class="replaceable"><code>server_version</code></em></span></dt><dd><p>
29 Optional server version, potentially useful to foreign-data wrappers.
30 </p></dd><dt><span class="term"><em class="replaceable"><code>fdw_name</code></em></span></dt><dd><p>
31 The name of the foreign-data wrapper that manages the server.
32 </p></dd><dt><span class="term"><code class="literal">OPTIONS ( <em class="replaceable"><code>option</code></em> '<em class="replaceable"><code>value</code></em>' [, ... ] )</code></span></dt><dd><p>
33 This clause specifies the options for the server. The options
34 typically define the connection details of the server, but the
35 actual names and values are dependent on the server's
37 </p></dd></dl></div></div><div class="refsect1" id="id-1.9.3.82.7"><h2>Notes</h2><p>
38 When using the <a class="xref" href="dblink.html" title="F.11. dblink — connect to other PostgreSQL databases">dblink</a> module,
39 a foreign server's name can be used
40 as an argument of the <a class="xref" href="contrib-dblink-connect.html" title="dblink_connect"><span class="refentrytitle">dblink_connect</span></a>
41 function to indicate the connection parameters. It is necessary to have
42 the <code class="literal">USAGE</code> privilege on the foreign server to be
43 able to use it in this way.
45 If the foreign server supports sort pushdown, it is necessary for it
46 to have the same sort ordering as the local server.
47 </p></div><div class="refsect1" id="id-1.9.3.82.8"><h2>Examples</h2><p>
48 Create a server <code class="literal">myserver</code> that uses the
49 foreign-data wrapper <code class="literal">postgres_fdw</code>:
50 </p><pre class="programlisting">
51 CREATE SERVER myserver FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host 'foo', dbname 'foodb', port '5432');
53 See <a class="xref" href="postgres-fdw.html" title="F.38. postgres_fdw — access data stored in external PostgreSQL servers">postgres_fdw</a> for more details.
54 </p></div><div class="refsect1" id="id-1.9.3.82.9"><h2>Compatibility</h2><p>
55 <code class="command">CREATE SERVER</code> conforms to ISO/IEC 9075-9 (SQL/MED).
56 </p></div><div class="refsect1" id="id-1.9.3.82.10"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-alterserver.html" title="ALTER SERVER"><span class="refentrytitle">ALTER SERVER</span></a>, <a class="xref" href="sql-dropserver.html" title="DROP SERVER"><span class="refentrytitle">DROP SERVER</span></a>, <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-createforeigntable.html" title="CREATE FOREIGN TABLE"><span class="refentrytitle">CREATE FOREIGN TABLE</span></a>, <a class="xref" href="sql-createusermapping.html" title="CREATE USER MAPPING"><span class="refentrytitle">CREATE USER MAPPING</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sql-createsequence.html" title="CREATE SEQUENCE">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-createstatistics.html" title="CREATE STATISTICS">Next</a></td></tr><tr><td width="40%" align="left" valign="top">CREATE SEQUENCE </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> CREATE STATISTICS</td></tr></table></div></body></html>