View a markdown version of this page

PG_GET_SESSION_ROLES - Amazon Redshift

Amazon Redshift will no longer support the use of Python UDFs after June 30, 2026. We will start enforcing it in phases. For more information on the details of Python end of life and migration options, see the blog post that was published on June 30, 2025.

PG_GET_SESSION_ROLES

Returns session roles of the currently logged in user. Session roles can correspond to groups defined for the user by an identity provider (IdP). For example, an identity provider such as Microsoft Azure Active Directory (Azure AD) verifies the identity of the user and provides external groups during sign-in. Amazon Redshift maps those groups to roles that are available during the current session. An administrator can grant privileges to a session role similar to other Amazon Redshift roles. For information about using roles, see Role-based access control (RBAC). For information about managing identities with an identity provider, see Native identity provider (IdP) federation for Amazon Redshift in the Amazon Redshift Management Guide.

For trusted identity propagation for IAM, session roles can include existing Amazon Redshift roles whose names exactly match the person's IAM Identity Center groups. The returned role name has no identity provider namespace prefix. When the session runs as the person, Amazon Redshift ignores roles in the RedshiftDbRoles session tag. For sessions that run as an IAM database user, such as IAM: or IAMR:, session roles can include roles from that tag.

To view the roles defined in the Amazon Redshift catalog, query the system view SVV_ROLES.

Syntax

pg_get_session_roles()

Return type

A set of rows that consists of two values. The first value is the role name. For roles from a namespaced identity provider, the name has two parts separated by a colon in the form idp-namespace:role-name. For trusted identity propagation for IAM, the value is the exact matching Amazon Redshift role name without an identity provider namespace prefix. The second value is the role identifier.

Usage notes

The PG_GET_SESSION_ROLES function returns one row for each session role. It returns only session roles and doesn't combine them with user-to-role or role-to-role grants stored in the database. Session roles end with the session.

A supported system role, such as sys:dba, can be added to a direct group-enabled session when the cluster or namespace identity configuration allows it. A session forwarded to a warehouse with federated permissions doesn't receive system roles from group mapping.

Examples

The following example returns the matching Amazon Redshift roles for a session that uses trusted identity propagation for IAM. These role names don't have an identity provider namespace prefix.

SELECT * FROM pg_get_session_roles() AS t(rolname name, rolid integer); rolname | rolid -------------------+-------- finance_analysts | 104321

The temporary finance_analysts session role is different from any ordinary stored grant shown by SVV_USER_GRANTS.

The following example returns one row for each role from the Azure Active Directory IdP. The returned columns are cast to sess_roles with columns name and roleid. Each name consists of the Azure Active Directory namespace and a group name in Azure Active Directory.

SELECT * FROM pg_get_session_roles() AS sess_roles(name name, roleid integer); name roleid -------------------------------- my_aad:test_group_1 106204 my_aad:test_group_2 106205 my_aad:test_group_3 106206 my_aad:test_group_4 106207 my_aad:test_group_5 106208

The following example returns one row for each IAM group that the currently logged in IAM user is a member of. The returned columns are cast to sess_roles with columns name and roleid. Each name consists of the IAM namespace and IAM group name.

SELECT * FROM pg_get_session_roles() AS sess_roles(name name, roleid integer); name roleid -------------------------------- IAM:myGroup 110332