CREATE_USER_MAPPING(7)

โœจ CREATE USER MAPPING ๐Ÿ’…

okay bestie, so this is <pink>CREATE_USER_MAPPING</pink> โ€” the Postgres page about mapping a user to a foreign server. Yes, it's a whole manual page, and yes, it's giving main character energy for your federated query setup. Let's get into it ๐Ÿซถ


๐ŸŒธ NAME ๐ŸŒธ

CREATE_USER_MAPPING โ€” define a new mapping of a user to a foreign server. literally that's the whole job. slay.


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

CREATE USER MAPPING [ IF NOT EXISTS ] FOR { user_name | USER | CURRENT_ROLE | CURRENT_USER | PUBLIC }
    SERVER server_name
    [ OPTIONS ( option 'value' [ , ... ] ) ]

look at her. the curly braces, the brackets, the choices ๐ŸŒˆ every one of those alternatives is real and you gotta pick exactly one, no cap.


๐Ÿ’– DESCRIPTION ๐Ÿ’–

CREATE USER MAPPING defines a mapping of a user to a foreign server. iconic behavior honestly.

so like, a user mapping typically encapsulates connection information that a foreign-data wrapper uses together with the information encapsulated by a foreign server, all so it can go access an external data resource. it's the lil handshake that says "hey, this local user is that remote identity, trust ๐Ÿ’…"

now here's the permission tea, and you need to know it:

  • The owner of a foreign server can create user mappings for that server for any user. (owner privileges, we love to see it ๐Ÿ‘‘)
  • Also, a user can create a user mapping for their own user name โ€” but only if USAGE privilege on the server has been granted to the user. no USAGE, no mapping, periodt.

โœจ PARAMETERS โœจ

  • IF NOT EXISTS โ€” do not throw an error if a mapping of the given user to the given foreign server already exists. a notice gets issued in this case instead. and bestie, listen: there is no guarantee that the existing user mapping is anything like the one that would have been created. it might be a whole different vibe in there. so don't assume. ๐Ÿ™ˆ
  • user_name โ€” the name of an existing user that is mapped to the foreign server. also: CURRENT_ROLE, CURRENT_USER, and USER all match the name of the current user. and when you specify PUBLIC, a so-called public mapping is created โ€” that's the one that gets used when no user-specific mapping is applicable. the fallback queen ๐ŸŒธ
  • server_name โ€” the name of an existing server for which the user mapping is to be created. existing. as in already there. don't come at her with a server that doesn't exist, she will not know her. ๐Ÿ’€
  • OPTIONS ( option 'value' [, ... ] ) โ€” this clause specifies the options of the user mapping. the options typically define the actual user name and password of the mapping. Option names must be unique. and the allowed option names and values are specific to the server's foreign-data wrapper โ€” so like, that's between you and your FDW, iykyk. ๐Ÿฆ‹

๐ŸŒŸ EXAMPLES ๐ŸŒŸ

Create a user mapping for user bob, server foo:

CREATE USER MAPPING FOR bob SERVER foo OPTIONS (user 'bob', password 'secret');

look at her go. bob is mapped. foo is served. secret is... right there in plaintext, which is a whole other conversation, but the example is the example, bestie ๐Ÿ’…


๐Ÿ’œ COMPATIBILITY ๐Ÿ’œ

CREATE USER MAPPING conforms to ISO/IEC 9075-9 (SQL/MED). standards girlie behavior. certified. ๐ŸŽ€


๐Ÿซถ SEE ALSO ๐Ÿซถ

the whole friend group fr fr. go read them, they're all linked and they all ate. ๐Ÿ”ฅ


and that's the page!! this whole thing is from PostgreSQL 18.6 documentation, dated 2026, and the page is CREATE USER MAPPING(7). mwah, go forth and map your users ๐Ÿ’–โœจ๐ŸŒธ