Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mOdtZ-0005dX-2P for pgsql-admin@arkaria.postgresql.org; Fri, 10 Sep 2021 10:36:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mOdtV-0006F3-Of for pgsql-admin@arkaria.postgresql.org; Fri, 10 Sep 2021 10:36:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mOdtV-0006Ev-Ft for pgsql-admin@lists.postgresql.org; Fri, 10 Sep 2021 10:36:29 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mOdtS-0003ik-Od for pgsql-admin@lists.postgresql.org; Fri, 10 Sep 2021 10:36:28 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 18AAaLCQ3933157; Fri, 10 Sep 2021 06:36:21 -0400 From: Tom Lane To: depesz@depesz.com cc: Hotmail , pgsql-admin@lists.postgresql.org Subject: Re: Is there anyway for non-superuser to log all sql statements at the session level? In-reply-to: <20210910084255.GB11352@depesz.com> References: <16e9ff79-fe32-4d0d-be57-7c823744a793@Spark> <20210910084255.GB11352@depesz.com> Comments: In-reply-to hubert depesz lubaczewski message dated "Fri, 10 Sep 2021 10:42:55 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <3933155.1631270181.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Fri, 10 Sep 2021 06:36:21 -0400 Message-ID: <3933156.1631270181@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk hubert depesz lubaczewski writes: > On Thu, Sep 09, 2021 at 05:30:55PM -0600, Hotmail wrote: >> We use liquibase to run migrations against our postgres 11 database. >> We run the migrations as an application user that does not have >> superuser permissions. Is there any workaround we could use that would >> allow us to capture the migration sql that is run by our application >> user? We want to capture all of the ddl as well as the dml run by the >> migration user. Since setting log_statement=all  at the session level >> isn’t possible unless the user is a superuser is there any other way >> to accomplish this task? > Sure. Make a security-definer function that changes the log_statement, > and grant privileges to call it to whoever you need. Also you can do alter user foo set log_statement = 'all'; to apply the setting at future logins of user foo. (While a non-superuser can't do that for themselves, a superuser can do it for them.) regards, tom lane