Trigger function always logs postgres as user name

Поиск
Список
Период
Сортировка
От Alexander Reichstadt
Тема Trigger function always logs postgres as user name
Дата
Msg-id 7726A65A-7A13-4C1D-82C5-AE95F2F34EB7@me.com
обсуждение исходный текст
Ответы Re: Trigger function always logs postgres as user name  (Francisco Olarte <folarte@peoplecall.com>)
Re: Trigger function always logs postgres as user name  (Alexander Reichstadt <lxr@mac.com>)
Список pgsql-general
Hi,

I setup trigger functions for logging, and while they do work and get triggered, the current_user always insert
“postgres”even when updates/deletes/inserts are caused by users of another name. 

How do I get it to use the name that caused the update? It seems current_user is the trigger’s user, so the server
itselfin some way. This is on PG10 

Here the function:
        BEGIN

                IF      TG_OP = 'INSERT'

                THEN

                        INSERT INTO logging (tabname, schemaname, who, operation, new_val)

                                VALUES (TG_RELNAME, TG_TABLE_SCHEMA, current_user, TG_OP, row_to_json(NEW));

                        RETURN NEW;

                ELSIF   TG_OP = 'UPDATE'

                THEN

                        INSERT INTO logging (tabname, schemaname, who, operation, new_val, old_val)

                                VALUES (TG_RELNAME, TG_TABLE_SCHEMA, current_user, TG_OP,

                                        row_to_json(NEW), row_to_json(OLD));

                        RETURN NEW;

                ELSIF   TG_OP = 'DELETE'

                THEN

                        INSERT INTO logging (tabname, schemaname, operation, who, old_val)

                                VALUES (TG_RELNAME, TG_TABLE_SCHEMA, TG_OP, current_user, row_to_json(OLD));

                        RETURN OLD;

                END IF;

        END;



Cheers,
Alex

В списке pgsql-general по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: Server goes to Recovery Mode when run a SQL
Следующее
От: auxsvr
Дата:
Сообщение: Re: FDW, too long to run explain