So is there a way to associate user variable with Postgres connection that can be picked up by SQL code running in that connection? Right now I can only think of PlPerl function that caches user id in a global variable, but am not sure about potential pitfalls of such setup...
You could use temporary table. E.g. create temporary table localdata(name, value) as select values('user', 'john'); This will be connection-scope.