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 1pSXxR-0001Lj-1m for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Feb 2023 06:41:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pSXxP-0004NL-Sr for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Feb 2023 06:41:27 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pSXxP-0004NC-HK for pgsql-hackers@lists.postgresql.org; Thu, 16 Feb 2023 06:41:27 +0000 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pSXxM-0003B7-GH for pgsql-hackers@lists.postgresql.org; Thu, 16 Feb 2023 06:41:26 +0000 Received: by mail-pg1-x534.google.com with SMTP id z6so685111pgk.0 for ; Wed, 15 Feb 2023 22:41:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=0zNnS8lgWMSWTC/QpraWcZrEm3IgLeCOkay7+4WbH3I=; b=WQksPsbIkSTbbgVjP6U9uXi7pARylKxr7JQTqPxOgDCwJ5nFmIiOw+NdZ+HpkgmmQ4 bJxraxH2o/7nUzNwOYQaUpt1okIimd9q7dewEtTnHJUmEBqg/mWWeIXYMqqy5H7sjj22 NN86F6/pYh846O27uvkUC5Jo6G78VfG33NkaQXiHipRHAd7N6vlVHULKPm7KPIE4ncii uWJ9xUtDUq6n2/aPqSbGGgzFkwxoATc9vmdAVJJ+4ei+lTr42xurPw4/IfVSXp1ztx49 PbZdZZZJqi2mO1PqlQycwkBqhOHCh1db8JA8sG+ooglE6c/7X4So9/CXwnueybWPogPH VGhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=0zNnS8lgWMSWTC/QpraWcZrEm3IgLeCOkay7+4WbH3I=; b=uAPhajZTwVPutrrb48PmOUrz0DYTTXHUZUBMIxyM0lK/rRDyzOYmYtG0VzExOHR+G5 ACazunCsAySRJL6nXsv5MXrn1WWoGGDn4yBVdQE5zYGuAjwR5KVw1lgx97l0mEZQULzm O+GKU555y8YXmW58mN30smkapF8HqUbeT2AhKC5x5BnxXOpQmbb0SUVMo3s06urKunaE t70tgMkcfJy78kpLVlvDZKfT2RcsA3+16cSRIeHziuHYHxrenodPRjL6za62i+Tygq6F XqZxSdhKG7Bme6ELcYkTRWo7L6xGYsA/maWDlAnVvJS0vR7srYp9J6F618K1Rgf7gn7H XiAQ== X-Gm-Message-State: AO0yUKUJIiW+dKnfbb+r4SbSwj/0tLq8hCU4ANPJMAEwdTgwE1Qvd2Jo +tF2Snx+jwEHGuKlJyI7iuc= X-Google-Smtp-Source: AK7set8+j6QQnbIwzK9vZbppkVh7nnPWeGyle8S9/8X7OlOy9Laoj+ID8HbmMXleYKzqwEo3L4H4BQ== X-Received: by 2002:aa7:9f85:0:b0:577:272f:fdb with SMTP id z5-20020aa79f85000000b00577272f0fdbmr4088653pfr.29.1676529683322; Wed, 15 Feb 2023 22:41:23 -0800 (PST) Received: from nathanxps13 ([50.47.162.83]) by smtp.gmail.com with ESMTPSA id s22-20020a62e716000000b00593e4e6516csm448107pfh.124.2023.02.15.22.41.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 22:41:22 -0800 (PST) Date: Wed, 15 Feb 2023 22:41:20 -0800 From: Nathan Bossart To: Michael Paquier Cc: Dilip Kumar , "Ryo Matsumura (Fujitsu)" , PostgreSQL Hackers Subject: Re: DDL result is lost by CREATE DATABASE with WAL_LOG strategy Message-ID: <20230216064120.GA2016097@nathanxps13> References: <20230216000659.GA1932550@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="wac7ysb48OaltWcw" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --wac7ysb48OaltWcw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Feb 16, 2023 at 02:26:55PM +0900, Michael Paquier wrote: > So, if I am understanding this stuff right, this issue can create data > corruption once a DDL updates any pages of pg_class stored in a > template database that gets copied by this routine. In this case, the > patch sent makes sure that any page copied will get written once a > checkpoint kicks in. Shouldn't we have at least a regression test for > such a scenario? The issue can happen when updating a template > database after creating a database from it, which is less worrying > than the initial impression I got, still I'd like to think that we > should have some coverage as of the special logic this code path > relies on for pg_class when reading its buffers. I was able to quickly hack together a TAP test that seems to reliably fail before the fix and pass afterwards. There's probably a better place for it, though... -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --wac7ysb48OaltWcw Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="create_db_fix_v2.patch" diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index ef05633bb0..a0259cc593 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -296,7 +296,7 @@ ScanSourceDatabasePgClass(Oid tbid, Oid dbid, char *srcpath) CHECK_FOR_INTERRUPTS(); buf = ReadBufferWithoutRelcache(rlocator, MAIN_FORKNUM, blkno, - RBM_NORMAL, bstrategy, false); + RBM_NORMAL, bstrategy, true); LockBuffer(buf, BUFFER_LOCK_SHARE); page = BufferGetPage(buf); diff --git a/src/test/recovery/meson.build b/src/test/recovery/meson.build index 209118a639..6e9f8a7c7f 100644 --- a/src/test/recovery/meson.build +++ b/src/test/recovery/meson.build @@ -39,6 +39,7 @@ tests += { 't/031_recovery_conflict.pl', 't/032_relfilenode_reuse.pl', 't/033_replay_tsp_drops.pl', + 't/100_bugs.pl', ], }, } diff --git a/src/test/recovery/t/100_bugs.pl b/src/test/recovery/t/100_bugs.pl new file mode 100644 index 0000000000..6429a352e9 --- /dev/null +++ b/src/test/recovery/t/100_bugs.pl @@ -0,0 +1,24 @@ + +# Copyright (c) 2023, PostgreSQL Global Development Group + +# Tests for various bugs found over time +use strict; +use warnings; +use PostgreSQL::Test::Cluster; +use PostgreSQL::Test::Utils; +use Test::More; + +# DDL on template is persisted after creating database using WAL_LOG strategy +my $node = PostgreSQL::Test::Cluster->new('node'); +$node->init; +$node->start; +$node->safe_psql("postgres", "CREATE DATABASE test STRATEGY WAL_LOG;"); +$node->safe_psql("template1", "CREATE TABLE test (a INT);"); +$node->safe_psql("postgres", "CHECKPOINT;"); +$node->stop('immediate'); +$node->start; +my $result = $node->safe_psql("template1", "SELECT count(*) FROM test;"); +is($result, "0", "check table still exists"); +$node->stop; + +done_testing(); --wac7ysb48OaltWcw--