DB2 Ownership Transfer

If you ever get an error in DB2 along the lines of…

SQLCODE=-727, SQLSTATE=56098, SQLERRMC=1;-551;42501;MARKJ|EXECUTE|XX.PROC_P

…but in your code are executing the proc as another user (say “USR1”) instead of MARKJ, it may be that MARKJ created the proc and until recently still had the necessary access for executing everything in XX.PROC_P. Subsequently permissions were “fixed” and now stuff starts blowing up all over because MARKJ no longer has access. How to fix? Well, like all things I’m sure there are a million ways to do it, but the easiest in this situation was to have MARKJ transfer the ownership on everything he owned. To determine that, the following SQL was run to generate the commands, then the commands were run…


SELECT 
CASE ROUTINETYPE WHEN 'F' THEN
    'TRANSFER OWNERSHIP OF FUNCTION  '||
    RTRIM(ROUTINESCHEMA)||'.'|| ROUTINENAME ||
    ' TO USER DB2DBA PRESERVE PRIVILEGES; '
ELSE
    'TRANSFER OWNERSHIP OF PROCEDURE  '||
    RTRIM(ROUTINESCHEMA)||'.'|| ROUTINENAME ||
    ' TO USER DB2DBA PRESERVE PRIVILEGES; '
END
FROM SYSCAT.ROUTINES 
WHERE OWNER = 'MARKJ' 
WITH UR;
Please remember to subscribe to the newsletter to stay up to date!

You or someone you know looking to buy or sell?
Disclaimer: Thoughts and opinions are my own, and do not reflect the views of any employer, family member, friend, or anyone else. Some links may be affiliate links, but I don't link to anything I don't use myself. You would think this should be self evident these days, but apparently not...

Leave a Reply