CREATE_USER_MAPPING(7pg15)
π CREATE USER MAPPING π
okay bestie, welcome to the CREATE USER MAPPING(7) page from the PostgreSQL 15.19 Documentation β yes, the 7 manual, and yes, we're about to make user-to-foreign-server mappings feel iconic. π«Ά
π NAME π
CREATE USER MAPPING β define a new mapping of a user to a foreign server. 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' [ , ... ] ) ]
πΈ DESCRIPTION πΈ
So CREATE USER MAPPING defines a mapping of a user to a foreign server β it's giving "this user connects through this foreign server," no cap. 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. Basically, the mapping is carrying the connection deets that the FDW and server combo need. π
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. Slay, permissions.
π¦ 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. β οΈ But plot twist: there is no guarantee that the existing user mapping is anything like the one that would have been created. So like, don't assume it ate.user_nameβ the name of an existing user that is mapped to foreign server.CURRENT_ROLE,CURRENT_USER, andUSERmatch the name of the current user. WhenPUBLICis specified, a so-called public mapping is created that is used when no user-specific mapping is applicable. Main character energy for the fallback mapping, honestly.server_nameβ the name of an existing server for which the user mapping is to be created.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. The allowed option names and values are specific to the server's foreign-data wrapper. iykyk β check your FDW for the valid menu.
π EXAMPLES π
Create a user mapping for user bob, server foo:
CREATE USER MAPPING FOR bob SERVER foo OPTIONS (user 'bob', password 'secret');
literally that simple. π
β COMPATIBILITY β
CREATE USER MAPPING conforms to ISO/IEC 9075-9 (SQL/MED). periodt.
π 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))
okay that's the whole page, bestie. source/version: PostgreSQL 15.19; date: 2026. go forth and map those users, ily. πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-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