Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gsRrF-00055F-RN for pgsql-general@arkaria.postgresql.org; Sat, 09 Feb 2019 12:35:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gsRrD-0004Lw-PT for pgsql-general@arkaria.postgresql.org; Sat, 09 Feb 2019 12:35:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gsPZM-00019i-L8 for pgsql-general@lists.postgresql.org; Sat, 09 Feb 2019 10:09:08 +0000 Received: from mr85p00im-zteg06011501.me.com ([17.58.23.182]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gsPZH-0002y7-GG for pgsql-general@postgresql.org; Sat, 09 Feb 2019 10:09:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=04042017; t=1549706940; bh=KSAa+kRY/DVoLum1p+hIFEDufTdWs6QzmyPw6FSB/SM=; h=From:Content-Type:Mime-Version:Subject:Message-Id:Date:To; b=vYia3juWyyGyXxpWJyqife54ju71kRzx8Zy8OUw8GDE9ov14/XRYIqygB7olP/j6m SqEFRvD+HAl0D1iZfdclpyw5IMZADVDiVLhpnsTNn6SoeRN2B32hIwjA/rOuPHlbD4 cC9tmxl+0qLo6OOHtgFcaoY8QpBDgSMmMuW6YFs83SBU7DKQIeF32nkOwE9z5Y6WOQ aV1IVJgWk4mJK8n1itslcn76UneZSB5zwLmYRreUn92m/cIIAezFsVWsEb8+Zu6y6I N7TOrG/orDUm0umyutoXwJ6pIjnFvJdxXm9J8QWT+kL7mbnO+sUmhrSnkGQEnUMBqW 88Az0F2J7yIYw== Received: from [17.150.222.150] (unknown [17.150.222.150]) by mr85p00im-zteg06011501.me.com (Postfix) with ESMTPSA id E69C42A0100 for ; Sat, 9 Feb 2019 10:08:59 +0000 (UTC) From: Alexander Reichstadt Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Subject: Trigger function always logs postgres as user name Message-Id: <7726A65A-7A13-4C1D-82C5-AE95F2F34EB7@me.com> Date: Sat, 9 Feb 2019 10:08:53 +0000 To: pgsql-general@postgresql.org X-Mailer: Apple Mail (2.3445.102.3) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-02-09_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 mlxscore=0 mlxlogscore=439 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1812120000 definitions=main-1902090075 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, I setup trigger functions for logging, and while they do work and get = triggered, the current_user always insert =E2=80=9Cpostgres=E2=80=9D = 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=E2=80=99s user, so the server itself in some = way. This is on PG10 Here the function: BEGIN IF TG_OP =3D '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 =3D '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 =3D '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=