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 1mvGjt-0007AR-1i for pgsql-novice@arkaria.postgresql.org; Thu, 09 Dec 2021 10:33:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mvGjq-0003wu-KO for pgsql-novice@arkaria.postgresql.org; Thu, 09 Dec 2021 10:33:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mvGjp-0003wj-SY for pgsql-novice@lists.postgresql.org; Thu, 09 Dec 2021 10:33:22 +0000 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mvGjm-0006ZJ-Ig for pgsql-novice@lists.postgresql.org; Thu, 09 Dec 2021 10:33:20 +0000 Received: by mail-oi1-x236.google.com with SMTP id n66so8058162oia.9 for ; Thu, 09 Dec 2021 02:33:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bSXmr3ydeoOcyNcbNkzs2/iTxdC/DLLgQkwrTYv5qyI=; b=Ay86kpmzfkQBsj0lgSEQee3FuETr11rvUJpLibk+zXsCYFO+gHcVWUDrEY55UKkhMR /l4N6Fdx1NHSZtMnIgwj/zrl45jlqi+rfyo9z+2tQK4PtCJSgo4BiRgRRNSHIvvS7YXx 4Vhagzlqs1rndEBSdGRkKcjPM4hon+cEgocQMuWCtUriH+HLVhoWANhBfwoRHKX2Dfc/ LdatB3tkRYcbmkk2Zy4VtoXvboxbVQ4sI/+62F474VNF0GgntpP9devS9ZF0KolXuX3B QYoM+qnC4h3uJIsNcUr+iXD/hmVwLyWbNr9/PDeN67ydAD/SfoDX/IspIwoNO4hS/x4e MHEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bSXmr3ydeoOcyNcbNkzs2/iTxdC/DLLgQkwrTYv5qyI=; b=hgiXb4023p3jWsO6pua2MQ2qDE/SHvYaxYwFbH5pZ1cUfA756CWFC04P9e9s+d+Lur jrOgHqVjYytHg1auOAmOL8WTGm34iAq4KFx+vCiKQHT0f3HlsUgYH6tz1u9tuOscd2sx U7exNxaFRHRa1xcz3aMj/MVa3WPVxMQaPUl5+q2nSR74BwVxX5J2eHAbhZDaxYCYB0vM Y2V9y1jkw27g+EEd0AdVL4j5W8sBrH7ecLigPYpywRMmKF9kD9KknKI8Drdlrj3uW7kc 4cdG+dBqyI361NGMP515JlvGxzhnP5IjkK2OdLg6VN/BvXbPksk3ZlmyTH8+3KRUakez 8nEg== X-Gm-Message-State: AOAM5313QDgKVVzVmZTW6uzgnm6oat0fWBWHVeVlmYti/wE4TjTJU9Lr NaKqsOIwy+UfFDTNfIsLYIokESF1lxX+ASsjjMyTg2wPPh6gMK1ieZlKK9mqNWaH+DlNxLpEKUg hQf9czlsftT2iL4tI8jUCkKfCGtgofEH0lH3g29Ny/XprRSucPGXbMzexsunPd6Hg8b2wViONsO AsBGnH3BQsKW/bsuzsIHS/IJpBcY2Xnecnpau0w2huq4x4kkfXEUSjr2c8xy76PAsrpw== X-Google-Smtp-Source: ABdhPJzGpVsy+KB2mYzRcDfLsOOj9sil8VSs8jg/FxkkbDi/WuELrAciAf25F4VGXDow58aT/WRaVSmg95riS7XOrnM= X-Received: by 2002:aca:d6cb:: with SMTP id n194mr4877157oig.60.1639045997748; Thu, 09 Dec 2021 02:33:17 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Simon Riggs Date: Thu, 9 Dec 2021 10:33:06 +0000 Message-ID: Subject: Re: Table-Level Locks and Transactions To: greg.rychlewski@gmail.com Cc: pgsql-novice@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 9 Dec 2021 at 01:07, Greg Rychlewski wrote: > > I'm curious to understand when table-level locks are released by one transaction to use in another. At the end of transaction. > For instance, say I have the following transaction, where index1 and index2 both belong to the same table. > > BEGIN; > DROP INDEX index1; > CREATE INDEX index2; > COMMIT; > > This transaction acquires an ACCESS EXCLUSIVE lock during the DROP INDEX step and then acquires a SHARE lock during the CREATE INDEX step. > > I understand that there will be no conflicts between the statements in this transaction, but I'm wondering if an outside transaction will think that the table has an ACCESS EXCLUSIVE lock until this entire transaction is completed. No, just index1, but the SHARE lock will prevent writes. Have you thought about using DROP INDEX CONCURRENTLY and CREATE INDEX CONCURRENTLY? If in doubt, try it. Look at pg_locks. -- Simon Riggs http://www.EnterpriseDB.com/