Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dpNY0-0001MT-5Q for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Sep 2017 23:46:24 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dpNXz-0000IS-GT for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Sep 2017 23:46:23 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dosat-0007cA-CT for pgsql-hackers@postgresql.org; Mon, 04 Sep 2017 14:43:19 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dosam-0003N3-1B for pgsql-hackers@postgresql.org; Mon, 04 Sep 2017 14:43:18 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id A53BB21C1D11 for ; Mon, 4 Sep 2017 17:43:09 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru Received: from ars-thinkpad (unknown [192.168.27.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 80F3A21C1D04 for ; Mon, 4 Sep 2017 17:43:09 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1504536189; bh=Ii3oUe2/ReZcSCKFeTFpHRnAV+lhreCfFPdDqJTOX+E=; h=From:To:Subject:References:Date:In-Reply-To; b=o/L0Yn0zzvC72NosYrhxwgVy5efeCjW1CLpkXAVzpbfMTJOmOCkXXqCHfvuhLB8gK LLZmVmjOfWhvDQSfJ/uXgdStHNfe/qltAOGaGx7K0qey3zUSXnz+r1GPCKcsDhJrFu ZVOS4UOPxQpAXJJJi7LSbm7rdlqFaVwFpLWyWUA4= From: Arseny Sher To: pgsql-hackers@postgresql.org Subject: Re: DROP SUBSCRIPTION hangs if sub is disabled in the same transaction References: <87mv6av84w.fsf@ars-thinkpad> Date: Mon, 04 Sep 2017 17:43:09 +0300 In-Reply-To: <87mv6av84w.fsf@ars-thinkpad> (Arseny Sher's message of "Mon, 04 Sep 2017 17:41:19 +0300") Message-ID: <87ingyv81u.fsf@ars-thinkpad> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org --=-=-= Content-Type: text/plain Arseny Sher writes: > Attached patch fixes this by stopping workers before RO drop, as > already done in case when we drop replication slot. Sorry, here is the patch. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Stop-LR-workers-before-dropping-replication-origin.patch Content-Description: stop_lr_workers_patch From 008d54dfe2e8ba610bb7c897cfbb4ee7a700aa2e Mon Sep 17 00:00:00 2001 From: Arseny Sher Date: Mon, 4 Sep 2017 16:55:08 +0300 Subject: [PATCH] Stop LR workers before dropping replication origin. Previously, executing ALTER SUBSCRIPTION DISABLE and DROP SUBSCRIPTION in one transaction would hang forever, because worker didn't stop until transaction is commited, and transaction couldn't commit before worker exit since the latter occupies ReplicationState. --- src/backend/commands/subscriptioncmds.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/backend/commands/subscriptioncmds.c b/src/backend/commands/subscriptioncmds.c index 77620dfd42..5d608855a1 100644 --- a/src/backend/commands/subscriptioncmds.c +++ b/src/backend/commands/subscriptioncmds.c @@ -886,6 +886,10 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel) else slotname = NULL; + /* Get originid */ + snprintf(originname, sizeof(originname), "pg_%u", subid); + originid = replorigin_by_name(originname, true); + /* * Since dropping a replication slot is not transactional, the replication * slot stays dropped even if the transaction rolls back. So we cannot @@ -909,9 +913,10 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel) ReleaseSysCache(tup); /* - * If we are dropping the replication slot, stop all the subscription - * workers immediately, so that the slot becomes accessible. Otherwise - * just schedule the stopping for the end of the transaction. + * We stop all subscription workers immediately in two cases: + * - We are dropping the replication slot, to make the slot accessible; + * - We are dropping repl origin tracking, to release ReplicationState; + * Otherwise just schedule the stopping for the end of the transaction. * * New workers won't be started because we hold an exclusive lock on the * subscription till the end of the transaction. @@ -923,7 +928,7 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel) { LogicalRepWorker *w = (LogicalRepWorker *) lfirst(lc); - if (slotname) + if (slotname || originid != InvalidRepOriginId) logicalrep_worker_stop(w->subid, w->relid); else logicalrep_worker_stop_at_commit(w->subid, w->relid); @@ -937,8 +942,6 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel) RemoveSubscriptionRel(subid, InvalidOid); /* Remove the origin tracking if exists. */ - snprintf(originname, sizeof(originname), "pg_%u", subid); - originid = replorigin_by_name(originname, true); if (originid != InvalidRepOriginId) replorigin_drop(originid, false); -- 2.11.0 --=-=-= Content-Type: text/plain -- Arseny Sher Postgres Professional: https://postgrespro.ru The Russian Postgres Company --=-=-= Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --=-=-=--