CREATE SERVER(7) SQL Commands CREATE SERVER(7)NAME
CREATE SERVER - define a new foreign server
SYNOPSIS
CREATE SERVER servername [ TYPE 'servertype' ] [ VERSION 'serverversion' ]
FOREIGN DATA WRAPPER fdwname
[ OPTIONS ( option 'value' [, ... ] ) ]
DESCRIPTION
CREATE SERVER defines a new foreign server. The user who defines the server becomes its owner.
A foreign server typically encapsulates connection information that a foreign-data wrapper uses to access an external data resource. Addi-
tional user-specific connection information may be specified by means of user mappings.
The server name must be unique within the database.
Creating a server requires USAGE privilege on the foreign-data wrapper being used.
PARAMETERS
servername
The name of the foreign server to be created.
servertype
Optional server type.
serverversion
Optional server version.
fdwname
The name of the foreign-data wrapper that manages the server.
OPTIONS ( option 'value' [, ... ] )
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.
NOTES
When using the dblink module (see in the documentation), the foreign server name can be used as an argument of the dblink_connect(l) func-
tion to indicate the connection parameters. See also there for more examples. It is necessary to have the USAGE privilege on the foreign
server to be able to use it in this way.
EXAMPLES
Create a server foo that uses the built-in foreign-data wrapper default:
CREATE SERVER foo FOREIGN DATA WRAPPER "default";
Create a server myserver that uses the foreign-data wrapper pgsql:
CREATE SERVER myserver FOREIGN DATA WRAPPER pgsql OPTIONS (host 'foo', dbname 'foodb', port '5432');
COMPATIBILITY
CREATE SERVER conforms to ISO/IEC 9075-9 (SQL/MED).
SEE ALSO
ALTER SERVER [alter_server(7)], DROP SERVER [drop_server(7)], CREATE FOREIGN DATA WRAPPER [create_foreign_data_wrapper(7)], CREATE USER
MAPPING [create_user_mapping(7)]
SQL - Language Statements 2010-05-14 CREATE SERVER(7)
Check Out this Related Man Page
CREATE FOREIGN DATA WRAPPER(7) PostgreSQL 9.2.7 Documentation CREATE FOREIGN DATA WRAPPER(7)NAME
CREATE_FOREIGN_DATA_WRAPPER - define a new foreign-data wrapper
SYNOPSIS
CREATE FOREIGN DATA WRAPPER name
[ HANDLER handler_function | NO HANDLER ]
[ VALIDATOR validator_function | NO VALIDATOR ]
[ OPTIONS ( option 'value' [, ... ] ) ]
DESCRIPTION
CREATE FOREIGN DATA WRAPPER creates a new foreign-data wrapper. The user who defines a foreign-data wrapper becomes its owner.
The foreign-data wrapper name must be unique within the database.
Only superusers can create foreign-data wrappers.
PARAMETERS
name
The name of the foreign-data wrapper to be created.
HANDLER handler_function
handler_function is the name of a previously registered function that will be called to retrieve the execution functions for foreign
tables. The handler function must take no arguments, and its return type must be fdw_handler.
It is possible to create a foreign-data wrapper with no handler function, but foreign tables using such a wrapper can only be declared,
not accessed.
VALIDATOR validator_function
validator_function is the name of a previously registered function that will be called to check the generic options given to the
foreign-data wrapper, as well as options for foreign servers and user mappings using the foreign-data wrapper. If no validator function
or NO VALIDATOR is specified, then options will not be checked at creation time. (Foreign-data wrappers will possibly ignore or reject
invalid option specifications at run time, depending on the implementation.) The validator function must take two arguments: one of
type text[], which will contain the array of options as stored in the system catalogs, and one of type oid, which will be the OID of
the system catalog containing the options. The return type is ignored; the function should report invalid options using the
ereport(ERROR) function.
OPTIONS ( option 'value' [, ... ] )
This clause specifies options for the new foreign-data wrapper. The allowed option names and values are specific to each foreign data
wrapper and are validated using the foreign-data wrapper's validator function. Option names must be unique.
NOTES
At the moment, the foreign-data wrapper functionality is rudimentary. There is no support for updating a foreign table, and optimization of
queries is primitive (and mostly left to the wrapper, too).
There is one built-in foreign-data wrapper validator function provided: postgresql_fdw_validator, which accepts options corresponding to
libpq connection parameters.
EXAMPLES
Create a useless foreign-data wrapper dummy:
CREATE FOREIGN DATA WRAPPER dummy;
Create a foreign-data wrapper file with handler function file_fdw_handler:
CREATE FOREIGN DATA WRAPPER file HANDLER file_fdw_handler;
Create a foreign-data wrapper mywrapper with some options:
CREATE FOREIGN DATA WRAPPER mywrapper
OPTIONS (debug 'true');
COMPATIBILITY
CREATE FOREIGN DATA WRAPPER conforms to ISO/IEC 9075-9 (SQL/MED), with the exception that the HANDLER and VALIDATOR clauses are extensions
and the standard clauses LIBRARY and LANGUAGE are not implemented in PostgreSQL.
Note, however, that the SQL/MED functionality as a whole is not yet conforming.
SEE ALSO
ALTER FOREIGN DATA WRAPPER (ALTER_FOREIGN_DATA_WRAPPER(7)), DROP FOREIGN DATA WRAPPER (DROP_FOREIGN_DATA_WRAPPER(7)), CREATE SERVER
(CREATE_SERVER(7)), CREATE USER MAPPING (CREATE_USER_MAPPING(7))
PostgreSQL 9.2.7 2014-02-17 CREATE FOREIGN DATA WRAPPER(7)