Skip to content

Fix an issue AWS Redshift auto-provisioned user not deleted in drop mode#36828

Merged
greedy52 merged 2 commits intomasterfrom
STeve/36708/fix
Jan 22, 2024
Merged

Fix an issue AWS Redshift auto-provisioned user not deleted in drop mode#36828
greedy52 merged 2 commits intomasterfrom
STeve/36708/fix

Conversation

@greedy52
Copy link
Copy Markdown
Contributor

@greedy52 greedy52 commented Jan 17, 2024

Fixes #36708

changelog: Fix an issue AWS Redshift auto-provisioned user not deleted in drop mode

@greedy52 greedy52 added database-access Database access related issues and PRs backport/branch/v14 labels Jan 17, 2024
@greedy52 greedy52 self-assigned this Jan 17, 2024
Comment on lines +6 to +7
IF EXISTS (SELECT user_name FROM stv_sessions WHERE user_name = CONCAT('IAM:', username)) THEN
RAISE EXCEPTION 'TP000: User has active connections';
Copy link
Copy Markdown
Contributor Author

@greedy52 greedy52 Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from:

-- Only deactivate if the user doesn't have other active sessions.
-- Update to pg_stat_activity is delayed for a few hundred ms. Use
-- stv_sessions instead.
IF EXISTS (SELECT user_name FROM stv_sessions WHERE user_name = CONCAT('IAM:', username)) THEN
RAISE EXCEPTION 'TP000: User has active connections';

Note the bug happens because pg_stat_activity is sometimes delayed so that the procedure will RAISE NOTICE 'User has active connections';. However, RAISE NOTICE does not trigger an error in our database engine with Redshift.

-- Only drop if the user doesn't have other active sessions.
IF EXISTS (SELECT usename FROM pg_stat_activity WHERE usename = username) THEN
RAISE NOTICE 'User has active connections';
IF EXISTS (SELECT user_name FROM stv_sessions WHERE user_name = CONCAT('IAM:', username)) THEN
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe include a link to https://docs.aws.amazon.com/redshift/latest/dg/r_STV_SESSIONS.html that explains what this table is? I had to look it up.

@greedy52 greedy52 enabled auto-merge January 22, 2024 16:17
@greedy52 greedy52 added this pull request to the merge queue Jan 22, 2024
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jan 22, 2024
@greedy52 greedy52 added this pull request to the merge queue Jan 22, 2024
Merged via the queue into master with commit 3a6d10f Jan 22, 2024
@greedy52 greedy52 deleted the STeve/36708/fix branch January 22, 2024 17:40
@public-teleport-github-review-bot
Copy link
Copy Markdown

@greedy52 See the table below for backport results.

Branch Result
branch/v14 Create PR
branch/v15 Create PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

database-access Database access related issues and PRs size/sm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AWS Redshift auto-user provisioning drop mode not deleting users

3 participants