Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iHBzy-0007G3-8r for pgsql-bugs@arkaria.postgresql.org; Sun, 06 Oct 2019 19:15:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iHBzv-0002Vk-KP for pgsql-bugs@arkaria.postgresql.org; Sun, 06 Oct 2019 19:15:15 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iHBzv-0002Vd-9W for pgsql-bugs@lists.postgresql.org; Sun, 06 Oct 2019 19:15:15 +0000 Received: from anput.mintsoft.net ([130.255.76.212]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1iHBzs-0003vt-I0 for pgsql-bugs@lists.postgresql.org; Sun, 06 Oct 2019 19:15:14 +0000 Received: from set.mintsoft.net (cpc89770-stok19-2-0-cust16356.1-4.cable.virginm.net [86.23.127.229]) by anput.mintsoft.net (Postfix) with ESMTPS id 78DC343563 for ; Sun, 6 Oct 2019 19:15:10 +0000 (UTC) Received: by set.mintsoft.net (Postfix, from userid 33) id 1F91F101074; Sun, 6 Oct 2019 20:15:10 +0100 (BST) To: pgsql-bugs@lists.postgresql.org Subject: [PATCH] Re: BUG #16032: pg_basebackup when running on Windows doesn't clean up on failure correctly X-PHP-Originating-Script: 1000:rcube.php MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=_43f7ec0bbffe8d8765ecef3db9ffe153" Date: Sun, 06 Oct 2019 20:15:10 +0100 From: Rob Emery In-Reply-To: <16032-4ba56823a2b2805f@postgresql.org> References: <16032-4ba56823a2b2805f@postgresql.org> Message-ID: <0c6477f627e63c9cea68a6eda3f29a74@mintsoft.net> X-Sender: postgresql@mintsoft.net User-Agent: Roundcube Webmail/1.2.2 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --=_43f7ec0bbffe8d8765ecef3db9ffe153 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed Hello, I've already posted this to pg_hackers, but I'm not sure if it's more normal to post proposed fixes against the bug itself; so see attached if needed. Thanks, Rob On 2019-10-01 17:06, PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 16032 > Logged by: Rob Emery > Email address: postgresql@mintsoft.net > PostgreSQL version: 11.5 > Operating system: Windows > Description: > > Hello, > > When running a pg_basebackup in tar mode on windows against a PG 9.5 > box we > are finding that the backup doesn't get deleted successfully when it > fails. > Based on > https://github.com/postgres/postgres/commit/9083353b15c3cf8e7bbac104a81ad42281178cdf#diff-473d306e41ee616e92fb58ac128a9dcc > we would expect it to? > > To reproduce start running pg_basebackup like so: > > PS C:\Users\developer> & "$PgBinPath\pg_basebackup.exe" > --host="PGSERVER" > --pgdata="D:\Backups\rofl" --format=tar --wal-method=fetch > --username="backup_user" > > from a psql on the box run: > `SELECT pg_terminate_backend(pid) FROM pg_stat_replication WHERE state > = > 'backup';` > this kills the backup. > > If you run pg_basebackup on a linux box it nicely deletes the base.tar > and > the directory, whereas on windows we get the following error: > ``` > pg_basebackup: could not read COPY data: SSL SYSCALL error: EOF > detected > pg_basebackup: removing data directory "D:\Backups\rofl" > could not remove file or directory "D:\Backups\rofl/base.tar": > Permission > denied > could not remove file or directory "D:\Backups\rofl": Directory not > empty > pg_basebackup: failed to remove data directory > ``` > Once pg_basebackup has exited, the file lock seems to be gone and we > can > delete it ourselves, > it looks like pg_basebackup is contending with itself but only on > Windows. > > We've reproduced this on 2 different Windows machines so we don't think > it's > something like AntiVirus getting in the way or similiar. > > Thanks, > Rob --=_43f7ec0bbffe8d8765ecef3db9ffe153 Content-Transfer-Encoding: base64 Content-Type: text/x-diff; name=0001-Fix-bug16032-under-windows-when-the-backup-is-aborte.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