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 1uCLhz-00Dw6N-JA for pgsql-general@arkaria.postgresql.org; Tue, 06 May 2025 17:03:55 +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 1uCLhy-00946I-Ka for pgsql-general@arkaria.postgresql.org; Tue, 06 May 2025 17:03:54 +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 1uCEGK-007UCw-1p for pgsql-general@lists.postgresql.org; Tue, 06 May 2025 09:06:52 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uCEGH-000OjI-20 for pgsql-general@lists.postgresql.org; Tue, 06 May 2025 09:06:51 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-43d4ff56136so6560085e9.3 for ; Tue, 06 May 2025 02:06:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746522407; x=1747127207; darn=lists.postgresql.org; h=content-transfer-encoding:subject:from:to:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=HeiY2KMwZk3spTbdPH5WW2pVfaAFEH8qXUSL4TvSHDM=; b=k7Gvj5w44mEjtBbjxJlypQNGFowepEcM4tVWjG9h6jHnfWXpZJWHZknmIi7iKXQ/Jo 9Hk1smCM3WNgeRQ6tjVzhWd9L9OkX1wq8qir31JlJmxKfgsuLhJCrNgFj9uzZhSm3Ce3 68r3OHijZJm3mHk8gkJ7FBfSsoQN6THxApwzLES+asVbqSM5f8UIyKKflMTZP2fOjt/r gLRAyn+bD+5X2y5pkZYc/agL63qy7qxRFv98JijYj9NIqTahUA8BLca9Sxnkpz13cULL xx4W8hiT9i0xfnbRf4JkTSBmBtV8B1+k0lKQvNzFH8Om5lWuN8XYrrEuS4uCWvwsuwed R/Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746522407; x=1747127207; h=content-transfer-encoding:subject:from:to:content-language :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=HeiY2KMwZk3spTbdPH5WW2pVfaAFEH8qXUSL4TvSHDM=; b=nWT9jSwVeETgL97SQIfzUwsZhqZ4t8feQE3rSULvG0a0C7h9g8cnCcz5axtv5skPwR UC0IdjI9nUyM49HhUBSEZLkXm5YWF2wdrYnIbdjjtYe5wMA4c/jze3LXccOMSomq5Wzz p8I41KUkB9QCvBdMXpvur349iKDyQPXx6wfG/QneMOoeSDQSLIJZrdYOBwW68xCKsn8t ZMvJnyQrZLPBpHbPBubtz5rKj3ZtUU12lwDQyHkhKnQ3at1JNrDhTcMDfus9rcojTgCK 5rLT3lBmoCbmwSltwBtyOB+T9+ZwC0kPttTF4SBbng1d73MOfkL03KQjVCX3EsQIWje2 NmKw== X-Gm-Message-State: AOJu0YxElXciKJBVK1zULXbJ6/Iqb40iPbaAXIIyXqk7spb0yncitBe8 5DMXrC8Z/5l6StY6LEarbcSF5PHWu/R1Xv/WJNDekMvcI9tCAdMFqwmcCqlJ X-Gm-Gg: ASbGncswwmqLkN0M51abHZg7oyAB1yI0jl6f8vJL66H77XtkPi5usvsY3iKPHX/m36+ VFfJUSTfJlJ+sMzfVrI0pVlAqkvHyXTnuYanIynMBj6c2jU0WOA2IRa0+IgmV6JfPw/Lc1jzdkT /5JYvYkV/1HNOzWnseNWBPk3vFGSgImjVI4K3ibR6bRH731jqp6J0FockrR5w05QHRdomTr22jK 7bcFhlIUZFaYbni1ofnsbmFq5dNj4+HM2/lUmRXUhhgvOgPH6Qn185LaeoeUYZKjnNJ3bTYFaHk 4anyOwAx7pZNgmhtcCyMQWfxLrlUx74Gl/O0WOCWV7BH1iY/ X-Google-Smtp-Source: AGHT+IEc1dicJ12uPTeHMneCAaT/KMEjrbGQnLxzwgY7UIG9iVcLHkQSy4diA04fW6Yn+cstJlXtpQ== X-Received: by 2002:a05:600c:3b11:b0:43b:c0fa:f9bf with SMTP id 5b1f17b1804b1-441bbec0daemr50354315e9.3.1746522407040; Tue, 06 May 2025 02:06:47 -0700 (PDT) Received: from [192.168.68.200] ([94.131.133.177]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a099b107c4sm12970873f8f.76.2025.05.06.02.06.46 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 06 May 2025 02:06:46 -0700 (PDT) Message-ID: Date: Tue, 6 May 2025 12:06:45 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: pgsql-general@lists.postgresql.org From: Agis Anastasopoulos Subject: Soundness of strategy for detecting locks acquired by DDL statements Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello! I'd like to "preflight" a given schema migration (i.e. one or more DDL statements) before applying it to the production database (e.g. for use in a CI pipeline). I'm thinking of a strategy and would like to know about its soundness. The general idea is: - you have a test database that's a clone of your production one (with or without data but with the schema being identical) - given the DDL statements, you open a transaction, grab its pid, and for each statement:   1. from a different "observer" connection, you read pg_locks, filtering locks for that pid. This is the "before" locks   2. from the first tx, you execute the statement   3. from the observer, you grab again pg_locks and compute the diff between this and the "before" view   4. from the first tx, you rollback the transaction By diffing the after/before pg_locks view, my assumption is that you know what locks will be acquired by the DDL statements (but not for how long). The query I'm thinking is:     SELECT locktype, database, relation, objid, mode FROM pg_catalog.pg_locks WHERE pid = $1 AND locktype IN ('relation', 'object') AND granted"; The type of statements that would be fed as input would be `ALTER|CREATE TABLE`, `CREATE|DROP INDEX` and perhaps DML statements (`UPDATE`, `INSERT`, `DELETE`). Do you think this is a robust way to detect the locks that were acquired? Are there any caveats/drawbacks/flaws in this strategy? Thanks in advance