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 1hEcPR-0004Io-Gs for pgsql-general@arkaria.postgresql.org; Thu, 11 Apr 2019 16:18: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 1hEcPQ-0003EC-6J for pgsql-general@arkaria.postgresql.org; Thu, 11 Apr 2019 16:18:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hEcPP-0003AA-Jv for pgsql-general@lists.postgresql.org; Thu, 11 Apr 2019 16:18:39 +0000 Received: from smtp58.i.mail.ru ([217.69.128.38]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hEcPM-0001H8-9q for pgsql-general@postgresql.org; Thu, 11 Apr 2019 16:18:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail2; h=Content-Type:In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject; bh=tFiLLG8AiA8mVvOEuN7nHjPtOHVXGhFYJCNV1xJ2cxM=; b=X7WiazZx9SiK1m3d8UaBFB0Yl6kuzBaKTUOs6225w9gPHZ6rk6pxsb5Uzl/tTX/lY9rG/n5LMWyRV9kEnAqdJslfj7jv9U6KozwWVgvrdLAv2yUobSi+dibeQsPSZOcqjq5z6uMWgEf0YDTGR0bYqoLpZKOUhUjCzZd5tQz7Es8=; Received: by smtp58.i.mail.ru with esmtpa (envelope-from ) id 1hEcPK-0003zB-95; Thu, 11 Apr 2019 19:18:34 +0300 Subject: Re: When do vacuumed pages/tuples become available for reuse? To: Jeff Janes Cc: Tom Lane , pgsql-general General 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> From: rihad Message-ID: <44a10837-648b-7cc9-d42a-146bc0c83574@mail.ru> Date: Thu, 11 Apr 2019 20:18:32 +0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------5DDC84534E618EDD2778ED9D" Content-Language: en-US Authentication-Results: smtp58.i.mail.ru; auth=pass smtp.auth=rihad@mail.ru smtp.mailfrom=rihad@mail.ru X-77F55803: 689590B63E0A4B015A78504BD2AC29416CDE1282D82D8196403550BAD6E37000A36A0B55C312A8C71EAAE72A7F0B2679 X-7FA49CB5: 0D63561A33F958A59EE02AF141AC96F76B274C3D86DEA1CDA4D2052C2575E1C58941B15DA834481FA18204E546F3947CEDCF5861DED71B2F389733CBF5DBD5E9C8A9BA7A39EFB7666BA297DBC24807EA117882F44604297287769387670735209ECD01F8117BC8BEA471835C12D1D977C4224003CC8364767815B9869FA544D8D32BA5DBAC0009BE9E8FC8737B5C2249CDE59DDCCE53AF2B3AA81AA40904B5D9CF19DD082D7633A0BCA8734010DFDAB0D81D268191BDAD3D78DA827A17800CE76888F6138A55F47ECD04E86FAF290E2D26E476CCD9869EB175ECD9A6C639B01B78DA827A17800CE7CA8FE9899DCBC7A1A32D675A3C3AA06975ECD9A6C639B01B4E70A05D1297E1BBC6867C52282FAC8519DC0BE04022C72727F269C8F02392CD5571747095F342E88FB05168BE4CE3AF X-Mailru-Sender: B19AB4DAF1EA2FB518D2771EFF7BC99A494D81D091E982174D9BBBC01D3118E41BE96DBAF4D557C5108F17C94788D7333DDE9B364B0DF2891F953FB4A677E77772D6B4FCE48DF648AE208404248635DF X-Mras: OK List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------5DDC84534E618EDD2778ED9D Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 04/11/2019 08:09 PM, Jeff Janes wrote: > On Thu, Apr 11, 2019 at 11:44 AM rihad > wrote: > > On 04/11/2019 07:40 PM, Jeff Janes wrote: >> >> The disk usage doesn't reach a steady state after one or two >> autovacs?  Or it does, but you are just unhappy about the ratio >> between the steady state size and the theoretical fully packed size? >> >> Cheers, >> >> Jeff > > > 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 > (Indeed, those dumps you take daily might be the source of those > long-lived snapshots.  How long does a dump take?) The daily dumps are taken daily from the slave server as part of stock FreeBSD postgres port activity. I don't think it impacts the master server. > > 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). > Cheers, > > Jeff --------------5DDC84534E618EDD2778ED9D Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
On 04/11/2019 08:09 PM, Jeff Janes wrote:
On Thu, Apr 11, 2019 at 11:44 AM rihad <rihad@mail.ru> wrote:
On 04/11/2019 07:40 PM, Jeff Janes wrote:

The disk usage doesn't reach a steady state after one or two autovacs?  Or it does, but you are just unhappy about the ratio between the steady state size and the theoretical fully packed size?

Cheers,

Jeff


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


(Indeed, those dumps you take daily might be the source of those long-lived snapshots.  How long does a dump take?)

The daily dumps are taken daily from the slave server as part of stock FreeBSD postgres port activity.
I don't think it impacts the master server.


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).

Cheers,

Jeff


--------------5DDC84534E618EDD2778ED9D--