Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hz2ZP-0003AC-EB for pgsql-general@arkaria.postgresql.org; Sat, 17 Aug 2019 17:32:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hz2ZO-00060L-3s for pgsql-general@arkaria.postgresql.org; Sat, 17 Aug 2019 17:32:50 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hz2ZN-0005zq-Mt for pgsql-general@lists.postgresql.org; Sat, 17 Aug 2019 17:32:49 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1hz2ZG-0005yQ-Mm for pgsql-general@postgresql.org; Sat, 17 Aug 2019 17:32:48 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 234C420D56; Sat, 17 Aug 2019 13:32:42 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Sat, 17 Aug 2019 13:32:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=C pWH+tkPcLQNrbOvPDaHSB5JFQFr3VhbzpREGBYPC5I=; b=Ot9/1PirV0ZSnZ5TR 4cfbsfu4yan/L2Rm5X+RkOuGJmBLynZoUHqDIIcQkYakECJEfK2cbT3U8SUEwlyF QoxYSpdgWHjdVir9NCMs2IgualNDWJD0XrmQCfpadUA1Rn/6q4Y7mGbSWieipW/+ FVQRm/BDEV4zeDVCvPWRGkNNdd7qp4wtnvBqNprBhwvUk2peLH0I/7ZLVOuVSnCz lGfmuU9dJjZOd8q/xBTlSSi/VflC52wozLVGWTLCxq8fiN6c+2aGqqAaGsK5UCio Y34UL7E7jyKt/QKPAbInrqTMJ+fsj0I3/zZv+hqTYrOrIPRUAXsebPmvKuLdcPVE aAyTQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=CpWH+tkPcLQNrbOvPDaHSB5JFQFr3VhbzpREGBYPC 5I=; b=FwZ5Kh+LnJFHDpFUMLZusEVNb+O1tMNmR3aA8bNIbg7ogh6vpCl5yt19/ OIOaVd9EOhtmdkz9B7gh2OFEbranwZKL/ol9B0mzj7Eb0c+yL4o0AxNTROpBkb2a c4LzBFeaVsNKabenxkmsBu13gYxfHv6tkweTiefIhRjkjrWoNaPy5xIlpvs1FGLS QUjsEpHSCQKbtQBca7G+iJKOgJG7xJ8Oe9Spucj2+7c1g915qYVtKnRPLvnqsLUc 6RjoXPjnP/pppJp0BVQwRaXLYB/9vvNlwAAouCg4tPEK1LKlGKvu9hJR9BL0kjsM 5wfEhAXHPeV9B/gcwuuXab+fgMgag== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrudefhedgudduiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefuvfhfhffkffgfgggjtgfgsehtjeertddtfeejnecuhfhrohhmpeetughr ihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtg homheqnecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrghenucfkphepjedurddv uddvrdduhedtrddvtddvnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkh hlrghvvghrsegrkhhlrghvvghrrdgtohhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from [192.168.1.4] (unknown [71.212.150.202]) by mail.messagingengine.com (Postfix) with ESMTPA id 79B6980059; Sat, 17 Aug 2019 13:32:41 -0400 (EDT) Subject: Re: Unexpected "canceling statement due to user request" error To: Will Storey , pgsql-general@postgresql.org References: <20190816210243.tohrx52bnbxx5zra@dev.null> From: Adrian Klaver Message-ID: <34a5ea6d-8dbb-e46a-0c08-fbbea4d4bcd7@aklaver.com> Date: Sat, 17 Aug 2019 10:32:40 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20190816210243.tohrx52bnbxx5zra@dev.null> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 8/16/19 2:02 PM, Will Storey wrote: > Hi! > > I have a query that fails due to this error and I'm trying to understand > why. > > My understanding is I should only see this error if I cancel a query > manually, such as with kill -INT or with pg_cancel_backend(). However I > can't find anything doing that. > > The query looks like this: > > SELECT * > FROM ( > SELECT > c1, c2, [...], > EXTRACT(EPOCH FROM time) AS epoch, > to_rfc3339_us(time) AS time_rfc3339 > FROM t1 > WHERE > NOT EXISTS (SELECT 1 FROM t2 WHERE c2 = ?) AND > c2 = ? AND > time < ? AND > time > ?::timestamptz - ? * interval '1 day' > LIMIT ? > ) AS s > ORDER BY epoch DESC > > t1 is partitioned on time, by month. > > I run it using Perl's DBI with DBD::Pg. I wrap it in a transaction where I > first run: > > SET LOCAL statement_timeout TO 1000 > > I know this query can time out, and it does, resulting in the error I > expect: "canceling statement due to statement timeout". The problem is > occasionally I see this other error: "canceling statement due to user > request". > > Looking at the query logs, when the query fails with the user request > error, the query reached the statement timeout (at least in cases I > checked). In one instance the duration shows as 1283ms for example. > > Could there be any situation where a query getting cancelled due to a > statement timeout be reported as cancelled due to user request? Or do you > have any ideas about what might be going on? Here is the relevant source: https://doxygen.postgresql.org/postgres_8c.html#ab7af3ee6ad40efb8454c6f2f790d9588 Start at around line 3078. > > This is on PostgreSQL 9.6.14 on Ubuntu Xenial. > > Thank you! > > > -- Adrian Klaver adrian.klaver@aklaver.com