Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ljOu6-0000O3-FC for pgsql-hackers@arkaria.postgresql.org; Wed, 19 May 2021 16:18:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ljOu4-00056R-8P for pgsql-hackers@arkaria.postgresql.org; Wed, 19 May 2021 16:18:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ljOu3-00055q-UG for pgsql-hackers@lists.postgresql.org; Wed, 19 May 2021 16:18:36 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ljOtx-0003TV-F4 for pgsql-hackers@lists.postgresql.org; Wed, 19 May 2021 16:18:35 +0000 Received: from mail.postgrespro.ru (cyclops.postgrespro.ru [93.174.131.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id F22D721C8303 for ; Wed, 19 May 2021 19:18:27 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1621441108; bh=Kt+eBrLCAqMHzc+nXjSdgxOFu+ioGsqbaNYp7swi7Jk=; h=Date:From:To:Subject; b=Fo0dweyYwiso0I/xkl8UGhW2YhBM+KfvF8j20w6VBpzf6W7zXAqUMAtRBD/OCqV0T +5ocOh77BK7fJRzxXNT4Vr32AWx3FxFcsSbPeevXUNNWzpVZ45vPKy9BJzbjCoyKuU duUzfYuccLO7Zu2+5SbZT4+9O8gh35IVWheUVgCE= MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=_258e7eae2d63fcabf7b3fdd5a72b9570" Content-Transfer-Encoding: 7bit Date: Wed, 19 May 2021 19:18:27 +0300 From: Yura Sokolov To: pgsql-hackers@lists.postgresql.org Subject: Add PortalDrop in exec_execute_message User-Agent: Roundcube Webmail/1.4.0 Message-ID: <4aa370cb91ecf2f9885d98b80ad1109c@postgrespro.ru> X-Sender: y.sokolov@postgrespro.ru List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=_258e7eae2d63fcabf7b3fdd5a72b9570 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed Hi, hackers. I've been playing with "autoprepared" patch, and have got isolation "freeze-the-dead" test stuck on first VACUUM FREEZE statement. After some research I found issue is reproduced with unmodified master branch if extended protocol used. I've prepared ruby script for demonstration (cause ruby-pg has simple interface to PQsendQueryParams). Further investigation showed it happens due to portal is not dropped inside of exec_execute_message, and it is kept in third session till COMMIT is called. Therefore heap page remains pinned, and VACUUM FREEZE became locked inside LockBufferForCleanup. It seems that it is usually invisible to common users since either: - command is called as standalone and then transaction is closed immediately, - next PQsendQueryParams will initiate another unnamed portal using CreatePortal("", true, true) and this action will drop previous one. But "freeze-the-dead" remains locked since third session could not send COMMIT until VACUUM FULL finished. I propose to add PortalDrop at the 'if (completed)' branch of exec_execute_message. --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -2209,6 +2209,8 @@ exec_execute_message(const char *portal_name, long max_rows) if (completed) { + PortalDrop(portal, false); + if (is_xact_command) { With this change 'make check-world' runs without flaws (at least on empty configure with enable-cassert and enable-tap-tests). There is small chance applications exist which abuses seekable portals with 'execute' protocol message so not every completed portal can be safely dropped. But I believe there is some sane conditions that cover common case. For example, isn't empty name check is enough? Can client reset or seek portal with empty name? regards, Sokolov Yura aka funny_falcon --=_258e7eae2d63fcabf7b3fdd5a72b9570 Content-Transfer-Encoding: base64 Content-Type: text/x-ruby; name=freeze-the-dead.rb Content-Disposition: attachment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