CREATE USER MAPPING

Updated at:

CREATE USER MAPPING — define a new mapping of a user to a foreign server.

Syntax

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

Overview

A user mapping stores the authentication credentials a foreign data wrapper (FDW) uses when connecting to a foreign server. The FDW combines the credentials in the user mapping with the connection details in the foreign server definition to access the external data source.

Who can create a user mapping:

  • The owner of a foreign server can create a mapping for any user.

  • Any user granted the USAGE privilege on a server can map their own username to that server.

Parameters

ParameterDescription
IF NOT EXISTSSkips the command without raising an error if a mapping from the specified user to the specified foreign server already exists. A notice is issued instead.
Note

The existing mapping may not match what you intended to create.

user_nameThe name of the existing local user to map to the foreign server. CURRENT_USER and USER resolve to the name of the current user. Specify PUBLIC to create a fallback mapping used when no user-specific mapping exists.
server_nameThe name of the existing foreign server to map the user to.
OPTIONS ( option 'value' [, ... ] )Connection options for the mapping — typically a remote username and password. Option names must be unique. The accepted option names and values are specific to the foreign data wrapper for the server.

Example

Map the local user bob to the foreign server foo, supplying remote credentials:

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

To adapt this to your environment, replace the following placeholders:

PlaceholderDescription
bob (FOR clause)The local PolarDB for PostgreSQL username to map
fooThe name of the foreign server created with CREATE SERVER
'bob' (user option)The username on the remote server
'secret'The password for the remote user