Re: Protect a table against concurrent data changes while allowing to vacuum it

From: Bill Moran <wmoran(at)potentialtech(dot)com>
To: Sameer Kumar <sameer(dot)kumar(at)ashnik(dot)com>
Cc: Vlad Arkhipov <arhipov(at)dc(dot)baikal(dot)ru>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Protect a table against concurrent data changes while allowing to vacuum it
Date: 2016-06-22 20:56:57
Message-ID: 20160622165657.47c4f7ee140cf57522cbac2f@potentialtech.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 22 Jun 2016 10:20:38 +0000
Sameer Kumar <sameer(dot)kumar(at)ashnik(dot)com> wrote:

> On Wed, Jun 22, 2016 at 6:08 PM Vlad Arkhipov <arhipov(at)dc(dot)baikal(dot)ru> wrote:
>
> > I am running PostgreSQL 9.5.
> >
> > CREATE TABLE t (id BIGINT NOT NULL PRIMARY KEY, name TEXT);
> >
> > The constraint that the data must satisfy is `there is no more than 3
> > records with the same name`.
> >
> > I am not in control of queries that modify the table, so advisory locks
> > can hardly be of help to me.
> >
>
> Define a function which does a count of the rows and if count is 3 it
> return false if count is less it returns true.

An exclusion constraint might be a better solution.

--
Bill Moran

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Patrick B 2016-06-22 21:42:10 Re: Help on recovering my standby
Previous Message David G. Johnston 2016-06-22 18:42:22 Re: Postgres 9.5.2 upgrade to 9.6