Re: Vacuum and freeing dead rows

From: Ron <ronljohnsonjr(at)gmail(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Vacuum and freeing dead rows
Date: 2019-07-05 13:52:35
Message-ID: a3736853-13f3-ebaa-0c8f-aa6d03520826@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2019-07-05 14:03:16 Re: Active connections are terminated because of small wal_sender_timeout
Previous Message Adrian Klaver 2019-07-05 13:50:57 Re: Unavailability of Jar for connectivity in Postgres