-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(postgres): support auto-provisioned user deletion Redshift (#34006)
- Loading branch information
1 parent
21beaa8
commit 66c08b4
Showing
2 changed files
with
54 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
CREATE OR REPLACE PROCEDURE teleport_delete_user(username varchar) | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
-- 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'; | ||
ELSE | ||
BEGIN | ||
EXECUTE 'DROP USER ' || QUOTE_IDENT(username); | ||
EXCEPTION WHEN OTHERS THEN | ||
-- Redshift only support OTHERS as exception condition, so we handle | ||
-- any error that might happen. | ||
|
||
-- Drop user/role will fail if user has dependent objects. | ||
-- In this scenario, fallback into disabling the user. | ||
CALL teleport_deactivate_user(username); | ||
END; | ||
END IF; | ||
END;$$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters