A possible explanation is that something is taking an exclusive lock on some system catalog and holding it for a second or two. If so, turning on log_lock_waits might provide some useful info.
regards, tom lane
I just checked my configuration and found out that "log_lock_waits" was already enabled.
Unfortunately there is no log output of locks when those long running "SET ROLE" statements occur.