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 1ubf0w-003eXV-C0 for pgsql-general@arkaria.postgresql.org; Tue, 15 Jul 2025 12:44:06 +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 1ubf0u-001nVc-1D for pgsql-general@arkaria.postgresql.org; Tue, 15 Jul 2025 12:44:04 +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 1ubf0t-001nVU-Lg for pgsql-general@lists.postgresql.org; Tue, 15 Jul 2025 12:44:04 +0000 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1ubf0s-007sRu-0L for pgsql-general@lists.postgresql.org; Tue, 15 Jul 2025 12:44:03 +0000 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-60c01b983b6so1975411a12.0 for ; Tue, 15 Jul 2025 05:44:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1752583440; x=1753188240; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=1xPNcXkGTUOZ6BBwPiF+EpYoegVfL/bB6wXiMnrdSlE=; b=QvRUdWcQuM+rLQLY21qZH3VtR4VGWJdPkoOxFbbrhYIYaXe0kAUMCjuBAlcHT9HkVg /fnU/DybnsPeJNj7OSMVfR3+uoGQGIq8r+cimqhWy3D47QrAWQPyUCsEQ7EnYXKzYAvS etNukEOrnzjGAUuWbs2X1EGsFBIGCklFzgC6dcJvrP0UkgiAhHHH5se1sn5FWb8FQ5su Yx6K4o+P5XMWzk6D0V0FkD2r+RX19Hw9V0obEQXYdusHj3MonKF55Mt+2nbTRjs20/zW RrxkpgLauCrGXYJNlk/WwGkyOYWrSJhEU4ErnJdwpCtkHJ5InsAHU1bOqb3gXOMeFXIa DLSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752583440; x=1753188240; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=1xPNcXkGTUOZ6BBwPiF+EpYoegVfL/bB6wXiMnrdSlE=; b=eEuTGY/PlXnnm1J7gQW6+lTdq3Xd0sH8C7+D8IkHEvilvPiDESPKiWssmRaZwLm4Ii k0cfTT1C1OPJXCBjzGSvdP/9G5AOXK9PEGjhVhP9wjFQHXtkxiWvyfLyS7Hkza8fXbRf sRdrOLWiUes3cG0qiSkm38NmwiKTP1V7VYf4CMzxWtbGMcYsqYIADHUC+A9vATo1DGno 5+BL7DL5YecYoXbtkt2qBY44qLS4QpJS87Ba5Ptnvl1LfyG2vCZGeDhbF5yqkar9NYas OEJ5qToT4uLYdb2l6wbDdhqhvfesuFHCgLORW77vIgE2gV1tFQwEdsiU/X3eOsi2vTlp O1Eg== X-Forwarded-Encrypted: i=1; AJvYcCWLyrpg7ZzaTZhC8lwIavmbwCXdZldEKi2GmAq/k8TWSUPNWan2dsj8dsF6HLxQPwyVA71epKhJmlTYXR1K@lists.postgresql.org X-Gm-Message-State: AOJu0YxmhsM8KaD2CgeLnaEDgui5u5nzPUUK8n7cTTUfOAK1InSWsf4i sU5p1BUiupSGNUIJU7af8G88nOdHT9iNe9kGjtrsjwdMOp2GOMP4Q7LachRw6AhujuMKpfZqT3w JUgcV X-Gm-Gg: ASbGnct4rmC5Uvct9+v2LztPtvU+nLrK/fVWQde4B/urV1FnOq0CaEW/ItObScaiVnI D3nPhPnxO4P+qSKHhtIB+rzZy8viR5b7yWpwW2dg9aLbhrR5aUcGX0wCWN3XbrgEkV3s4c4j//a KOaslPprw/t+iy0pg8RCVWbsRPYEoLnIWsg6UUW2M2Kn6bOhoEsva85DDPcvG170y2QGPuhLqSE kjxhhZB6GDGw4gZB0eKkDBKUBbVAqBr6ZVY9NVD+LKd9IG+GhjLNYUmj1oEax4SyRzYqUYBOQG8 AZ2nqMXTrVHwXNgXn5JqslZ1acOc1tYcBJv5uvkNUvBzxLHTXnAYM76024K875PQp7MgiJP4mnO rKs7D4J+81maYpVTPDb/mhhdEntBTjbHy7bXTp//OAr6BOxK/Q6bH X-Google-Smtp-Source: AGHT+IFXFVreRmbxscTDCDm7m9/NW+Cwky4jagqMzcw04TXFKAZ7FgGCcDWHOYkUepmRJHbPRHIa7Q== X-Received: by 2002:a05:6402:40d6:b0:60c:3ecd:5140 with SMTP id 4fb4d7f45d1cf-61265cffe3bmr2897053a12.0.1752583440249; Tue, 15 Jul 2025 05:44:00 -0700 (PDT) Received: from laurenz.albe-K4N0CV00F97414D ([2001:871:260:6b34:b252:6ee9:4652:d1b4]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-611c979893dsm7305141a12.81.2025.07.15.05.43.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jul 2025 05:44:00 -0700 (PDT) Message-ID: Subject: Re: Regarding query optimisation (select for update) From: Laurenz Albe To: Durgamahesh Manne , pgsql-general Date: Tue, 15 Jul 2025 14:43:59 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2 (3.56.2-1.fc42) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 2025-07-15 at 15:40 +0530, Durgamahesh Manne wrote: > We are facing issues=C2=A0with slow running query=C2=A0 > =C2=A0 =C2=A0SELECT betid, versionid, betdata, processed, messagetime, cr= eatedat, updatedat > FROM praermabetdata where processed =3D 'false' > ORDER BY betid, versionid LIMIT 200 OFFSET 0 FOR UPDATE;=C2=A0=C2=A0 >=20 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0QUERY PLAN > -------------------------------------------------------------------------= ------------------------------------------------------- > =C2=A0Limit =C2=A0(cost=3D0.28..1.89 rows=3D1 width=3D78) > =C2=A0 =C2=A0-> =C2=A0LockRows =C2=A0(cost=3D0.28..1.89 rows=3D1 width=3D= 78) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0-> =C2=A0Index Scan using idx_praermabe= tdata_processed_betid_versionid on praermabetdata =C2=A0(cost=3D0.28..1.88 = rows=3D1 width=3D78) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Index Cond: (proce= ssed =3D false) >=20 > image.png >=20 > Do we have any alternative way to improve the performance? > Sometimes processed column use true as well as false=C2=A0 Please provide EXPLAIN (ANALYZE, BUFFERS) output and use "log_lock_waits" to see if you are hanging behind locks for a longer time. Yours, Laurenz Albe