Files
teleport/lib/srv/db/postgres/sql/delete-user.sql
T
Gavin Frazar 54d2e903d5 add RDS MariaDB e2e tests (#40066)
* add AWS RDS MariaDB e2e tests

* fix spurious teardown error logs

* if a role or user doesn't exist, that is not an error nor is it worth
  logging during auto user teardown.

* check for admin option

* add some extra secret fetching checkings

* only drop redshift user if the user exists
2024-04-08 21:46:17 +00:00

22 lines
774 B
PL/PgSQL

CREATE OR REPLACE PROCEDURE teleport_delete_user(username varchar, inout state varchar default 'TP003')
LANGUAGE plpgsql
AS $$
DECLARE
role_ varchar;
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 FORMAT('DROP USER IF EXISTS %I', username);
EXCEPTION
WHEN SQLSTATE '2BP01' THEN
state := 'TP004';
-- 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;$$;