CREATE_SERVER(7pg15)

πŸ“¦ version 15.19, in opensuse-leap 16.0

πŸ’… 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 πŸ‘‘


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