Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f73V1-0005k5-JD for pgsql-general@arkaria.postgresql.org; Fri, 13 Apr 2018 18:32:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f73V0-0001Gn-0v for pgsql-general@arkaria.postgresql.org; Fri, 13 Apr 2018 18:32:38 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f73Uy-0001Gc-RP for pgsql-general@lists.postgresql.org; Fri, 13 Apr 2018 18:32:37 +0000 Received: from resqmta-ch2-09v.sys.comcast.net ([2001:558:fe21:29:69:252:207:41]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f73Uv-0006MF-RU for pgsql-general@postgresql.org; Fri, 13 Apr 2018 18:32:35 +0000 Received: from resomta-ch2-04v.sys.comcast.net ([69.252.207.100]) by resqmta-ch2-09v.sys.comcast.net with ESMTP id 73TWf0FCzOjYT73UtfrMVd; Fri, 13 Apr 2018 18:32:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20161114; t=1523644351; bh=mw33di3Zd5RNpsUapFfHVY1KMuq/uGFUPVcOtwQOF/o=; h=Received:Received:Received:From:To:Subject:Date:Message-ID: MIME-Version:Content-Type; b=TVxoQy31jQFuRsWmHmWnfftNzek55RGYK4/wVK69NODu+MOK0EUQjTkktDcGuE5dQ qhpiU0/9iD7C07rkld3fC/WuMn+FaZqcPPB74YS7RMz2s4P2BjvR0gbUsL0w3WDwG5 bfdLNLyvFCCeS3YjZWWUmwjT05upFuXMSokVqvP8T229mN4bldt+TTOp+RtARsDI6j gl7/qolVk2ZIu4picjI1svkOOl5/js9yyGkFVRevoXrQssWHa4oSY4MCodYhWJWyuz +cK79DhWy2bRfJ2ks1rSeTp33/+pxcdCm7GzfeSCu5MtsIrUqrMiyMaktCDCxXobRs 8UQvd8gg+nYPg== Received: from jsievers.comcast.net ([12.30.159.20]) by resomta-ch2-04v.sys.comcast.net with SMTP id 73UlfGJZRibDC73UnfpT14; Fri, 13 Apr 2018 18:32:29 +0000 Received: from jsievers.enova.com (localhost [127.0.0.1]) by jsievers.comcast.net (Postfix) with ESMTP id EB6D5260056 for ; Fri, 13 Apr 2018 13:32:22 -0500 (CDT) From: Jerry Sievers To: pgsql-general@postgresql.org Subject: Gratuitous use of savepoint considered silly, if not harmful Date: Fri, 13 Apr 2018 13:32:22 -0500 Message-ID: <87k1tbrm89.fsf@jsievers.enova.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-CMAE-Envelope: MS4wfG1k2EhdYzQrD8BKQ/R3RATriVAIpk7psNht6uMB/KuvO4PkhO/+g3Fr/aaoE4Dea5UDU5nVBplV/gYMdobLm0+5ecFbSuIbz6QoAMy+RiXiHK5GwJB1 E1Pk/xrgrIQHooh9GpEtcM4ILaCgeLvhHeAqWaKUHJKLM4xO0S8FjkvTteVqjZVEpH0BQzkdKt1bWQ== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk So I'm (was) puzzled here when a big warehouse system just upgraded to 9.6 which I knew does only a few 100k *real* transactions/day was wrapping txid_current() so fast, in turn causing some big, nasty tablesl to age and then require painful long-running vacuums... Got the brilliant idea to full statement log for just 20 minutes or so and then do some digging. OMG my DW team's Pentaho/Kettle driver gizmo emulates single-line autocommit inserts using savepoints. It racked up ~1.8M txids meanwhile actually doing only ~900 transactions. Symptomatic of this also is that your pg_stat_database.(xact_commit + xact_rollback) counter over time will be wildly smaller then the advancement of txid_current() perhaps helping in the confusion. This was csvlogged and field #8 is command-tag which we're pulling out and summarizing as seen below. tmp$ grep ^2018 $log-file | grep silly_etl_user | cut -d, -f8 | sort | uniq -c | sort -k1,1bnr -k2 1880283 "INSERT" 1879931 "RELEASE" 1879931 "SAVEPOINT" 314838 "SELECT" 314298 "UPDATE" 2681 "idle" 2677 "authentication" 1967 "SET" 898 "COMMIT" 897 "BEGIN" 160 "DELETE" 83 "TRUNCATE TABLE" 6 "DROP TABLE" 2 "CREATE INDEX" 2 "CREATE TABLE AS" Anyway, I felt this was worth sharing :-) Thx -- Jerry Sievers Postgres DBA/Development Consulting e: postgres.consulting@comcast.net p: 312.241.7800