Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ob1on-0008Nx-MI for pgsql-general@arkaria.postgresql.org; Wed, 21 Sep 2022 15:39:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ob1om-0001gT-7w for pgsql-general@arkaria.postgresql.org; Wed, 21 Sep 2022 15:39:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ob1ol-0001gK-Rg for pgsql-general@lists.postgresql.org; Wed, 21 Sep 2022 15:39:19 +0000 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ob1oj-00064J-F2 for pgsql-general@postgresql.org; Wed, 21 Sep 2022 15:39:19 +0000 Received: by mail-pg1-x52e.google.com with SMTP id bh13so6328227pgb.4 for ; Wed, 21 Sep 2022 08:39:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date; bh=WVqQnFXh0yb55MKMBYzk5AED/7DZ2tnGtxug1msjXyw=; b=GPYqS1eSDvD/wJj2PMDGvxZvNjvfkjV6YvWNKg4Os3IPPjs/NalhiPoologYqWDJ/b c1zNDSJ29VQ+ueLVmHpLF77wPIgYy1dZUxrPYVA5Ev0u1lTOvmbNm5I1l1W5mobvxxSt tivUaB1sNI3C/WP2cFjGw+3YSJDtzRWmI3BlwNBvr3ZL5DALTpUJN5RY3YKFlZ2DlxeB FgyTrKA5lG/+p1yyVCbjyfg2EFeB/BKatVQz1n9wz/YrTnvWos+T5LU5Pu/f8uUfWh3P vkdKjdzmtutdVfQnHzWXBIxzW/F7Xp47oUKikKLYTDB31/TN3fnYTeVeLM780KpHgOd0 G+5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date; bh=WVqQnFXh0yb55MKMBYzk5AED/7DZ2tnGtxug1msjXyw=; b=h3rcebMEYPwJs0B/weh2UC0MSHZ7PjSExmcXASwh37ImUVSwbnuVum94gUj6drPzkh 1fovr5+1tDPNuBOj8jZ4rwsyZUu4I9WuyivOs+W6x9bqMzcU21mfjKYU1ulml8kX9EXt L338C44tHE8lumvOUrbdZOoKnffguwHCDzqTlwNtfadPzgGfSdw55on9dkVaDo7R8jtV jHnVfyGzAdaZBxJlaGFKYk0uliDPndVT1YxHYhiZDP5gEpMr2iPZFRFDeXIfyEP6sqgk 5JvDJ+bL6Kb+liiGUMBk1903LJSTpQJdAYluObTLv2Ph8djwm8FsGrLFxueh3aRYYkBx ruEA== X-Gm-Message-State: ACrzQf0Drdr+M9OWFYN1cVj/Elb+YyDKaoUmmyZDopdh53O4dZonZuhH ii+mrdhckiteePpRvFHWOZs= X-Google-Smtp-Source: AMsMyM6O96pct/pUzUFv5MCRJMkMtfJFQ/Q6afUiqngT33+dGGdooP/Zjquvkq/jQQ30GHjUbCnbbw== X-Received: by 2002:a63:6a85:0:b0:43b:dac2:ff0b with SMTP id f127-20020a636a85000000b0043bdac2ff0bmr6018076pgc.234.1663774754658; Wed, 21 Sep 2022 08:39:14 -0700 (PDT) Received: from smtpclient.apple ([76.140.27.218]) by smtp.gmail.com with ESMTPSA id t18-20020a170902e85200b00172bf229dfdsm2293082plg.97.2022.09.21.08.39.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Sep 2022 08:39:14 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Re: [EXT] pg_stat_activity.backend_xmin From: Rob Sargent In-Reply-To: Date: Wed, 21 Sep 2022 09:39:11 -0600 Cc: Laurenz Albe , "pgsql-general@postgresql.org" , "Medarametla, Pavan (TR Technology)" Content-Transfer-Encoding: quoted-printable Message-Id: References: <73c8c16fbee732725f53e291002b694d15932516.camel@cybertec.at> To: "Dirschel, Steve" X-Mailer: Apple Mail (2.3654.120.0.1.13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Sep 21, 2022, at 9:32 AM, Dirschel, Steve = wrote: >=20 > On Wed, 2022-09-21 at 14:11 +0000, Dirschel, Steve wrote: >>> We are troubleshooting an issue where autovacuum is not cleaning up = a table. >>> The application using this database runs with autocommit turned off. >>> We can see in pg_stat_activity lots of sessions =E2=80=9Cidle in = transaction=E2=80=9D=20 >>> even though those sessions have not executed any DML- they have=20 >>> executed selects but no DML. The database=E2=80=99s isolation level = is set to read committed. >=20 >> "backend_xmin" is set when the session has an active snapshot. Such = a snapshot is held for the whole duration of a transaction in the = REPEATABLE READ isolation level, but there are cases where you can see = that in READ COMMITTED isolation level > as well: >>=20 >> - if there is a long running query >>=20 >> - if there is a cursor open >>=20 >> Perhaps you could ask your developers if they have long running = read-only transactions with cursors. >>=20 >> Yours, >> Laurenz Albe >=20 > Thanks for the reply Laurenz. For an application session in this = "state" pg_stat_activity shows the state of "idle in transaction" and = backend_xmin is populated. The query shows the last select query it = ran. It is not currently executing a query. And dev has said they are = not using a cursor for the query. So it does not appear they have long = running read-only transactions with cursors. >=20 > Outside that scenario can you think of any others where a session: > 1. Login to the database > 2. Set autocommit off > 3. Run select query, query completes, session does nothing after that = query completes. > 4. transaction isolation level is read committed >=20 > That session sitting there idle in transaction has backend_xmin = populated. When I run that test backend_xmin does not get populated = unless I set my transaction isolation level to repeatable read. We have = enabled statement logging so we can see if their sessions are changing = that transaction isolation level behind the scenes that they are not = aware of but so far we have not seen that type of command logged. >=20 > Regards > Steve What stack is the application using? Anything like Spring or Hibernate = involved?