Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ePVCB-0007jq-Ns for pgsql-general@arkaria.postgresql.org; Thu, 14 Dec 2017 15:13:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ePVCA-0002jb-Pg for pgsql-general@arkaria.postgresql.org; Thu, 14 Dec 2017 15:13:10 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ePVCA-0002Vq-FF for pgsql-general@lists.postgresql.org; Thu, 14 Dec 2017 15:13:10 +0000 Received: from tamriel.snowman.net ([2001:470:e38f::11]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ePVC6-0006kN-O6 for pgsql-general@lists.postgresql.org; Thu, 14 Dec 2017 15:13:09 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 5EB345F795; Thu, 14 Dec 2017 10:13:05 -0500 (EST) Date: Thu, 14 Dec 2017 10:13:05 -0500 From: Stephen Frost To: Nicola Contu Cc: Rene Romero Benavides , pgsql-general@lists.postgresql.org, Alessandro.aste@gtt.net Subject: Re: pgstattuple free_percent to high Message-ID: <20171214151305.GY4628@tamriel.snowman.net> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="Mn2+qEYm1PCNU0p9" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Mn2+qEYm1PCNU0p9 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Greetings Nicola, * Nicola Contu (nicola.contu@gmail.com) wrote: > I think tuning the autovacuum settings may increase performances and remove > dead_tuples but as far as I know, the autovacuum runs a vacuum analyze. > The vacuum analyze won't touch the free_percent of the table. That's not entirely accurate. If all of the free space is at the *end* of the relation then autovacuum will attempt to lock the relation and truncate the table to give that free space back to the OS. On a table where all of the rows are regularly updated, eventually the "live" data should end up towards the front of the relation and the end of the relation will be all dead tuples, allowing the truncate to happen. If you have tuples at the end of the relation that aren't ever updated but they're "live" then we won't be able to truncate. The pg_freespacemap extension can be useful to see where the free space is in the relation. There are a few tools out there that aren't part of core PostgreSQL that you could consider using such as pg_repack and pg_squeeze. > So I'm trying to find a way to adjust the free percent for some tables > without doing a manually full vacuum. > We are now monitoring the free percent, so we may find the part of the code > that can increase that value, but was wondering if there is anything on the > postgres side to resolve this problem. Having some free space in the relation isn't a 'problem' and is a good thing because it means that new rows (from either INSERTs or UPDATEs) have a place to go that doesn't require extending the relation (which requires an additional lock as well as some additional work). As for how much free space is good to have and how much is too much depends on the specific workload. Thanks! Stephen --Mn2+qEYm1PCNU0p9 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJaMpUBAAoJEO1sijiDR2RV7oIP/1EtRoT1+IArt/nQa9p2tZzM A+OCL2arPpvawO1tdBc/kFvwMbT00y1zz5M04I48vBTACu5aIhn6nqNU/V+TWyF+ 9xWVLsC4aHa12X2vkOh2JcaUdsmEchHZMkNaVl2oRYA27aEaX3xrwpaVPfvJ94r0 YmJDAFHgvOZnAnnprBXJ8fTD/p7+Vq6aAAFFmCtZEQVDrSSC2Mp+1pEcuZs7p1rD eq4M4Cv1XEA8AJB7MRUDRxmBC6m/u03ZROp89ZctrxKx+vYIZqjJ5c4jCTLgYT53 KBqEY4phsGwh7AZ94STaf4mR4WmB5QAGv8X1OBVpyUYW/ahUyWby4Lz4BJWyzOXW yM6t+rK+V4Bz8AJUQPsnm6hXoauNX00300WJss5mUPIifRHubqcriyQ2vAlLCVeh 8Pd8beBDEZX6NfyVQ1KkYFQtpjrBzGKiTUEMlS/KG7Io8aBzCkScyUyGsbBtxnt1 VkoSivH3RYPcZBU1LZNrOkGcOUr8q3a6PabHASuNASU9QtFgbGfS2P7YA93TbqWg JEMAgOmtic73e3yYY85LdsqzbVNRevEKP2J7cfhgkNBKi7PMeljxJoVIYgj2jfiE McK8U9LgV/yZLSB4QO/obtWcby1/foB6TnGxfTPU1OE8etVUE3vVPL2T47wHO9Lt Bp9R/TeI5fmPPKu5T3fa =Bczf -----END PGP SIGNATURE----- --Mn2+qEYm1PCNU0p9--