pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: rihad <rihad@mail.ru>
To: Jeff Janes <jeff.janes@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-general General <pgsql-general@postgresql.org>
Subject: Re: When do vacuumed pages/tuples become available for reuse?
Date: Thu, 11 Apr 2019 23:04:40 +0400
Message-ID: <8aa21502-aed5-2114-dbb0-e2e03b7557eb@mail.ru> (raw)
In-Reply-To: <CAMkU=1wNZrKVK9Jy0jWqBtuEN=_rHBrfZ6iA3eKgk0DTm=igkA@mail.gmail.com>
References: <9cd73fcb-511d-ede9-6789-209b7d4eb193@mail.ru>
	<8560.1554990486@sss.pgh.pa.us>
	<0522481c-4cf6-1928-8780-9bfa2d7c6aca@mail.ru>
	<9914.1554992415@sss.pgh.pa.us>
	<17dafb0f-5ab9-390e-96b0-2280d654f790@mail.ru>
	<CAMkU=1wZ1jSDKOqR+KVoDXUT7yprWqMZD-Rv-x__q3i-URkHQw@mail.gmail.com>
	<c7d435c1-a6f6-d570-1698-b8791161d406@mail.ru>
	<CAMkU=1z+-o0F5PSsjhN8P98+YrYgg7odTZ+WZvocBObY-LnZLA@mail.gmail.com>
	<44a10837-648b-7cc9-d42a-146bc0c83574@mail.ru>
	<CAMkU=1wNZrKVK9Jy0jWqBtuEN=_rHBrfZ6iA3eKgk0DTm=igkA@mail.gmail.com>

On 04/11/2019 10:13 PM, Jeff Janes wrote:
> On Thu, Apr 11, 2019 at 12:18 PM rihad <rihad@mail.ru 
> <mailto:rihad@mail.ru>> wrote:
>
>     On 04/11/2019 08:09 PM, Jeff Janes wrote:
>>     On Thu, Apr 11, 2019 at 11:44 AM rihad <rihad@mail.ru
>>     <mailto:rihad@mail.ru>> wrote:
>>
>>
>>         Since we dump&restore production DB daily into staging
>>         environment, the difference in size (as reported by psql's
>>         \l+) is 11GB in a freshly restored DB as opposed to 70GB in
>>         production.
>>
>>
>>     Yeah, that seems like a problem.  Do you have long lived
>>     transactions/snapshots that are preventing vacuuming from
>>     removing dead tuples? You can run a manual "vacuum verbose" and
>>     see how many dead but nonremovable tuples there were, or
>>     set log_autovacuum_min_duration to some non-negative value less
>>     than the autovac takes, and do the same.
>>
>     vacuum frees tuples just fine. It's just that by the time each run
>     finishes many more accumulate due to table update activity, ad
>     nauseum. So this unused space constantly grows. Here's a sample
>     autovacuum run:
>
>     2019-04-11 19:39:44.450841500 [] LOG:  automatic vacuum of table
>     "foo.public.bar": index scans: 1
>     2019-04-11 19:39:44.450843500   pages: 0 removed, 472095 remain, 4
>     skipped due to pins, 39075 skipped frozen
>     2019-04-11 19:39:44.450844500   tuples: 19150 removed, 2725811
>     remain, 465 are dead but not yet removable
>     2019-04-11 19:39:44.450845500   buffer usage: 62407557 hits,
>     6984769 misses, 116409 dirtied
>     2019-04-11 19:39:44.450846500   avg read rate: 16.263 MB/s, avg
>     write rate: 0.271 MB/s
>     2019-04-11 19:39:44.450847500   system usage: CPU 59.05s/115.26u
>     sec elapsed 3355.28 sec
>
>
> This data doesn't seem to support either one of our theories.  "Dead 
> but not yet removable" is low.  But "removed" also seems pretty low.  
> Is 19,150 really the number of updates you think occur over the course 
> of an hour which causes the problem you are seeing?  Updates that 
> happened during one vacuum should be cleanly caught by the next one, 
> so you should only see a steady state of bloat, not unbounded increase.
>
> But your buffer usage being 132 time the number of pages in the table 
> suggests it is your indexes, not your table, which are bloated.
> How many indexes do you have, and of what type?  Index pages can only 
> get reused when they become completely empty, or when a new indexed 
> value fits into (or near) the key-space that that page already 
> covers.  So if the key space for new tuples is constantly migrating 
> around and your pages never become absolutely empty, you can get 
> unbounded bloat in the indexes.

