From: Tom Lane <tgl@sss.pgh.pa.us>
To: Nicola Contu <nicola.contu@gmail.com>
Cc: Kaixi Luo <kaixiluo@gmail.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Cc: Alessandro Aste <Alessandro.aste@gtt.net>
Subject: Re: Matview size - space increased on concurrently refresh
Date: Sun, 14 Jul 2019 16:23:03 -0400
Message-ID: <21217.1563135783@sss.pgh.pa.us> (raw)
In-Reply-To: <CAMTZZh3vqa94vU2g1fmzV2X3JDtNwr9G4GSPACHK2JgqbveWNg@mail.gmail.com>
References: <CAMTZZh1Muw_cg6fQHKihOK4i7mQarcmksE-+NPP0eEBaSPjywA@mail.gmail.com>
<CAMTZZh0vo62VczNBSF5dZ7MzWA0fKicn4MuU40=4MGSLiPcbRw@mail.gmail.com>
<CAHo5iyg88nFZaRWrkWvzL-j1fe9N=oaGpnDU973==ogFL5hEZA@mail.gmail.com>
<CAMTZZh3vqa94vU2g1fmzV2X3JDtNwr9G4GSPACHK2JgqbveWNg@mail.gmail.com>
[ please do not top-post in your replies, it makes the conversation hard
to follow ]
Nicola Contu <nicola.contu@gmail.com> writes:
> Il dom 14 lug 2019, 21:34 Kaixi Luo <kaixiluo@gmail.com> ha scritto:
>> This is normal and something to be expected. When refreshing the
>> materialized view, the new data is written to a disk and then the two
>> tables are diffed. After the refresh finishes, your view size should go
>> back to normal.
> It does not. That's the issue.
> It always increases of 120mb and it reached 12gb instead of just 180mb.
A concurrent matview refresh will necessarily leave behind two copies
of any rows it changes, just like any other row-update operation in
Postgres. Once there are no concurrent transactions that can "see"
the old row copies, they should be reclaimable by vacuum.
Since you're not seeing autovacuum reclaim the space automatically,
I hypothesize that you've got autovacuum turned off or dialed down
to unrealistically non-aggressive settings. Or possibly you have
old open transactions that are preventing reclaiming dead rows
(because they can still possibly "see" those rows). Either of those
explanations should imply that you're getting similar bloat in every
other table and matview, though.
You might want to look into pg_stat_all_tables to see what it says
about the last_autovacuum time etc. for that matview. Another source
of insight is to do a manual "vacuum verbose" on the matview and see
what that says about removable and nonremovable rows.
regards, tom lane
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: tgl@sss.pgh.pa.us, nicola.contu@gmail.com, kaixiluo@gmail.com, Alessandro.aste@gtt.net
Subject: Re: Matview size - space increased on concurrently refresh
In-Reply-To: <21217.1563135783@sss.pgh.pa.us>
References: <CAMTZZh1Muw_cg6fQHKihOK4i7mQarcmksE-+NPP0eEBaSPjywA@mail.gmail.com> <CAMTZZh0vo62VczNBSF5dZ7MzWA0fKicn4MuU40=4MGSLiPcbRw@mail.gmail.com> <CAHo5iyg88nFZaRWrkWvzL-j1fe9N=oaGpnDU973==ogFL5hEZA@mail.gmail.com> <CAMTZZh3vqa94vU2g1fmzV2X3JDtNwr9G4GSPACHK2JgqbveWNg@mail.gmail.com> <21217.1563135783@sss.pgh.pa.us>
* 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