Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drqzP-0006HX-BE for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Sep 2017 19:36:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1drqzO-0008Ka-VM for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Sep 2017 19:36:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1drqzN-0008EP-K7 for pgsql-hackers@postgresql.org; Tue, 12 Sep 2017 19:36:53 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1drqzK-0007jK-2t for pgsql-hackers@postgresql.org; Tue, 12 Sep 2017 19:36:53 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 44D08218AF; Tue, 12 Sep 2017 15:36:48 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute7.internal (MEProxy); Tue, 12 Sep 2017 15:36:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= fm1; bh=YMwTxS9SPga3AVQm/SIH1tXE7GNlsKMwppzd3a6sq4k=; b=nXDYQjCc fR5yeGy2h+BAczUFnZPdM8dyEBptYyLKdDFuPOUx2r9n67gO1VobRfDFiImWHSdL +++IaCZvx7ztDr2QyKKyH58Q7AK6LO/zaui7ULjxwx0Fc4/dA/p9vP6ss0IcH4Oa k+mauZtOys7qCa7tVx89CZg8yGUeM5pZoH7c2BYtGfbxfSXdJS9vlVQHnPtPSK2P ZUwh+wQQhqcwaUe0bgTLelx72o3TyewbEmSdj2ROjoWhjKax0AQdi/BAOLJZSb5Y 98Myr6LE5DDThx4hT6vVClFV/kmaiAnh9tD1brx3svg3bJAINGoefsH+MgLBTnlV E3bcR3q3ZYpEnQ== X-ME-Sender: X-Sasl-enc: MdX5GaWw1xFBcT8mwl4kaPSR6gjA4wgzVPXXwMFsKLGR 1505245008 Received: from april.local (c-73-13-66-39.hsd1.pa.comcast.net [73.13.66.39]) by mail.messagingengine.com (Postfix) with ESMTPA id EB3A87FA7F; Tue, 12 Sep 2017 15:36:47 -0400 (EDT) Subject: Re: DROP SUBSCRIPTION hangs if sub is disabled in the same transaction To: Arseny Sher , pgsql-hackers@postgresql.org References: <87mv6av84w.fsf@ars-thinkpad> From: Peter Eisentraut Organization: 2ndQuadrant Message-ID: <48b251c6-0652-c131-975a-835d8cdb003c@2ndquadrant.com> Date: Tue, 12 Sep 2017 15:36:46 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <87mv6av84w.fsf@ars-thinkpad> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit 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 On 9/4/17 10:41, Arseny Sher wrote: > node 2: > create table t (i int); > create subscription s CONNECTION 'port=5432' publication p; > begin; > alter subscription s disable ; > alter subscription s set (slot_name = none); > drop subscription s; > end; > > It hangs in replorigin_drop because we wait until ReplicationState is > released. This should happen on exit of worker, but worker will not exit > until transaction commit because he doesn't see that the sub was > disabled. I think we are whacking things around a in circle now. First we moved the worker killing to the end of the transaction to make subscription DDL transaction-capable. Then we changed replication origin dropping to wait until the worker detaches. If you do both of these things at once, you get this circular dependency. We can break this in any number of ways: - (your patch) Kill workers right away after ALTER SUBSCRIPTION DISABLE, thus breaking the appearance of transactional DDL somewhat. - Revert to the old behavior that the replication origin dropping fails if it is in use. Then you would get an error instead of hanging. But that was previously also reported as a bug. - Disallow DROP SUBSCRIPTION in a transaction under certain circumstances, for example if a transaction has previously manipulated the same subscription. - Have DROP SUBSCRIPTION attempt to kill workers if the subscription is disabled (and possibly, was changed in the same transaction), which would address this scenario very narrowly. Maybe there are more ideas. But I think we have to pick a poison. Thoughts? -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers