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 1hjOdm-00007g-A3 for pgsql-general@arkaria.postgresql.org; Fri, 05 Jul 2019 13:52:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hjOdl-0002G9-5b for pgsql-general@arkaria.postgresql.org; Fri, 05 Jul 2019 13:52:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hjOdk-0002G2-Lo for pgsql-general@lists.postgresql.org; Fri, 05 Jul 2019 13:52:40 +0000 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hjOdi-0005XI-Ba for pgsql-general@lists.postgresql.org; Fri, 05 Jul 2019 13:52:39 +0000 Received: by mail-io1-xd42.google.com with SMTP id z3so4335625iog.0 for ; Fri, 05 Jul 2019 06:52:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=WX/mX2WJWLSPDVMW/1YPbyf9fDYap7g0CmyZnjduZOM=; b=S4R0f5QwQ4Stz7koKyfqcKjcaqXLj/q3zU0zY4wfaS9lFjAYiehv9uxfr7LtIFceGe +HQgwtrm8N5Tsx8NUCTgE2jpmHywRAz/8cJCb9NCtZy2cm0jdiLcbUaZH3YcBNNK+0Sg gehvRIHCgSKpuqDt4e+qoZjKmE5lLfee4i5FXDYnPemxO7FGEl4Gqba/dlI3tI3l/nXy 6GQ4kroZWnAKU/ZjYunhh5zRu3xKAWjGQgIXG9TdHj+N+KQ/Ulmsy1IywlKsDeqG99qX Qp4Hi4RtvQQuZHz81uX1Mbsy1hFuAbIpsWXzSfbQX8ldjIYmS01mp/bEFvEbNS1AaLRj eMQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=WX/mX2WJWLSPDVMW/1YPbyf9fDYap7g0CmyZnjduZOM=; b=FQ9j+ZbjqcFx1iHZqb6YxGBsMPtYsHh6rAJaXymsTdaGecCMwsFntL/25EC7wkOuR/ eK4iwCNa86qLXOax3Ofu7tSG/s3FYeBLam6Db8+n/IBg4D7cIZuxdZZrohkucq+ezXse e0nrzNDHlOR5MxRgelvCq+g1Ht/HurCCoGb3nN5qGjqD7F0nB4nAPvtl1SsBDIGLdVF3 gfOR3L6fovMC+QZPI7V4BvshpXqz/AO8Xt6YcrCfIYqeRqJLwS5P1FQox0vGZmq0GhUV C0btHrGoLzd7znSGDriux+H/HClo5cNvYPyimEQRN3zG6unkI/tEjtyyiQuFeaoLyZ70 ngKQ== X-Gm-Message-State: APjAAAX7hGoKiLLUBbkKBYNfRIZ+PjI8FbZtt2zC3cS0WxGOPuJsZOLq dqvsHBQbsiwWAPLjFRA3xdGZ8JVzxt12hw== X-Google-Smtp-Source: APXvYqwmWZjTiTDzeVYiPBci4l/uhxAz2VgtPQvwMXytKsP39ekVqHJ/9KBbzKw7Wfb2IWRaeKCmuA== X-Received: by 2002:a02:3c07:: with SMTP id m7mr5051733jaa.64.1562334756985; Fri, 05 Jul 2019 06:52:36 -0700 (PDT) Received: from [192.168.1.10] (ip70-171-116-89.no.no.cox.net. [70.171.116.89]) by smtp.googlemail.com with ESMTPSA id u4sm11028869iol.59.2019.07.05.06.52.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Jul 2019 06:52:36 -0700 (PDT) Subject: Re: Vacuum and freeing dead rows To: pgsql-general@lists.postgresql.org References: From: Ron Message-ID: Date: Fri, 5 Jul 2019 08:52:35 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------960FA938231D804D6B00888B" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------960FA938231D804D6B00888B Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 7/5/19 3:16 AM, Simon T wrote: > Hi, > > I have a very heavily updated table in a Postgres 9.6.10 database with > lots of disk bloat. Every row is updated about once a minute, and > little to no inserts. Approx 18k rows total. The table has bloated > from ~1700 KB to about 6 GB over a few weeks time. I'm trying to > understand why vacuum hasn't made dead rows available for re-use. > [snip] > And in case it is relevant: > > appdb=# SELECT pid, datname, usename, state, backend_xmin > appdb-# FROM pg_stat_activity > appdb-# WHERE backend_xmin IS NOT NULL > appdb-# ORDER BY age(backend_xmin) DESC; > pid | datname | usename | state | backend_xmin > -------+---------------+----------+---------------------+-------------- > 10921 | appdb | app | idle*in transaction* | 3501305052 "idle IN TRANSACTION" is never good.  Transactions should always be as short as possible. > 10919 | appdb | app | idle in transaction | 3501305052 > 10916 | appdb | app | idle in transaction | 3501305052 > 27935 | appdb | app | idle in transaction | 3501305052 > 24500 | appdb | postgres | active | 3501305052 > 10914 | appdb | app | active | 3501305052 > 20671 | appdb | postgres | active | 3501305052 > 11817 | appdb | app | active | 3501305052 > 1988 | appdb | app | active | 3501305052 > 15041 | appdb | postgres | active | 3501305052 > 9916 | appdb | postgres | active | 3501305052 > 10912 | appdb | app | idle in transaction | 3501305052 > 10909 | appdb | app | idle in transaction | 3501305052 > (13 rows) Add backend_start to that query.  I'd kill any idle transactions are more than 30 minutes old.  (Of course, since they're "idle IN TRANSACTION", you'd lose stuff. -- Angular momentum makes the world go 'round. --------------960FA938231D804D6B00888B Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit On 7/5/19 3:16 AM, Simon T wrote:
Hi,

I have a very heavily updated table in a Postgres 9.6.10 database with
lots of disk bloat. Every row is updated about once a minute, and
little to no inserts. Approx 18k rows total. The table has bloated
from ~1700 KB to about 6 GB over a few weeks time. I'm trying to
understand why vacuum hasn't made dead rows available for re-use.

[snip]
And in case it is relevant:

appdb=# SELECT pid, datname, usename, state, backend_xmin
appdb-# FROM pg_stat_activity
appdb-# WHERE backend_xmin IS NOT NULL
appdb-# ORDER BY age(backend_xmin) DESC;
  pid | datname | usename | state | backend_xmin
-------+---------------+----------+---------------------+--------------
 10921 | appdb | app | idle in transaction | 3501305052

"idle IN TRANSACTION" is never good.  Transactions should always be as short as possible.

 10919 | appdb | app | idle in transaction | 3501305052
 10916 | appdb | app | idle in transaction | 3501305052
 27935 | appdb | app | idle in transaction | 3501305052
 24500 | appdb | postgres | active | 3501305052
 10914 | appdb | app | active | 3501305052
 20671 | appdb | postgres | active | 3501305052
 11817 | appdb | app | active | 3501305052
  1988 | appdb | app | active | 3501305052
 15041 | appdb | postgres | active | 3501305052
  9916 | appdb | postgres | active | 3501305052
 10912 | appdb | app | idle in transaction | 3501305052
 10909 | appdb | app | idle in transaction | 3501305052
(13 rows)

Add backend_start to that query.  I'd kill any idle transactions are more than 30 minutes old.  (Of course, since they're "idle IN TRANSACTION", you'd lose stuff.

--
Angular momentum makes the world go 'round.
--------------960FA938231D804D6B00888B--