Re: Better error message for trying to drop a DB with open subscriptions?

From: Craig Ringer <craig(at)2ndquadrant(dot)com>
To: Josh Berkus <josh(at)berkus(dot)org>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Better error message for trying to drop a DB with open subscriptions?
Date: 2017-07-21 01:57:13
Message-ID: CAMsr+YH-M3KK+65pqwNN+Asrt2CKZwBwquKOnVAtGVFNP_HF_g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 21 July 2017 at 07:09, Josh Berkus <josh(at)berkus(dot)org> wrote:

> All:
>
> The problem:
>
> postgres=# drop database bookdata;
> ERROR: database "bookdata" is being accessed by other users
> DETAIL: There is 1 other session using the database.
> postgres=# \c bookdata
> You are now connected to database "bookdata" as user "postgres".
> bookdata=# drop subscription wholedb;
> NOTICE: dropped replication slot "wholedb" on publisher
> DROP SUBSCRIPTION
> bookdata=# \c postgres
> You are now connected to database "postgres" as user "postgres".
> postgres=# drop database bookdata;
> DROP DATABASE
>
> Is there any easy way for us to detect that the "user" accessing the
> target database is actually a logical replication subscription, and give
> the DBA a better error message (e.g. "database 'bookdata' still has open
> subscrptions")? <http://www.postgresql.org/mailpref/pgsql-hackers>

Good idea. Also, this affects any active logical (db-specific) replication
slot, not just built-in logical replication.

CountOtherDBBackends reports prepared xacts separately already, and
errdetail_busy_db uses that to report the two separately. Since we have
slot attachment data I expect reporting attached replication slots would
not be hard either; you might be able to prep a patch for that in a few
hours.

--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Craig Ringer 2017-07-21 02:01:31 Re: More optimization effort?
Previous Message Craig Ringer 2017-07-21 01:53:19 Re: [PATCH] A hook for session start