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 1tA0WJ-00DJLb-3a for pgsql-admin@arkaria.postgresql.org; Sun, 10 Nov 2024 05:29:54 +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 1tA0WE-005JGo-4R for pgsql-admin@arkaria.postgresql.org; Sun, 10 Nov 2024 05:29:50 +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 1tA0WD-005JGg-Oj for pgsql-admin@lists.postgresql.org; Sun, 10 Nov 2024 05:29:50 +0000 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tA0WA-0018id-4R for pgsql-admin@lists.postgresql.org; Sun, 10 Nov 2024 05:29:49 +0000 Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5cec93719ccso4698345a12.2 for ; Sat, 09 Nov 2024 21:29:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=cybertec.at; t=1731216586; x=1731821386; 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=iCBKe5VLUDoAKFbud7CmfHQ9ccIPdAmsW7urh91dM+Y=; b=UGsMaaRc0wxvClhhQvHxXrZj2l//RpMp6DBO3B3tClBKKHvB+fSAgNIY1x8NyNJpbT PmDvJpvz0JLyQQOqEfPbupoBmiZWbv4FYtkVYA0oPyP7/h5zn1+SRYkJCT6v61rQdPlt stDKtFXFr3M8uP+5W5M9iIpwuZ/Fv/MZXYKB8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731216586; x=1731821386; 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=iCBKe5VLUDoAKFbud7CmfHQ9ccIPdAmsW7urh91dM+Y=; b=aTYle0gZNS65c88cMbRvEmU3YSO2bP4YEiYyWIidbahATmU/RV+Po8FjjZIjvtEtyw l3QcvNEvoLXEyfB0B8ekXryXuCj2Efq3iaVgWDB5bLQGNDnbsK/Ww96rsZCPdII3tlTQ /i+XbmJ9rBTrMS+GCHf5G7Qo0eOnHNH0HnxA5vDhslrOmn1ugV6VMwPFM2XwG0WA7xeZ uersX8Gxpc109oKZCXfAlWmvHcjyzwQsKcie5/iIWsnLo70mtWGpwrFJ7JxvTEA7P2C3 lm//7OYlWqq4yX/3Qro0FsmahyEf+CwBQG+Ttxf9XocDariG93MpPmR4xSu15x2Tbx80 4S0g== X-Forwarded-Encrypted: i=1; AJvYcCW1YFQ1oKPCoJu8VBXVONQ+DIF33eHNe9/VD3F8i84cOHY2pRXnb+d52g2F8GrBy/b/3PkZEyG28rnfbQ==@lists.postgresql.org X-Gm-Message-State: AOJu0YwDuSU3Oh5Ye72ygSCtN4Bv/prIEdDI5rAfPbGGZXRG5iQCME4B R4GQcbQO/rJGpyhrGIdryAqsGJFO3D8RoVdsL0WwUnDmsw9Ri8624FV+0BcwsKQ= X-Google-Smtp-Source: AGHT+IFrk0mRrd3VXR6FjBR5XHCDT0bqoCYP3fJ6Ark2Btz1lYOmJZFnTBx//M3zKvT8xzdfOpouhA== X-Received: by 2002:a17:907:2d88:b0:a9a:c769:5a5 with SMTP id a640c23a62f3a-a9ef001c666mr724806566b.50.1731216586211; Sat, 09 Nov 2024 21:29:46 -0800 (PST) Received: from localhost.localdomain ([2001:871:260:b7b5:bac4:89e2:bfd8:89ea]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9ee0dc5234sm444639766b.124.2024.11.09.21.29.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Nov 2024 21:29:45 -0800 (PST) Message-ID: <6af4a50d5a942117f2c76add61c37d2a55810a3f.camel@cybertec.at> Subject: Re: How to check if session is a hung thread/session From: Laurenz Albe To: Edwin UY , "pgsql-admin@lists.postgresql.org" Date: Sun, 10 Nov 2024 06:29:44 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.4 (3.52.4-2.fc40) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, 2024-11-10 at 10:25 +1300, Edwin UY wrote: > I am not sure how to explain this, but I believe this is something usuall= y referred to in the JDBC world as a hung thread. >=20 > This is an Aurora RDS PostgreSQL database that was patched in a supposed = to be zero downtime kind of thing. > After the patching, I have a user complaining that he has a job that norm= ally gets run in the OS cron session that has been failing. >=20 > Checking pg_stat_activity >=20 > select pid as process_id, > =C2=A0 =C2=A0 =C2=A0 =C2=A0usename as username, > =C2=A0 =C2=A0 =C2=A0 =C2=A0datname as database_name, > =C2=A0 =C2=A0 =C2=A0 =C2=A0client_addr as client_address, > =C2=A0 =C2=A0 =C2=A0 =C2=A0application_name, > =C2=A0 =C2=A0 =C2=A0 =C2=A0now() - pg_stat_activity.query_start AS durati= on, > =C2=A0 =C2=A0 =C2=A0 =C2=A0backend_start, > =C2=A0 =C2=A0 =C2=A0 =C2=A0backend_start at time zone 'Pacific/Auckland' = as backend_start_localtime, > =C2=A0 =C2=A0 =C2=A0 =C2=A0state, > =C2=A0 =C2=A0 =C2=A0 =C2=A0state_change, > =C2=A0 =C2=A0 =C2=A0 =C2=A0state_change at time zone 'Pacific/Auckland' a= s state_change_localtime > from pg_stat_activity > where usename =3D '[blah]' > order by username asc >=20 > I have the output as below: >=20 > =C2=A0process_id | username =C2=A0| database_name | client_address | =C2= =A0 =C2=A0application_name =C2=A0 =C2=A0| =C2=A0 =C2=A0duration =C2=A0 =C2= =A0 | =C2=A0 =C2=A0 =C2=A0 =C2=A0 backend_start =C2=A0 =C2=A0 =C2=A0 =C2=A0= | =C2=A0backend_start_localtime =C2=A0 | state | =C2=A0 =C2=A0 =C2=A0 =C2= =A0 state_change =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 state_change_lo= caltime > ------------+-----------+---------------+----------------+---------------= ---------+-----------------+-------------------------------+---------------= -------------+-------+-------------------------------+---------------------= ------- > =C2=A0 =C2=A0 =C2=A0 31947 | [blah] | [blah] =C2=A0 =C2=A0 =C2=A0 =C2=A0 = | [blah] =C2=A0=C2=A0 | PostgreSQL JDBC Driver | 00:47:21.838892 | 2024-11-= 06 10:44:53.309388+00 | 2024-11-06 23:44:53.309388 | idle =C2=A0| 2024-11-0= 8 02:00:06.005173+00 | 2024-11-08 15:00:06.005173 > (1 row) >=20 > From the pg_stat_output, the backend_start has not changed for several da= ys since the patching, so I am 'guessing' > it may have gone lost/rogue already. Is there any way to check that this = is the case before I kill it. > The state_change date is getting updated though, I don't know if this is = proof that it is not a hung thread. You should look at the "state_change" column for the session to see how lon= g it has been idle. At any rate, an idle session is not hanging - at least not in the database.= Perhaps you got the wrong session, or perhaps the client has got a problem. I'd say that killing the session won't resolve any hanging thread on the cl= ient side. Still, if you kill it, you'd at worst cause an error on the client side. Yours, Laurenz Albe