Way to many indexes. I'm going to have a hard time convincing our 
programmers to get rid of any of them )

>
> Can you compare the sizes object by object between the live and the 
> stage, taking care not to include index (or toast) size into the size 
> of their parent table?

You're right, it's mostly indexes that are bloated.

Staging:
# select pg_size_pretty(pg_relation_size('foo'));
  pg_size_pretty
----------------
  2924 MB
(1 row)

# select pg_size_pretty(pg_indexes_size('foo'));
  pg_size_pretty
----------------
  1958 MB
(1 row)

Prod:

# select pg_size_pretty(pg_relation_size('foo'));
  pg_size_pretty
----------------
  3688 MB
(1 row)

# select pg_size_pretty(pg_indexes_size('foo'));
  pg_size_pretty
----------------
  60 GB
(1 row)



>
>>
>>     Also, what does pg_freespace
>>     (https://www.postgresql.org/docs/current/pgfreespacemap.html)
>>     show about the available of space in the table? How
>>     about pgstattuple
>>     (https://www.postgresql.org/docs/current/pgstattuple.html)
>     Thanks, I'll try those. But as I said freshly restored DB is only
>     11GB in size, not 70 (only public schema is used).
>
>
> Yeah, but we need to know **why** that extra 59GB  is not being 
> reused, not simply the fact that it isn't being reused.  If it isn't 
> listed as free in the freespace map, then PostgreSQL might not know 
> how to find it in order to reuse it, for example. But now that I think 
> it is the indexes, not the table, that is bloated I would chase that 
> part down first.  No point checking the freespace of the table proper 
> if the problem is with the indexes.
> Cheers,
>
> Jeff

view thread (30+ messages)  latest in thread

Message-ID: <8aa21502-aed5-2114-dbb0-e2e03b7557eb@mail.ru>
Permalink:  ../8aa21502-aed5-2114-dbb0-e2e03b7557eb@mail.ru/
Also on:    postgresql.org/message-id/8aa21502-aed5-2114-dbb0-e2e03b7557eb@mail.ru

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: rihad@mail.ru, jeff.janes@gmail.com, tgl@sss.pgh.pa.us
  Subject: Re: When do vacuumed pages/tuples become available for reuse?
  In-Reply-To: <8aa21502-aed5-2114-dbb0-e2e03b7557eb@mail.ru>
  References: <9cd73fcb-511d-ede9-6789-209b7d4eb193@mail.ru> <8560.1554990486@sss.pgh.pa.us> <0522481c-4cf6-1928-8780-9bfa2d7c6aca@mail.ru> <9914.1554992415@sss.pgh.pa.us> <17dafb0f-5ab9-390e-96b0-2280d654f790@mail.ru> <CAMkU=1wZ1jSDKOqR+KVoDXUT7yprWqMZD-Rv-x__q3i-URkHQw@mail.gmail.com> <c7d435c1-a6f6-d570-1698-b8791161d406@mail.ru> <CAMkU=1z+-o0F5PSsjhN8P98+YrYgg7odTZ+WZvocBObY-LnZLA@mail.gmail.com> <44a10837-648b-7cc9-d42a-146bc0c83574@mail.ru> <CAMkU=1wNZrKVK9Jy0jWqBtuEN=_rHBrfZ6iA3eKgk0DTm=igkA@mail.gmail.com> <8aa21502-aed5-2114-dbb0-e2e03b7557eb@mail.ru>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox