CREATE_USER_MAPPING(7pg17)
๐ 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, andUSERall match the name of the current user. and whenPUBLICis 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 ๐ฎ
ALTER USER MAPPING(ALTER_USER_MAPPING(7))DROP USER MAPPING(DROP_USER_MAPPING(7))CREATE FOREIGN DATA WRAPPER(CREATE_FOREIGN_DATA_WRAPPER(7))CREATE SERVER(CREATE_SERVER(7))
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
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms