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 1sRV1X-00FovF-EF for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Jul 2024 10:58: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 1sRV1W-003l4L-3q for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Jul 2024 10:58:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sRV1V-003l4D-Ol for pgsql-hackers@lists.postgresql.org; Wed, 10 Jul 2024 10:58:09 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sRV1O-001NOq-CI for pgsql-hackers@postgresql.org; Wed, 10 Jul 2024 10:58:08 +0000 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-426636ef8c9so23466905e9.2 for ; Wed, 10 Jul 2024 03:58:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1720609080; x=1721213880; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=k3EzY3vlnh74BfYuceRJcxxFr22ZnayjpKvo8Jkb5ic=; b=aKghLtPc+8jgs9RNfWIzdUdHkQBUFvBsqsov+WaaRmiE5WQMRd3BlxyMnpd7UtShH7 So2VQsu9hRn9qgZJXGGTEs0AvfG+D34/38Qy6gkJmi/iqFVLkdep4kzwu0fiR9fWcyq+ SIOgjXvuKE9nXqdBTfQ4a/UNRXFiG3QPxrpBRKVaAJMm+Y6BQKZe49OAkTBgBLHl5uKZ 6h29NeVtQDM3IZtTjRDhLRxZHlyeV7EUpTLlJ2kZ9YY7Ellw2GHt7tNFm20zbS/rOodn zHaXQpDE3OWGF8Z0KLJJWwTgsUJTYZtViH7S0G7CbHoMCYyeiF5qQZY0zfdXkLZExd2e EBEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720609080; x=1721213880; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=k3EzY3vlnh74BfYuceRJcxxFr22ZnayjpKvo8Jkb5ic=; b=YiePkfXrXmxigZjnlD140xVHzALTLynLjZ1NZ+ZGWEqySI5sys9raA9KesidZ+tcdX ejyOe98YEZ0WOGwHFNtaTCnTtoxRq9E+9d1ljqAKZ2ql0tVvZpsfZLBp9G+XuSukcESr Q8UHKzmRvhSEiBsM1e9COTClCTTfl5DqbV2DyWFA0u173hwShp8GTJcIllUFoh28ipCb dx5rhyB2xCpUr0j/eDsrXi3mwyUXNUMH3pM23w70uOp4Jx5yWIKkUg/E6dbDnJLDLMnR aC2QwUBDPgax9xm87rLM3g1nh9TNaOoie2HtOckJ9KpIpie+zDpLXVyRzgLOA4tnhvzv G6Ow== X-Gm-Message-State: AOJu0YwbiSlnBE3uzysXp8B/vbl38RpUHwmGNXc/cuQQJnjLbbqbohY2 GV4D/w3U57IfO0bAR2IddUMfTdUF043j9y4qn+Wz9A1TC+UjhqZxOavsl1NZ6Q== X-Google-Smtp-Source: AGHT+IEWnbhixvgxDFaVG+lB/JaMmS7jXGOTqOJdDMgITXIbXU1U0B6H0zriSWYm0R1r9Ol87TmsOQ== X-Received: by 2002:a05:600c:28b:b0:426:6f81:d235 with SMTP id 5b1f17b1804b1-426707d9c3dmr40635825e9.15.1720609080186; Wed, 10 Jul 2024 03:58:00 -0700 (PDT) Received: from [10.137.0.18] (ip-86-49-229-30.bb.vodafone.cz. [86.49.229.30]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-367cde89133sm5043434f8f.54.2024.07.10.03.57.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 10 Jul 2024 03:57:59 -0700 (PDT) Message-ID: <4a18060c-8ba8-43df-b400-bfa20c88d020@enterprisedb.com> Date: Wed, 10 Jul 2024 12:57:53 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Lock-free compaction. Why not? To: David Rowley , Ahmed Yarub Hani Al Nuaimi Cc: Pg Hackers References: Content-Language: en-US From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/10/24 11:49, David Rowley wrote: > On Tue, 9 Jul 2024 at 16:58, Ahmed Yarub Hani Al Nuaimi > wrote: >> The thing is, after reading the code a million times, I still don't understand why lock-free (or minimum locking) is such a big problem! Is it that hard to lazily move tuples from one page to the other after defragmenting it lazily? > > I think there are a few things to think about. You may have thought of > some of these already. > > 1. moving rows could cause deadlocking issues. Users might struggle to > accept that some background process is causing their transaction to > rollback. > 2. transaction size: How large to make the batches of tuples to move > at once? One transaction sounds much more prone to deadlocking. > 3. xid consumption. Doing lots of small transactions to move tuples > could consume lots of xids. > 4. moving tuples around to other pages needs indexes to be updated and > could cause index bloat. > > For #1, maybe there's something that can be done to ensure it's always > vacuum that's the deadlock victim. > > You might be interested in [1]. There's also an older discussion in > [2] that you might find interesting. > IIRC long time ago VACUUM FULL actually worked in a similar way, i.e. by moving rows around. I'm not sure if it did the lock-free thing as proposed here (probably not), but I guess at least some of the reasons why it was replaced by CLUSTER would still apply to this new thing. Maybe it's a good trade off for some use cases (after all, people do that using pg_repack/pg_squeeze/... so it clearly has value for them), but it'd be a bit unfortunate to rediscover those old issues later. The cluster vacuum was introduced by commit 946cf229e89 in 2010, and then the "inplace" variant was removed by 0a469c87692 shortly after. I haven't looked for the threads discussing those changes, but I guess it should not be hard to find in the archives. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company