2008-12-19 17:25:19 +01:00
<!--
2010-09-20 22:08:53 +02:00
doc/src/sgml/ref/create_server.sgml
2008-12-19 17:25:19 +01:00
PostgreSQL documentation
-->
2017-10-20 03:16:39 +02:00
<refentry id="sql-createserver">
2014-02-24 03:25:35 +01:00
<indexterm zone="sql-createserver">
<primary>CREATE SERVER</primary>
</indexterm>
2008-12-19 17:25:19 +01:00
<refmeta>
2010-04-03 09:23:02 +02:00
<refentrytitle>CREATE SERVER</refentrytitle>
2009-06-19 17:28:25 +02:00
<manvolnum>7</manvolnum>
2008-12-19 17:25:19 +01:00
<refmiscinfo>SQL - Language Statements</refmiscinfo>
</refmeta>
<refnamediv>
<refname>CREATE SERVER</refname>
<refpurpose>define a new foreign server</refpurpose>
</refnamediv>
<refsynopsisdiv>
<synopsis>
2018-03-30 03:25:32 +02:00
CREATE SERVER [ IF NOT EXISTS ] <replaceable class="parameter">server_name</replaceable> [ TYPE '<replaceable class="parameter">server_type</replaceable>' ] [ VERSION '<replaceable class="parameter">server_version</replaceable>' ]
2009-09-19 12:23:27 +02:00
FOREIGN DATA WRAPPER <replaceable class="parameter">fdw_name</replaceable>
2017-10-09 04:00:57 +02:00
[ OPTIONS ( <replaceable class="parameter">option</replaceable> '<replaceable class="parameter">value</replaceable>' [, ... ] ) ]
2008-12-19 17:25:19 +01:00
</synopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para>
<command>CREATE SERVER</command> defines a new foreign server. The
user who defines the server becomes its owner.
</para>
2009-06-18 16:34:36 +02:00
<para>
A foreign server typically encapsulates connection information that
a foreign-data wrapper uses to access an external data resource.
Additional user-specific connection information may be specified by
means of user mappings.
</para>
2008-12-19 17:25:19 +01:00
<para>
2009-01-17 05:29:00 +01:00
The server name must be unique within the database.
2008-12-19 17:25:19 +01:00
</para>
<para>
2017-10-09 03:44:17 +02:00
Creating a server requires <literal>USAGE</literal> privilege on the
2008-12-19 17:25:19 +01:00
foreign-data wrapper being used.
</para>
</refsect1>
<refsect1>
<title>Parameters</title>
<variablelist>
2017-03-20 21:40:45 +01:00
<varlistentry>
2017-10-09 03:44:17 +02:00
<term><literal>IF NOT EXISTS</literal></term>
2017-03-20 21:40:45 +01:00
<listitem>
<para>
Do not throw an error if a server with the same name already exists.
A notice is issued in this case. Note that there is no guarantee that
the existing server is anything like the one that would have been
created.
</para>
</listitem>
</varlistentry>
2008-12-19 17:25:19 +01:00
<varlistentry>
2009-09-19 12:23:27 +02:00
<term><replaceable class="parameter">server_name</replaceable></term>
2008-12-19 17:25:19 +01:00
<listitem>
<para>
The name of the foreign server to be created.
</para>
</listitem>
</varlistentry>
<varlistentry>
2009-09-19 12:23:27 +02:00
<term><replaceable class="parameter">server_type</replaceable></term>
2008-12-19 17:25:19 +01:00
<listitem>
<para>
2012-08-15 17:47:02 +02:00
Optional server type, potentially useful to foreign-data wrappers.
2008-12-19 17:25:19 +01:00
</para>
</listitem>
</varlistentry>
<varlistentry>
2009-09-19 12:23:27 +02:00
<term><replaceable class="parameter">server_version</replaceable></term>
2008-12-19 17:25:19 +01:00
<listitem>
<para>
2012-08-15 17:47:02 +02:00
Optional server version, potentially useful to foreign-data wrappers.
2008-12-19 17:25:19 +01:00
</para>
</listitem>
</varlistentry>
<varlistentry>
2009-09-19 12:23:27 +02:00
<term><replaceable class="parameter">fdw_name</replaceable></term>
2008-12-19 17:25:19 +01:00
<listitem>
<para>
The name of the foreign-data wrapper that manages the server.
</para>
</listitem>
</varlistentry>
<varlistentry>
2017-10-09 04:00:57 +02:00
<term><literal>OPTIONS ( <replaceable class="parameter">option</replaceable> '<replaceable class="parameter">value</replaceable>' [, ... ] )</literal></term>
2008-12-19 17:25:19 +01:00
<listitem>
<para>
This clause specifies the options for the server. The options
typically define the connection details of the server, but the
actual names and values are dependent on the server's
foreign-data wrapper.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
2009-06-18 16:34:36 +02:00
<refsect1>
<title>Notes</title>
<para>
2017-11-23 15:39:47 +01:00
When using the <xref linkend="dblink"/> module,
2013-02-21 11:26:23 +01:00
a foreign server's name can be used
2017-11-23 15:39:47 +01:00
as an argument of the <xref linkend="contrib-dblink-connect"/>
2013-02-21 11:26:23 +01:00
function to indicate the connection parameters. It is necessary to have
2009-06-18 16:34:36 +02:00
the <literal>USAGE</literal> privilege on the foreign server to be
able to use it in this way.
</para>
</refsect1>
2008-12-19 17:25:19 +01:00
<refsect1>
<title>Examples</title>
<para>
2017-10-09 03:44:17 +02:00
Create a server <literal>myserver</literal> that uses the
foreign-data wrapper <literal>postgres_fdw</literal>:
2008-12-19 17:25:19 +01:00
<programlisting>
2013-02-21 11:26:23 +01:00
CREATE SERVER myserver FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host 'foo', dbname 'foodb', port '5432');
2008-12-19 17:25:19 +01:00
</programlisting>
2017-11-23 15:39:47 +01:00
See <xref linkend="postgres-fdw"/> for more details.
2008-12-19 17:25:19 +01:00
</para>
</refsect1>
<refsect1>
<title>Compatibility</title>
<para>
<command>CREATE SERVER</command> conforms to ISO/IEC 9075-9 (SQL/MED).
</para>
</refsect1>
<refsect1>
<title>See Also</title>
<simplelist type="inline">
2017-11-23 15:39:47 +01:00
<member><xref linkend="sql-alterserver"/></member>
<member><xref linkend="sql-dropserver"/></member>
<member><xref linkend="sql-createforeigndatawrapper"/></member>
<member><xref linkend="sql-createforeigntable"/></member>
<member><xref linkend="sql-createusermapping"/></member>
2008-12-19 17:25:19 +01:00
</simplelist>
</refsect1>
</refentry>