CREATE_SERVER(7pg15)
π CREATE SERVER π
okay bestie, so this one is straight out of the PostgreSQL 15.19 docs β page CREATE SERVER(7) β and it's honestly such a glow-up of a command. let's get into it π«Ά
β¨ NAME β¨
CREATE_SERVER β define a new foreign server π
π¦ SYNOPSIS π¦
CREATE SERVER [ IF NOT EXISTS ] server_name [ TYPE 'server_type' ] [ VERSION 'server_version' ]
FOREIGN DATA WRAPPER fdw_name
[ OPTIONS ( option 'value' [, ... ] ) ]
πΈ DESCRIPTION πΈ
CREATE SERVER defines a new foreign server. and like, whoever defines the server becomes its owner β main character energy fr, you made it, you own it π
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. so it's like the server holds the group-chat link, and the user mappings hold everybody's personal login π
The server name must be unique within the database. no dupes, no copycats π
Creating a server requires USAGE privilege on the foreign-data wrapper being used. no privilege, no entry β that's the vibe check β¨
π PARAMETERS π
IF NOT EXISTSβ 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. π like yes bestie it'll stay quiet, but it will not check whether the existing one matches what you asked for β so don't come crying to me.server_nameβ The name of the foreign server to be created. pick something cute, it's yours forever πserver_typeβ Optional server type, potentially useful to foreign-data wrappers. optional, lowkey a little hint for the fdw π§server_versionβ Optional server version, potentially useful to foreign-data wrappers. also optional, also just a hint πΈfdw_nameβ The name of the foreign-data wrapper that manages the server. this is the icon that's actually running the show π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. so yeah, the format lives here, the what lives with the fdw β iykyk π¦
π NOTES π
When using the dblink module, a foreign server's name can be used as an argument of the dblink_connect(3) function to indicate the connection parameters. It is necessary to have the USAGE privilege on the foreign server to be able to use it in this way. so like, the name is the flex, but the privilege is the ticket π
If the foreign server supports sort pushdown, it is necessary for it to have the same sort ordering as the local server. no cap β different ordering and the whole pushdown situation gets messy π
π₯ 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. it's giving "the sequel is better", go read it π
π COMPATIBILITY π
CREATE SERVER conforms to ISO/IEC 9075-9 (SQL/MED). standards-compliant and stunning, we love to see it π
π SEE ALSO π
ALTER SERVER(ALTER_SERVER(7)) β when you need a little change β¨DROP SERVER(DROP_SERVER(7)) β when it's time to say bye πCREATE FOREIGN DATA WRAPPER(CREATE_FOREIGN_DATA_WRAPPER(7)) β the wrapper itself πΈCREATE FOREIGN TABLE(CREATE_FOREIGN_TABLE(7)) β tables but from far away π¦CREATE USER MAPPING(CREATE_USER_MAPPING(7)) β everybody's personal login π
okay that's the whole page, bestie, go define some servers π€π
big sign-off energy: this was PostgreSQL 15.19, dated 2026, living on page CREATE SERVER(7) β mwah, slay, periodt ππ
π¦ where this page comes from
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms