Postgres security for functions with "security definer" I was reading about possible security issues when creating functions in Postgres with "security definer". Official documentation suggests that search_path is set to some trusted schema followed by pg_temp. All examples I could find had pg_temp at the end. Do I have to put pg_temp at the end, what would happen if set search_path only to the trusted schema? Would it open any security holes? And why would you put pg_temp in search_path anyway?
pg_temp is always in the search path.  If you don't add it to search_path parameter explicitly, it will behave as if it were there at the beginning of the setting.  That means the user could create tables which masked the ones the function was supposed to operate on.