Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gL6wM-0006xJ-U4 for pgsql-general@arkaria.postgresql.org; Fri, 09 Nov 2018 13:35:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gL6wL-0003XJ-C6 for pgsql-general@arkaria.postgresql.org; Fri, 09 Nov 2018 13:35:13 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gL6wK-0003X9-W4 for pgsql-general@lists.postgresql.org; Fri, 09 Nov 2018 13:35:13 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gL6wI-0007hI-Ga for pgsql-general@lists.postgresql.org; Fri, 09 Nov 2018 13:35:11 +0000 Received: from [192.168.127.1] (port=30178 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1gL6wF-000ACF-R1; Fri, 09 Nov 2018 13:35:07 +0000 Received: from [127.0.0.1] (port=30196 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1gL6wF-000AUx-3h; Fri, 09 Nov 2018 13:35:07 +0000 From: Andrew Gierth To: Lance Luvaul Cc: pgsql-general@lists.postgresql.org Subject: Re: Full list of operations that constitute a "maintenance" operation? In-Reply-To: (Lance Luvaul's message of "Fri, 9 Nov 2018 20:57:28 +1100") Message-ID: <87muqixvh0.fsf@news-spur.riddles.org.uk> References: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Fri, 09 Nov 2018 13:35:07 +0000 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Lance" == Lance Luvaul writes: Lance> Hi all, I've read on the Postgres documentation for Lance> 'maintenance_work_mem' that VACUUM, CREATE INDEX, and ALTER Lance> TABLE ADD FOREIGN KEY are considered maintenance operations, but Lance> are there others? For example I use ALTER TABLE ADD COLUMN and Lance> ALTER TABLE SET LOGGED in my scripts... are they maintenance Lance> operations that would cause a maintenance_work_mem-sized chunk Lance> of memory (or more than 1 such chunk) to be allocated? There are essentially two classes of operations that use maintenance_work_mem: 1. Specific operations: non-full VACUUM (for the deleted tid list), CLUSTER (for sorting the table content), ALTER ... ADD FOREIGN KEY (for the validation query, which might want to use sorts or a hashjoin). (It's not impossible, though it should be rare, for an FK validation to use two chunks of maintenance_work_mem - with the right table sizes and data types, the validation query could plan as a merge anti-join with explicit sorts on both sides.) 2. Anything that (re)builds an index for any reason. This includes a large set of operations: CREATE INDEX and REINDEX are obvious, likewise VACUUM FULL and CLUSTER, but also any form of ALTER TABLE that rewrites the heap (which _includes_ SET LOGGED, but does not include adding a column with no default, or in pg11+ adding a column with a default). It also includes non-concurrent refresh of a materialized view. (TRUNCATE also technically rewrites the table heap, but since the new heap is empty, memory consumption during reindex is not an issue.) ALTER TABLE to add a unique, primary key or exclusion constraint also creates an index to implement the constraint with (unless USING INDEX was used to adopt an existing index) so that counts too. -- Andrew (irc:RhodiumToad)