mirror of
https://github.com/gravitational/teleport.git
synced 2026-11-04 02:21:02 +08:00
* Database Automatic User Provisioning support for Redshift * capitalize sql script * DeleteUser to fallback to deactivate. * add TPxxx code to RAISE messages * fix missing space in scripts
22 lines
764 B
PL/PgSQL
22 lines
764 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 %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;$$;
|