CREATE_USER_MAPPING(7pg18)
โจ 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
USAGEprivilege on the server has been granted to the user. noUSAGE, 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, andUSERall match the name of the current user. and when you specifyPUBLIC, 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 ๐ซถ
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))
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 ๐โจ๐ธ
๐ฆ where this page comes from
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms