CREATE_SERVER(7pg13)

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

✨ CREATE SERVER πŸ’… (PostgreSQL 13.23, CREATE_SERVER(7))

okay bestie, so you want to make a whole new foreign server?? iconic. let's get into it 🫢


🌸 SYNOPSIS 🌸

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

like, that's the whole vibe. read it, love it, respect it ✨


πŸ’– DESCRIPTION πŸ’–

CREATE SERVER defines a new foreign server. and the way that whoever creates it just Literally becomes its owner?? main character energy fr fr πŸ‘‘

so basically, a foreign server is this lil package of connection info that a foreign-data wrapper uses to go talk to some external data resource. you can also add your own extra user-specific connection deets through user mappings β€” very demure, very customizable πŸŽ€

the server name has to be unique within the database. no dupes, no copies, no twinsies. periodt πŸ’…

⚠️ also important bestie: creating a server requires USAGE privilege on the foreign-data wrapper you're using. no privilege, no server. that's just the rules 😭

🌈 PARAMETERS 🌈

  • IF NOT EXISTS β€” don't throw an error if a server with the same name already exists, just issue a notice instead πŸ’Œ but real talk: there's no guarantee the existing server is anything like the one you were about to create. so like... eyes open, bestie πŸ™ˆ
  • server_name β€” the name of the foreign server you're creating. pick something cute ✨
  • server_type β€” optional server type, potentially useful to foreign-data wrappers. lowkey optional, highkey helpful πŸ¦‹
  • server_version β€” optional server version, potentially useful to foreign-data wrappers. same vibe, different field 🌸
  • fdw_name β€” the name of the foreign-data wrapper that manages the server. the boss of the operation, if you will πŸ‘‘
  • OPTIONS ( option 'value' [, ... ] ) β€” this clause specifies the options for the server. typically these define the connection details of the server, but the actual names and values are dependent on the server's foreign-data wrapper β€” so check with your fdw, not with me 🫢

πŸ¦‹ NOTES πŸ¦‹

okay so when you're 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. cute, right? BUT β€” it is necessary to have the USAGE privilege on the foreign server to be able to use it in this way. no privilege, no dblink. sorry babes πŸ’€

and if the foreign server supports sort pushdown, it is necessary for it to have the same sort ordering as the local server. like, they have to match. 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. she ate, no crumbs πŸ’…


⭐ COMPATIBILITY ⭐

CREATE SERVER conforms to ISO/IEC 9075-9 (SQL/MED). standards girlie behavior, we love to see it πŸ’–


πŸŽ€ SEE ALSO πŸŽ€


that's the whole page bestie, go forth and create servers responsibly πŸ§šπŸ’œ

signing off from PostgreSQL 13.23, dated 2025 β€” mwah, talk soon πŸ’‹

πŸ“¦ where this page comes from