Re: How can I tell if pg_restore is running?

From: Keith Fiske <keith(at)omniti(dot)com>
To: Moshe Jacobson <moshe(at)neadwerx(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: How can I tell if pg_restore is running?
Date: 2014-06-10 14:39:16
Message-ID: CAG1_KcAKd=eN1B0Q=aEtF1baZGymyKtRV-5gkEJa_r_iexixNQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jun 10, 2014 at 10:02 AM, Moshe Jacobson <moshe(at)neadwerx(dot)com> wrote:

> My extension has a config table that is dumped by pg_dump and populated by
> pg_restore.
> However, this table has triggers on it that I would like not to do
> anything if the table is being populated by pg_restore. I want the triggers
> to operate only if the user is manipulating the table directly after the
> database has been restored and is running.
>
> Is there a way for my extension's trigger functions to return immediately
> when triggered by pg_restore?
>
> Thanks.
>
> Moshe Jacobson
> Manager of Systems Engineering, Nead Werx Inc. <http://www.neadwerx.com>
> 2323 Cumberland Parkway · Suite 201 · Atlanta, GA 30339
>
> "Quality is not an act, it is a habit." -- Aristotle
>

I'd look into advisory locks.

http://www.postgresql.org/docs/9.3/static/explicit-locking.html#ADVISORY-LOCKS
http://www.postgresql.org/docs/9.3/static/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS

You'd probably have to wrap your pg_dump/restore in some sort of script
that can call the advisory locks, but I don't see why it wouldn't work.
Then you'd have your triggers check if the advisory lock is held and skip
whatever they do if so.

--
Keith Fiske
Database Administrator
OmniTI Computer Consulting, Inc.
http://www.keithf4.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Martin French 2014-06-10 14:51:44 Re: How can I tell if pg_restore is running?
Previous Message Moshe Jacobson 2014-06-10 14:02:10 How can I tell if pg_restore is running?