Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qri1k-005XlA-66 for pgsql-bugs@arkaria.postgresql.org; Sat, 14 Oct 2023 17:02:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qri1h-007rcv-0G for pgsql-bugs@arkaria.postgresql.org; Sat, 14 Oct 2023 17:02:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qri1g-007rcm-Iz for pgsql-bugs@lists.postgresql.org; Sat, 14 Oct 2023 17:02:09 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qri1a-000TDz-KQ for pgsql-bugs@lists.postgresql.org; Sat, 14 Oct 2023 17:02:08 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 39EH211g1766110; Sat, 14 Oct 2023 13:02:01 -0400 From: Tom Lane To: Erki Eessaar cc: "pgsql-bugs@lists.postgresql.org" Subject: Re: System administration functions about relation size ignore changes in the table structure In-reply-to: References: Comments: In-reply-to Erki Eessaar message dated "Sat, 14 Oct 2023 09:30:48 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1766108.1697302921.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 14 Oct 2023 13:02:01 -0400 Message-ID: <1766109.1697302921@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Erki Eessaar writes: > According to the example at the end of the letter the functions pg_total= _relation_size, pg_table_size and pg_indexes_size seem to ignore adding o= r removing columns from a table. I don't think this is a bug, it's more like a poor test case designed with no understanding of Postgres internals. 1. Dropping a column doesn't ever produce an instantaneous reduction of table size. The column is still there physically. We'll replace it with NULLs over time as existing rows are updated. 2. Adding a column may not cause an instantaneous increase in size either, if we can avoid an immediate table rewrite; which is true if the column has a null or constant default value. 3. Even for your example with adding a generated column, you would only see an increase in table size if we could now fit fewer rows per page than before. Your test case seems to involve comparing a table with 3 integer-size columns to one with 3 integers and 2 smallints. On 64-bit machines those come out to the same size (16 data bytes per row) because the row length is padded to a multiple of 8 bytes for alignment reasons. regards, tom lane