Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tg7YZ-007sfB-9p for pgsql-bugs@arkaria.postgresql.org; Thu, 06 Feb 2025 19:28:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tg7YY-00Arqd-AE for pgsql-bugs@arkaria.postgresql.org; Thu, 06 Feb 2025 19:28:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tg7YX-00AroV-Ry for pgsql-bugs@lists.postgresql.org; Thu, 06 Feb 2025 19:28:58 +0000 Received: from fennec.ash.relay.mailchannels.net ([23.83.222.58]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tg7YU-003b18-2y for pgsql-bugs@lists.postgresql.org; Thu, 06 Feb 2025 19:28:56 +0000 X-Sender-Id: hostingeremail|x-authuser|david@pgbackrest.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 4B7848A1A2C; Thu, 6 Feb 2025 19:28:53 +0000 (UTC) Received: from uk-fast-smtpout7.hostinger.io (trex-3.trex.outbound.svc.cluster.local [100.125.12.218]) (Authenticated sender: hostingeremail) by relay.mailchannels.net (Postfix) with ESMTPA id 74A288A3663; Thu, 6 Feb 2025 19:28:52 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1738870132; a=rsa-sha256; cv=none; b=tnCVaD9+jZ2CvaVS583g5JUo58nH7HcXXlijoVgLttw430wT7PGvlqOnMuiD25Dy8L761k i3AReuZ7mQDV3wt+Htn8hthb30PUvHOL5XKN9GqnWBNdsSDpDAyD7swLV2lndiqPxT9mjV KevQgthY4aZt9FqfsFHOVjuxAHdZt3NT2opNlLgPW9z2Vu2Sqn3gElnwSH1qVp3YZRiciX JHb+znbrLcnIh91tfaz594VY0oXgyR6CbnT3RO1qrH3I59E02cafA8wmgCaYH04b3SWPne rNfjNljFLVQiTy4N1JW7PnR9mBnar/tB9TmMRWO0+OFQrRKqNM10stLEMldNag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1738870132; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=muLnQyjDQeh4LBCgMHZ8YvADwG2En9laQDimI8Q9Jt8=; b=6ie5/58qB4FPtJeTnzs+xYq/g2rOw+f7YMTfoX+GHVGhU5aGElPLtMJ30ptrJWiIR6u4DD EANv5i2VSKXFr+ZnRa3Gnx0vKBBWc9ORz9Cnb2qhDVgswh0bcc6E156C6lFToX6bDYlt9l bB6WT3ly5XGdJiSDKUv0krBcVcvRSbVpdko3jJIMoXQWHaogGlow7K7oi0b3hGgTXYk5IA XU2OGlD9ldc1qA1HetoijqgaqqnQ+/nLM9LnQeKXEvrAmKt5c9ct0aOkVEM5v3/S0NkXK0 B86nQoXD1o0OLVLD0LAEF9FF8gwDvjiNK0a3+WBChsxld/i+zEonDOE8M/JR9A== ARC-Authentication-Results: i=1; rspamd-8586946c78-p7lnd; auth=pass smtp.auth=hostingeremail smtp.mailfrom=david@pgbackrest.org X-Sender-Id: hostingeremail|x-authuser|david@pgbackrest.org X-MC-Relay: Neutral X-MailChannels-SenderId: hostingeremail|x-authuser|david@pgbackrest.org X-MailChannels-Auth-Id: hostingeremail X-Absorbed-Relation: 2717f4c55c0666c3_1738870133095_3590541277 X-MC-Loop-Signature: 1738870133095:2881845149 X-MC-Ingress-Time: 1738870133095 Received: from uk-fast-smtpout7.hostinger.io (uk-fast-smtpout7.hostinger.io [31.220.23.87]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.125.12.218 (trex/7.0.2); Thu, 06 Feb 2025 19:28:53 +0000 Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pgbackrest.org; s=hostingermail1; t=1738870130; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=muLnQyjDQeh4LBCgMHZ8YvADwG2En9laQDimI8Q9Jt8=; b=oPIuRuf/glrb5KSyozb7q8zajvNQOf/LztxhSJfRWq3TXjLD4uOoFMvNjLHlzpqXlMm5y/ mw4HkpAiPoenALcQUVzg7AqIhSPtnR2EFAyMPjPDjLvOWrtX6bGgErF2/6YZHkzF5S5jl4 5d0NMsAdEjvoZommDpJU1u1VV2VLX5/A0YwL1E8unaFJaEpn24FSsslzgMNqfbJDAxItoe atbB82Xf2nsHCWlFqnmfSm2bL3mHuaNGlY9y+A+dPJ7GzLkkjGyd3Pq0KQF5ixECuBI1aY tmg52Ecl/Yekxl82ju9qHjrwi4fuzGga8bf3//dsLUnL8ZSjMwxUbCWc/uyqOA== MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Bug in recovery of drop database? To: Andres Freund Cc: "pgsql-bugs@lists.postgresql.org" References: <43f0c3df-a23c-4159-9610-934d3dceb80c@pgbackrest.org> <73f2e462-d767-4248-98ed-9c0fcdac10bf@pgbackrest.org> Content-Language: en-US From: David Steele In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 06 Feb 2025 19:28:50 +0000 (UTC) X-CM-Analysis: v=2.4 cv=FNtJxPos c=1 sm=1 tr=0 ts=67a50d72 a=gdlHKkXP8+lrT2Og+UTy0w==:117 a=gdlHKkXP8+lrT2Og+UTy0w==:17 a=IkcTkHD0fZMA:10 a=QU6MapHj1F_jXYKjwMEA:9 a=QEXdDO2ut3YA:10 X-CM-Envelope: MS4xfFJqJHJ20qrA4VPhSkT4zgeZ7XBwYmluK3zwkyn3V4GHIrDaosEz5pFuKZlol5lC7ETDBm6K5reehj0O7T7KswOjQi7ZCAqCJ5281Oc2x+yIHUmXWYU7 mc3W52Ts+DOC9M0oUsr54B4+qGtcUMM2ne72EcQuobXRExGQSGsIIuv/PmctRar/MOPqmVA1PA7o0Gads4rgAApvAAovB8HtTDC8C6M5ExjG+hYP1RAUT7VG X-AuthUser: david@pgbackrest.org List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2/6/25 13:05, Andres Freund wrote: > On 2025-02-06 15:55:21 +0000, David Steele wrote: >> >> Before c66a7d75 it looked like this: >> >> FATAL: database "mytest" does not exist >> DETAIL: The database subdirectory "base/16384" is missing. >> >> Which seems reasonable when just looking at the error and not the detail. > > Yea, I don't think my commit fundamentally changed things, it just made the > issue a bit more apparent. The biggest change is that it actually allows to > "fix" the leaked space from SQL. > > To actually fix this problem we'd need to move the dropping of database files > to happen as part of transaction commit, similar to how relation files aren't > actually truncated the moment you truncate a table. That's not a trivial > change... Understatement. > WRT your repro: >> test/pg/bin/psql mytest -t -c 'select now()' >> 2025-02-05 19:18:26.245167+00 >> >> test/pg/bin/dropdb mytest >> test/pg/bin/psql mytest >> psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: >> FATAL: database "mytest" does not exist >> ... >> echo "recovery_target_time = '2025-02-05 19:18:26.245167+00'" >> >> test/data/postgresql.auto.conf >> ... >> test/pg/bin/psql mytest -c 'select count(*) from pgbench_accounts' >> psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: >> FATAL: cannot connect to invalid database "mytest" >> HINT: Use DROP DATABASE to drop invalid databases. > > I'd guess this is due to using the default recovery_target_inclusive=true. I got the same result with recovery_target_inclusive=false. I think you could get it to work with a more precise timestamp or better, xid or lsn. > The reason: > >> However, if I insert this command before the drop database: >> >> test/pg/bin/psql mytest -c 'create table test (id int)' >> >> Then recovery works fine since it is able to stop before the the drop >> database. This is an issue on HEAD as well as all current back branches. > > works, presumably is that now there's another transaction to stop at > *after*. Without the additional transaction the first complete transaction > with the recovery_target_time Given I'm grabbing the timestamp before the create table I'd expect it to stop before the table is created whether recovery_target_inclusive is true or false. I just gave it a try and sure enough either way I get: $ test/pg/bin/psql mytest -c 'select count(*) from test' ERROR: relation "test" does not exist > IOW, while the two-step-drop-database is an issue, even without it, your > reproducer doesn't seem like it actually would work, even if it were a single > step, to implement the below scenario: The repro works almost every time for me on all six active branches. It hasn't worked a few times, but in those cases I suspect I accidentally skipped a step. I'm running it manually each time. >> We have seen this several times now because a favorite test for users is to >> drop a database and see if they can recover it with PITR. PITR in a test >> database is always a bit dicey since little/no WAL activity means recovery >> doesn't have much to go on RE recovery targets, but at the least the >> database should be fully there or fully not there. > > Because the repro actually sets the recovery target to *after* the drop > database. > > Am I misunderstanding something? Without looking at the code, my guess is the dropping of files WAL record does not have a transaction timestamp that recovery can use so recovery blows by the dropping of files and stops before the entry is removed from pg_database. It sounds like this is more or less a known issue. If we decide not to fix it how about I at least document it as a caveat for drop database? Regards, -David