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 1nVLOr-0006Rt-0R for pgsql-general@arkaria.postgresql.org; Fri, 18 Mar 2022 22:48:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nVLOp-0004Ce-RB for pgsql-general@arkaria.postgresql.org; Fri, 18 Mar 2022 22:48:47 +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 1nVLOp-0004CV-E5 for pgsql-general@lists.postgresql.org; Fri, 18 Mar 2022 22:48:47 +0000 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nVLOm-0007rN-GB for pgsql-general@lists.postgresql.org; Fri, 18 Mar 2022 22:48:46 +0000 Received: by mail-ed1-x530.google.com with SMTP id t1so11851740edc.3 for ; Fri, 18 Mar 2022 15:48:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20210112.gappssmtp.com; s=20210112; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=ZRPWxtqHlltLMzPNdBFVP67Oiryetn8CBtb7U68jcRc=; b=Ua+Jdhg6flIG4ZhLkQjFkSr1Iape2AC/BnDqszN9aL34GNQyw+9ZkVC7KujG7rmLSI F0g3ZuQQ/OMUAWa3tKqwcY17mo3avCzvNQhRmx8jEsVEohnfwPWYfoOwet+8U33hFins 2/zvdiSYthCoqB3pHRHHbG5ECyKs4+ONJB3H8F+I62Q+15yj5YwDCHw+kXAnQRJ5rIbO fb6KGc76hoe5DeIg0d6zc7IsZPjOUHOCft8+l+j8wYkkBrbb5aOm36PS7oD0VSZr8Gja dCoweRQDnGOObeJe0dy/T88E0cNvB7xpyq8Bz0qxJ/HVQ9cZyrz4Pog+fBo71rbc64z9 8SUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=ZRPWxtqHlltLMzPNdBFVP67Oiryetn8CBtb7U68jcRc=; b=P4+wo7dMplWVjHZMkRAzvXVtHAWFpw9w306xrRPnve+tVPMd9nSoRibReyRkRTUhlt C9Vbu60pWfE+ALL2rh2GyUhMN/Dbknb0THZ1IRMSg9hWjnh1RsYBeHU+A8mMiAsppQCS C8DYoiPSJzDd36A4jFhBVAkD9VCGf+necM0ZgoRvkju4eOZudXSxQlR6niezJPCOk9Wz fTcs9ylOQrDiLdzsvT+kU64HdVIiGnhYOxXliB4eLYtGyCHfn7U2+bql2UcQi+/WkzQp 4NZi2vRkc1qNDTqujlGr/VMLlgEE9XNK2FRbMusgF2hTuxIM4FgVf4gkFOgw/rgiVs+c gtIg== X-Gm-Message-State: AOAM53164/nEPN1s3HZ3IH8863d3uN2/lBT5BOa5RqSqgpOIeK0ml4FK yUuLtBbMEcSeQmtxrCivBGTXGg== X-Google-Smtp-Source: ABdhPJx701F+hOBz5ZctIMHryJ8qNTLrF9fwQYT6mx5SOiuKSVGpadueiYlLQMZ7YaRUbV0Jwy+kxg== X-Received: by 2002:a50:e696:0:b0:413:3846:20a9 with SMTP id z22-20020a50e696000000b00413384620a9mr11795559edm.96.1647643722357; Fri, 18 Mar 2022 15:48:42 -0700 (PDT) Received: from localhost.localdomain (62-46-250-86.adsl.highway.telekom.at. [62.46.250.86]) by smtp.gmail.com with ESMTPSA id hg8-20020a1709072cc800b006d6e469fbf0sm4116381ejc.134.2022.03.18.15.48.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Mar 2022 15:48:42 -0700 (PDT) Message-ID: <3cc08f35825c14458c4cd345ef449211d37ddc49.camel@cybertec.at> Subject: Re: How to explicitly lock and unlock tables in pgsql? From: Laurenz Albe To: Merlin Moncure Cc: Shaozhong SHI , pgsql-general Date: Fri, 18 Mar 2022 23:48:41 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.4 (3.40.4-3.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 2022-03-18 at 11:38 -0500, Merlin Moncure wrote: > > Also, you should nevr explicitly lock tables.  Table locks are taken automatically > > by the SQL statements you are executing. > > Isn't that a bit of overstatement? > LOCK table foo; > > Locks the table, with the benefit you can choose the lockmode to > decide what is and is not allowed to run after you lock it.  The main > advantage vs automatic locking is preemptively blocking things so as > to avoid deadlocks. Yes, that was an overstatement. But I find that 90% of the time when people explicitly lock a table it is not the correct solution. Yours, Laurenz Albe