Redshift how to get the invoker username when executing a definers rights pl/pgsql procedure from Redshift

It is not difficult but also not straight forward.  If you do a:

select current_user;

A definers right procedure will show you the username of the definer.  Not what we want.

Solution: use 1st call invokers rights proc – get current_user:

select into v_username current_user;

Now call a definers rights from within the invokers rights.

By compiling the stored procedures as suggested above as a Redshift superuser, you can in affect, give (grant execute) to a user or group access to super user to select features, as you deem reasonable. For example, Redshift is notorious for holding shared locks all over if you do not turn on autocommit or have long running transacions.

Leave a Comment

Scroll to Top