CREATE_SERVER(7pg14)

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

πŸ’… CREATE SERVER β€” like, define a new foreign server, bestie

okay so this is the CREATE SERVER(7) page from the PostgreSQL 14.24 docs and it's genuinely iconic β€” it's the one that teaches you how to spin up a brand-new foreign server. let's get into it 🫢


✨ NAME ✨

CREATE_SERVER β€” define a new foreign server. that's it. that's the whole vibe. πŸ‘‘


πŸŽ€ SYNOPSIS πŸŽ€

CREATE SERVER [ IF NOT EXISTS ] server_name [ TYPE 'server_type' ] [ VERSION 'server_version' ]
    FOREIGN DATA WRAPPER fdw_name
    [ OPTIONS ( option 'value' [, ... ] ) ]

look at that syntax. gorgeous. no notes. πŸ’–


🌸 DESCRIPTION 🌸

CREATE SERVER defines a new foreign server. and the way that you, the user who defines it, automatically become its owner? main character energy fr fr. πŸŽ€

so a foreign server typically encapsulates connection information that a foreign-data wrapper uses to access an external data resource. think of it as the little bundle of "hey here's where the other database lives" info. ✨ additional user-specific connection information may be specified by means of user mappings β€” that's how you get per-user deets in there.

the server name must be unique within the database. no duplicates, bestie, i don't make the rules. πŸ’…

creating a server requires USAGE privilege on the foreign-data wrapper being used. so like… you gotta have the permissions. no sneaking in. πŸ”₯


πŸ¦‹ 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 instead, which is way more chill. ⭐ but heads up: there is no guarantee that the existing server is anything like the one that would have been created. it could be a whole different vibe. 😭
  • server_name β€” the name of the foreign server to be created. you pick it, you own it. πŸ’œ
  • server_type β€” optional server type, potentially useful to foreign-data wrappers. it's giving "nice to have." 🌸
  • server_version β€” optional server version, potentially useful to foreign-data wrappers. same energy, different field. πŸ¦‹
  • fdw_name β€” the name of the foreign-data wrapper that manages the server. this is the one in charge, the icon holding it all together. πŸ‘‘
  • 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 like, i can't tell you what goes here β€” ask your 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, again: permissions. always permissions. πŸ™ˆ

if the foreign server supports sort pushdown, it is necessary for it to have the same sort ordering as the local server. like matching outfits but for sort orders. 🌈


πŸ”₯ 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');

ate. no crumbs. πŸ’… see postgres_fdw for more details.


🌟 COMPATIBILITY 🌟

CREATE SERVER conforms to ISO/IEC 9075-9 (SQL/MED). she's certified, she's standards-compliant, she's that girl. ✨


πŸ’– SEE ALSO πŸ’–

the whole friend group, honestly. 🫢


and that's the page!! mwah πŸ’‹ β€” this was PostgreSQL 14.24 documentation, dated 2026, CREATE SERVER(7), signin' off with love. go forth and create servers, bestie πŸ§šβ€β™€οΈπŸ“πŸ’œ

πŸ“¦ where this page comes from