CREATE_SERVER(7pg18)
๐ CREATE_SERVER โ bestie edition ๐
okay so this is CREATE_SERVER(7) from the PostgreSQL 18.6 docs and we're gonna make a whole foreign server together, no cap. it's giving "I'm connecting you to a whole other data source" energy and honestly? iconic.
โจ SYNOPSIS โจ
CREATE SERVER [ IF NOT EXISTS ] server_name [ TYPE 'server_type' ] [ VERSION 'server_version' ]
FOREIGN DATA WRAPPER fdw_name
[ OPTIONS ( option 'value' [, ... ] ) ]
that's the whole vibe. type it out, bestie ๐ซถ
๐ธ DESCRIPTION ๐ธ
CREATE SERVER literally defines a new foreign server. whoever defines it becomes its owner โ yes, you, main character ๐
a foreign server is basically a little bundle of connection info that a foreign-data wrapper uses to go talk to some external data resource. like a lil passport for your database to travel abroad โ๏ธ and if you need extra per-user connection deets, those go in user mappings.
the server name has to be unique within the database. no twins allowed, periodt.
also, creating a server requires USAGE privilege on the foreign-data wrapper you're using. no privilege, no server, that's the rule ๐
๐ PARAMETERS ๐
IF NOT EXISTSโ do NOT throw an error if a server with the same name already exists. instead a notice gets issued. but real talk: there is no guarantee that the existing server is anything like the one you would've created. it could be a whole different situation ๐ญserver_nameโ the name of the foreign server you're creating. name it something cute.server_typeโ optional server type, potentially useful to foreign-data wrappers.server_versionโ optional server version, potentially useful to foreign-data wrappers.fdw_nameโ the name of the foreign-data wrapper that manages the server. this is the one holding the aux cord ๐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 fully dependent on the server's foreign-data wrapper. so like, read the wrapper's docs, iykyk.
๐ฆ NOTES ๐ฆ
- when you're using the
dblinkmodule, a foreign server's name can be used as an argument of thedblink_connect(3)function to indicate the connection parameters. but bestie โ you need theUSAGEprivilege on that foreign server to use it this way. no privilege, no shortcut ๐ซ - if the foreign server supports sort pushdown, it needs to have the same sort ordering as the local server. matching outfits only ๐
๐ EXAMPLES ๐
create a server myserver that uses the foreign-data wrapper postgres_fdw:
CREATE SERVER myserver FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host 'foo', dbname 'foodb', port '5432');
see postgres_fdw for more details. slay ๐
โญ COMPATIBILITY โญ
CREATE SERVER conforms to ISO/IEC 9075-9 (SQL/MED). standard behavior, we ate that ๐
๐ SEE ALSO ๐
ALTER SERVER (ALTER_SERVER(7))DROP SERVER (DROP_SERVER(7))CREATE FOREIGN DATA WRAPPER (CREATE_FOREIGN_DATA_WRAPPER(7))CREATE FOREIGN TABLE (CREATE_FOREIGN_TABLE(7))CREATE USER MAPPING (CREATE_USER_MAPPING(7))
okay that's the whole page bestie, go build your server and be iconic ๐โจ๐๐ฆ
this has been PostgreSQL 18.6 documentation, dated 2026, signing off โ mwah ๐๐
๐ฆ where this page comes from
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms