Re: Lock a viewe

From: Gaetano Mendola <mendola(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Lock a viewe
Date: 2017-01-04 20:32:34
Message-ID: CAJycT5oc2TTypmHCrEZ7Q+hOGbDceSCg-6k=oiCwAW1x27SYHA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Mon, 26 Dec 2016 at 20:53 Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
wrote:

> 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;
>

Exactly that, it would be ideal indeed that was exactly my first attempt.

Regards.

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Günce Kaya 2017-01-05 07:55:13 Displaying ProcessList to Users
Previous Message Achilleas Mantzios 2017-01-04 07:38:28 Re: Table/View creation time