CREATE_USER_MAPPING(7pg17)

๐Ÿ“ฆ version 17.11, in opensuse-leap 16.0

๐Ÿ’… CREATE USER MAPPING ๐Ÿ’…

okay bestie so this is CREATE USER MAPPING(7) from the PostgreSQL 17.11 Documentation, and it's literally about teaching your database how to log in as somebody else on a foreign server. very main character of it. let's go โœจ


๐ŸŽ€ NAME ๐ŸŽ€

CREATE_USER_MAPPING โ€” defines a new mapping of a user to a foreign server. that's it, that's the whole vibe ๐Ÿซถ


โญ SYNOPSIS โญ

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

look at that syntax glow-up ๐Ÿ˜ญ so many options to pick from, slay


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

So CREATE USER MAPPING defines a mapping of a user to a foreign server. ๐ŸŽ€ A user mapping typically encapsulates connection information that a foreign-data wrapper uses together with the information encapsulated by a foreign server to access an external data resource. it's giving "here's everything you need to know to walk in the door" energy.

now, who's allowed to do this? the owner of a foreign server can create user mappings for that server for any user. also, a user can create a user mapping for their own user name if USAGE privilege on the server has been granted to the user. so you can absolutely be the one to do it for yourself โ€” permission check, bestie ๐Ÿ‘‘


๐Ÿ’– 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 is issued in this case. ngl the important bit here: there is no guarantee that the existing user mapping is anything like the one that would have been created. so like... it won't yell at you, but it's not gonna match your fit either ๐Ÿ™ˆ
  • user_name โ€” the name of an existing user that is mapped to foreign server. CURRENT_ROLE, CURRENT_USER, and USER all match the name of the current user. and when PUBLIC is specified, a so-called public mapping is created that is used when no user-specific mapping is applicable. it's the default outfit when nothing else fits ๐Ÿ’œ
  • server_name โ€” the name of an existing server for which the user mapping is to be created. yes, it has to already exist. no inventing servers out here ๐Ÿ’€
  • 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, ask them, not me ๐ŸŒธ

๐ŸŒธ EXAMPLES ๐ŸŒธ

create a user mapping for user bob, server foo:

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

ate, no crumbs. iconic ๐Ÿ”ฅ


โœจ COMPATIBILITY โœจ

CREATE USER MAPPING conforms to ISO/IEC 9075-9 (SQL/MED). standards queen ๐Ÿ‘‘


๐Ÿ”ฎ SEE ALSO ๐Ÿ”ฎ


and that's the whole thing bestie, ily, go map some users ๐Ÿซถ๐Ÿ’–

โ€” PostgreSQL 17.11, dated 2026, page CREATE USER MAPPING(7). periodt. ๐Ÿ’…โœจ

๐Ÿ“ฆ where this page comes from