Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cLbMW-0007HU-Gz for pgsql-admin@arkaria.postgresql.org; Mon, 26 Dec 2016 19:55:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cLbMU-0008J6-NV for pgsql-admin@arkaria.postgresql.org; Mon, 26 Dec 2016 19:55:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cLbKm-0006JB-DZ for pgsql-admin@postgresql.org; Mon, 26 Dec 2016 19:53:24 +0000 Received: from mail-qt0-x22a.google.com ([2607:f8b0:400d:c0d::22a]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1cLbKh-0003cs-4V for pgsql-admin@postgresql.org; Mon, 26 Dec 2016 19:53:21 +0000 Received: by mail-qt0-x22a.google.com with SMTP id p16so311324727qta.0 for ; Mon, 26 Dec 2016 11:53:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=FFHsQL2JiSJXFOiKIdJu64fDwxAKYisJbmD5pUAeDqk=; b=EWFqVYwJ2sEd0fK0iuSCUGe/ESJMgMDaH8oscl6ulb+LiWRfXAcqjBD+FU7PyZrLdA 7+MVQ9J+rzN6Ao+Vo054NfWaqFa5o0dwn9o6fZwnuzZikzP34IQDJtgw1eMSknGXINbP rt++lFtda56Hz6xks0KXg+4leHqjHH7ex5ZRIZq31x9DjmG+Aiu8xyqj+U7+CHFGB7Py XMZScIaWeyU539cGcyyiLOWqd0pswh5LC9SYnsl7OXokHDXdjVA4OjatnfxY2gQtWOtu ovv7CMvlerVnkKR0EIlDyWRCJLQRckFzEhhmo1KCmecZrPV1lxW4/6eagGTaohilmL55 /baw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=FFHsQL2JiSJXFOiKIdJu64fDwxAKYisJbmD5pUAeDqk=; b=EsPfQX3xO/T+pg7WKwR/vUZtCRJkTQz3eZAUD95HauVF7KFqyJ7mZz37I3yov1FMfb Ik+aFHMSO7KaJ0/YBXn7RYTOiiP96BhTMxBXpO0Ri9YO5ppPW363zyCWODKYEctimvSB R73QMho5c9lD8e4A2lIQ9Y/oqeDoryBy/y6iv7pQOSAZefKX5FkcejWZlaNSdPJglSQC ErZZp4+8qIGoDS/lHfLreTug/NLmwl3baNg61P9mxncEa/swgfLA4jwDJbNb1PELr+xa 3oCEkxe4Z9YO5Vp9tbZEobT70sB83M5zWXMPR1CvXW56z8LaONIX5Gc6oqj31KawqCnU FJrA== X-Gm-Message-State: AIkVDXLSryhZpjiNHlL5hFBc4LpHj15cQ6G2h+nZxUJ+n8kR+H6dIdtmYBrLO7rF8WU5Abik X-Received: by 10.200.40.211 with SMTP id j19mr29721061qtj.72.1482781997578; Mon, 26 Dec 2016 11:53:17 -0800 (PST) Received: from alvin.alvh.no-ip.org ([179.56.97.120]) by smtp.gmail.com with ESMTPSA id q1sm120946qkh.35.2016.12.26.11.53.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Dec 2016 11:53:17 -0800 (PST) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 639E91734; Mon, 26 Dec 2016 16:53:15 -0300 (CLST) Date: Mon, 26 Dec 2016 16:53:15 -0300 From: Alvaro Herrera To: Gaetano Mendola Cc: "pgsql-admin@postgresql.org" Subject: Re: Lock a viewe Message-ID: <20161226195315.3frvv36pnvf2rk2b@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20161104 (1.7.1) X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-admin Precedence: bulk Sender: pgsql-admin-owner@postgresql.org Gaetano Mendola wrote: > Hi, > I was wondering if there is a clean view to lock the usage of a view. > > Basically during a schema migration, with applications still running a > typical > schema change is: > > BEGIN; > ALTER TABLE x ADD COLUMN (a INTEGER); > CREATE OR REPLACE VIEW v_x > AS > SELECT a,b FROM x; > COMMIT; > > now the issue is that if an application performs a: > > SELECT * from v_x; > > between the ALTER and the view redefinition then a deadlock happens. > > I'm preventing this issue doing a: > > ALTER VIEW v_x ALTER COLUMN b DROP DEFAULT; > (anyway there was no default on the view) > before the ALTER TABLE, that's basically reorders the locks sequence > avoiding the dead lock. So what you want is LOCK VIEW f; (which is exactly what your hack does) but we don't allow that: you can only lock tables. I wonder what's the reason for that restriction. AFAICT changing it is trivial, since it just requires a very minor change in RangeVarCallbackForLockTable() to allow views. > Is there a clean way to achieve it without the "hack"? I can't think of anything. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-admin