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 1rjQ0w-005RN7-10 for pgsql-bugs@arkaria.postgresql.org; Sun, 10 Mar 2024 20:43:22 +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 1rjQ0t-006Kj0-Te for pgsql-bugs@arkaria.postgresql.org; Sun, 10 Mar 2024 20:43:20 +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 1rjQ0t-006Kir-LS for pgsql-bugs@lists.postgresql.org; Sun, 10 Mar 2024 20:43:20 +0000 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rjQ0o-003oN0-CU for pgsql-bugs@lists.postgresql.org; Sun, 10 Mar 2024 20:43:18 +0000 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a44d084bfe1so288882466b.1 for ; Sun, 10 Mar 2024 13:43:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1710103393; x=1710708193; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=DaLeC3jix5Ly0xBTKkYto/3UyZmZSGUobyhfCLrofGs=; b=i6JE27S7mcVR3rO5SmiwP1Ccn39aDIDjyRrc+4KAaWSbqzSbFRO9nSz+IvVHLvbEHh lQq6RBwsAO4uWD1OX/WirYV0k8h2foJNWp16HfVHdCclt3Pz9WliNeQ1g9Rksjt/QkSr cqmNAWFrgt/AGrOVRdUIwlPoxLFZaSHk5houazHVUYuydd4YxzHq5mFgYZWHoUx7BTJm MRlMOKwqNyZyDwJunRaDxBkICxReY87Uy78HrH24tOZeZxElXdQf3ol5TS7EMR6yAEkG mhdzYESnXez+lsVAK8/h5i3KLy8hZmPF5NnPNmQJ2fN9DbtjqNrAuw1sJrwI6QEmIH4L JWrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710103393; x=1710708193; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DaLeC3jix5Ly0xBTKkYto/3UyZmZSGUobyhfCLrofGs=; b=uIqOfMAnZPzAVHZ7CqkOThutzY/iPbjhyJfsyMG2k2T5CDcbmH2ddtK5vceKRvan6y 4JB9RTiLdofNwpJmJl+Zq5Exz/dJW5Jy+CDJtb1k8+JlFQSxkTyny9dSu+MZpjbhkZZm JEUTe4AjzobQ2Ge8kTngsYPSlsyWGlvAkZBXkxN8c5nmkf6tRsJ9wLj8ZIbZ+0rA4Kf9 q/1QKFNhUIkkKU59h9EHtyRacqizRE/16uPGtGbdAujcPvETBApEuWuek5VMC0PbdS5/ aX9Jv09cml5cQUUtyBWL5JIpu4Vn5MuoBbYZPlux1APum+cBTOMygqxBTtz2TqAJCoyt bUCA== X-Forwarded-Encrypted: i=1; AJvYcCU6xCBh+xao5eSqddCsgbCZSsq8UWSWp5fqCh1HfJWG3bDrMEXFNYfHEd22sEa55s4Z+v6w+DZmrW/Skv2MsatzG+s9oL9QF/B4/UROOl8+ X-Gm-Message-State: AOJu0YyExSH340ncZRmQvMiNYSQKK3uqHMwA89Ei7pbw1bH/26M3Spfu xoH2g03qMbMWPD+v6KGqw1e8CWQvNFq5i+25aLNma4rL9xcO1bo/o3l7pGpiEQ== X-Google-Smtp-Source: AGHT+IHeldI0fEOUKw1KOS/CaRGBI/Ni7G1ApRpvbgADKw/+iCT7Lf2StgI2BUIWx6tNwb0lV5yFoQ== X-Received: by 2002:a17:906:13d5:b0:a44:2636:9965 with SMTP id g21-20020a17090613d500b00a4426369965mr2808239ejc.29.1710103392839; Sun, 10 Mar 2024 13:43:12 -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 k5-20020a170906578500b00a449ebf3d58sm2184467ejq.85.2024.03.10.13.43.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 10 Mar 2024 13:43:12 -0700 (PDT) Message-ID: Date: Sun, 10 Mar 2024 21:43:11 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Undetected deadlock between client backend and startup processes on a standby (Previously, Undetected deadlock between primary and standby processes) Content-Language: en-US To: Rintaro.Ikeda@nttdata.com, pgsql-bugs@lists.postgresql.org References: 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 3/4/24 09:35, Rintaro.Ikeda@nttdata.com wrote: > Hi, > > I correct the previous bug report [1] to provide a more accurate > description. The bug report demonstrated undetected deadlock between > client backend and startup processes on a standby server. (The title > in the previous bug report is "Undetected deadlock between primary > and standby processes". But this was wrong. Actually, this should be > noted that "Undetected deadlock between client backend and startup > process on a standby server".) > > After the procedures proposed in my bug report [1], a recovery > conflict is present because the tablespace which startup process > tries to drop is used by cliend backend process in standby. We see > the pg_stat_activity (shown below), which implies a deadlock. A > client backend process waits for AccessExclusiveLock to be released. > Startup process waits for recovery conflict resolution for dropping > the tablespace. This deadlock is not resolved after deadlock_timeout > passes. > > (Standby server) > postgres=# select datid, datname, wait_event_type, wait_event, query, backend_type from pg_stat_activity ; > datid | datname | wait_event_type | wait_event | query | backend_type > -------+----------+-----------------+----------------------------+-------------------------------------------------------------------------------------------------+------------------- > 5 | postgres | Lock | relation | SELECT * FROM t; | client backend > | | IPC | RecoveryConflictTablespace | | startup > > > This deadlock is similar to the previously identified and patched > issue [2], which also involved an undetected deadlock between > backend process and recovery on a standby server. I think the > deadlock explained in this report should be detected and resolved. > Thanks for the report. So what are the steps to reproduce this? The previous message did all kinds of stuff on the primary and then got stuck on pg_switch_wal() on the primary, but this updated seems to do stuff on the standby and gets the lockup there. It seems similar in the sense that it's about interaction between recovery and a regular backend, but unfortunately ResolveRecoveryConflictWithVirtualXIDs does not wait for a lock, it just checks if the XID is still running, so it's invisible to the deadlock detector :-( But it's still checked against max_standby_streaming_delay, which should resolve the deadlock (unless set to -1 to allow infinite delays) at some point, right? Also, I'm not very familiar with ResolveRecoveryConflictWithVirtualXIDs, but it seems it's doing a busy wait. I wonder if that's a good idea, but it's independent of this bug report. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company