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 1jgw1y-0003Qh-0P for pgsql-general@arkaria.postgresql.org; Thu, 04 Jun 2020 20:00:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jgw1w-0005ho-PO for pgsql-general@arkaria.postgresql.org; Thu, 04 Jun 2020 20:00:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jgw1w-0005hh-HR for pgsql-general@lists.postgresql.org; Thu, 04 Jun 2020 20:00:00 +0000 Received: from net153.net ([2001:470:b965:2:208:a1ff:fe05:bf2a]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jgw1s-0000kB-Ps for pgsql-general@lists.postgresql.org; Thu, 04 Jun 2020 19:59:59 +0000 Received: from [IPv6:2001:470:b965:1:8de6:905b:e17e:c2a1] (unknown [IPv6:2001:470:b965:1:8de6:905b:e17e:c2a1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by net153.net (Postfix) with ESMTPSA id 2747E497 for ; Thu, 4 Jun 2020 14:59:51 -0500 (CDT) Subject: Re: Monitoring for long running transactions To: pgsql-general@lists.postgresql.org References: From: Samuel Smith Message-ID: <920bb4ce-6ba8-2888-6239-52a15474fc58@net153.net> Date: Thu, 4 Jun 2020 14:59:51 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 6/4/20 2:29 PM, Adrian Klaver wrote: > On 6/4/20 10:00 AM, Samuel Smith wrote: >> We had a customer complaining of random data loss for the last 6 >> months or so. We eventually tracked it down to a combination of bad >> coding and a couple of bugs with the ORM. Basically, 'BEGIN' was being >> emitted by the web app when viewing a certain page and 'COMMIT' was >> never emitted after that. So once the app would get restarted, all >> data changes would be lost. Definitely worst case scenario. >> >> So the question is, what is the best way to monitor for this scenario >> going forward? Are there any plugins or community recommended scripts >> already made? > > https://www.postgresql.org/docs/12/monitoring-stats.html#PG-STAT-ACTIVITY-VIEW > > > " > state     text     Current overall state of this backend. Possible > values are: > >     active: The backend is executing a query. > >     idle: The backend is waiting for a new client command. > >     idle in transaction: The backend is in a transaction, but is not > currently executing a query. > >     idle in transaction (aborted): This state is similar to idle in > transaction, except one of the statements in the transaction caused an > error. > >     fastpath function call: The backend is executing a fast-path function. > >     disabled: This state is reported if track_activities is disabled in > this backend. > " > >> >> Regards, >> >> >> >> > > Sorry, I should have clarified that I was aware of the pg_stat_activity table. That is how we found the problem in the first place. And yes I could just write a bash script and run it in cron. I just didn't know if there was a more "official" way to go about this since it is probably a common monitoring point and/or if something like this was already made. Regards,