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 1tg3zu-007Pzd-3c for pgsql-general@arkaria.postgresql.org; Thu, 06 Feb 2025 15:40:58 +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 1tg3zt-008n6C-38 for pgsql-general@arkaria.postgresql.org; Thu, 06 Feb 2025 15:40:57 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tg3zs-008n5y-L0 for pgsql-general@lists.postgresql.org; Thu, 06 Feb 2025 15:40:56 +0000 Received: from mail-qt1-x82f.google.com ([2607:f8b0:4864:20::82f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tg3zq-003YVS-0Q for pgsql-general@lists.postgresql.org; Thu, 06 Feb 2025 15:40:55 +0000 Received: by mail-qt1-x82f.google.com with SMTP id d75a77b69052e-46b1d40abbdso8993161cf.2 for ; Thu, 06 Feb 2025 07:40:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=princeton.edu; s=google; t=1738856453; x=1739461253; darn=lists.postgresql.org; h=to:message-id:subject:date:mime-version:from :content-transfer-encoding:from:to:cc:subject:date:message-id :reply-to; bh=h0VRy0IgePBDTFLiunEIc8h9t1nAYTA5Hyi9323QvKI=; b=OIb4Lz5YqYaegI9LtyxTiFafTnIFeHN4ELB/hWAcjAqebN+Wj2NRNSc5Tg1axizMKr w5q2XkN1zOv6ssEVflW8yv7EPq/C0KKBuFjVwLfT6ug853YSItc5bIxOWOaOhFjfc2Bq KAgAmOlMGzgTrdWDPIWnyH4M+uA0dwIGZzFlTChoLf4WXBRbMsPlRPr+FCUR0rWNa4hr sUyn4YtBDeDuzXlj/Yc1RBeOTAid/xNEhHwZTi8LhXYpji4VTXCiKZ+aRV0j2ptULS/5 I6FmC0dj77uEA0oJJ+Qa2eHImLeTEIwW/VnUki08HZl++hVMwB6lU2sozbQVF/OVXhfJ aZRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738856453; x=1739461253; h=to:message-id:subject:date:mime-version:from :content-transfer-encoding:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=h0VRy0IgePBDTFLiunEIc8h9t1nAYTA5Hyi9323QvKI=; b=SDOPvY5EoyOosp+LL7CIideewEgbXAMJQiCRfpOmYkZD4IL1hdKJ1bfS8S0aB9uTT8 2gqE9vStHMlWKwinU1RetOccHMBncBxwBoEIcJQ8wp/1keiseG3EU1YunpaCNABWNz/t b8V67Wh8EptnuWTFu4vQyJ8mYSMB77emN8k3td3NSqugrxoXZFnNCXk4f4aZZK3pZ5Ib LBr8TS3W7QayfvVM9XVM3CKN6dm+d2lCQQt+T6AQN8Y55V8UiRayU3OpDcywSKJP0V8o Qx9XTmBLurPr0KAhiafevgjhXeqWtXiMJKChfG1RZ7DC78qjvfatqdu8B2VnJ2THqz+n BE2Q== X-Gm-Message-State: AOJu0YxLmBIfW0YlobUAs0WnbmLgUVLt/XOHMsuM5fkrFdc/6sNbTnfj 4z7iSG0P8Kmti0yc54ECMAmZig+BtZpICKdEpI+3AgqgHhaKe67FaT8JP+vpp4heovyfaCllDtV AlGdM9uKfTCImEQ0HQPy01bRrZebpo0c2YMXIyKFB4qC7WJMsPd1Ot/DMbnsb3pwiWPSy9u0Cyg zS5CnXWlkTnR5ar/t1gDw2jsKwS1ujJ17r7BctFQJTTk1pa0EeNdcE X-Gm-Gg: ASbGnctUgfUcjSoPDWGi0Yap5rWoy50ltndTiMeEbVt3g4xDNZxd9wmdrY/FcSClZ9t nP7DjXH01IunMu9G1IPtJFLWTQeDmBFqmfftTs+rdMbTZTm2jDjMVoQlU8Y3w3XjzJJzqL+xrYi zJPr+ZkOqc59/85OoIKcXEPDs1n8PqW/QqTL46MWFf5anwTmGHwXWx/3yOU6pXTxfQgeTE5rxtd zT7mTds6gRxqOed86VQ3qtnqPcUAJ8vwB/cz6ve0Cw5Go7c9XQLr/MJx+oHj02sF2UPAhmS/j86 rDjWNb5L26mQhxL/d828T3cHRvKV/vol3Mzejnaxp83L9UZ53zNXGMyOF1x62wP3VTC9Ue3cYJy teDOfSdJaPw== X-Google-Smtp-Source: AGHT+IF90pFJK6c8AnoRuiwduuRB8b1UeZ2YAYYw/Rh9QYRhFwSBg+SygZaqMee9kXKczszTR1giXA== X-Received: by 2002:ac8:5a44:0:b0:46c:729a:a5b with SMTP id d75a77b69052e-470281c422bmr89623121cf.28.1738856452749; Thu, 06 Feb 2025 07:40:52 -0800 (PST) Received: from smtpclient.apple (pool-173-61-86-135.cmdnnj.fios.verizon.net. [173.61.86.135]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-471492c333csm6512171cf.48.2025.02.06.07.40.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 06 Feb 2025 07:40:52 -0800 (PST) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable From: Robert Leach Mime-Version: 1.0 (1.0) Date: Thu, 6 Feb 2025 10:40:41 -0500 Subject: How to perform a long running dry run transaction without blocking Message-Id: To: pgsql-general@lists.postgresql.org X-Mailer: iPhone Mail (21G80) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I've been trying to solve this problem in Django and I've finally decided af= ter over a year going down this path that there's no way to solve it in Djan= go (in a database agnostic fashion). So I'm thinking that I need to explore a= Postgres-specific solution. FYI, I'm not a database expert. I just know eno= ugh to get myself into trouble like this problem. Let me try and distill all the back story down to an oversimplified explanat= ion: I created a scientific data submission validation interface that helps resea= rchers compile their data submissions to our database. To do this, I decided= to add a `--validate` option to the load scripts that essentially raises a d= ry run exception at the end of a load run so that the data is all rolled bac= k before leaving the atomic transaction block. This validation interface skips the raw data load step, which is the hefties= t, most long running, part and generally finishes in well under a minute. The interface works fantastically well. It rolls back problematic data in sm= aller transactions and buffers those errors for a final report that the user= can work to fix in their data files and retry validation until all their pr= oblems are solved and the data is ready to load. The problem is that if we have a long running load going on in the backgroun= d (which can take hours) and during that load, a user tries to validate a ne= w submission that contains some overlapping common data (e.g. a new tissue t= ype or protocol that is currently being loaded) or perhaps they are trying t= o validate data added to an existing submission that is being partially load= ed, that validation process gets blocked and the validation interface encoun= ters a gateway timeout. I had tried changing the isolation level to both repeatable read and seriali= zable, but the hang can still occur (though serializable seems to avoid hang= s in some cases that repeatable read does not). My initial interpretation of the isolation level documentation was that tran= sactions would not be aware of what is happening in other transactions and t= hat if there was a problem, you would only ever get a serialization error at= the end when the data is committed, but after encountering the hang yesterd= ay, I realized that the "snapshot" that the second transaction gets includes= locks already established by the first transaction. I had hoped that since my validation interface would never commit, it would n= ever have a serialization error or hang. What options are available that might allow this all to work as I intended? I= s there some way to tell the validation process transaction to assume that a= ny pending changes from another transaction will succeed? I have lots of ideas on how to mitigate these occurrences, but I don't want t= o bias any potentially helpful responses. Am I screwed from my early decisio= n to use the loading code to validate data submissions?=