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 1sS3aF-003SuY-R5 for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Jul 2024 23:52:19 +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 1sS3aE-001oVE-BF for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Jul 2024 23:52:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sS3aD-001oV6-38 for pgsql-hackers@lists.postgresql.org; Thu, 11 Jul 2024 23:52:18 +0000 Received: from mail-yb1-xb2f.google.com ([2607:f8b0:4864:20::b2f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sS3aA-001dUb-IH for pgsql-hackers@lists.postgresql.org; Thu, 11 Jul 2024 23:52:16 +0000 Received: by mail-yb1-xb2f.google.com with SMTP id 3f1490d57ef6-df4d5d0b8d0so1376432276.2 for ; Thu, 11 Jul 2024 16:52:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1720741932; x=1721346732; darn=lists.postgresql.org; h=user-agent: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=B2XlAYknpHrfRcJf1Zmb0RwoI1yE7qlCjGAw8QD1wMo=; b=df0LsqzvGd8w4vjV75ML5eGYo/jquqjJnI7FlZ0o1wSJXuXL+tgmm74hnn21WC4BXY scW++/cSlxHo9rJiZkqapshNSIf6aUkWG6difUbEwTrlCHBacV6JNlOdbBqWgLWiiewi S3ClRwr5MLZQT45pgRcHL4R4iMnKUZPbd+E20= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720741932; x=1721346732; h=user-agent: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=B2XlAYknpHrfRcJf1Zmb0RwoI1yE7qlCjGAw8QD1wMo=; b=CVti6wuDkPEpNrgyr1Hn5vt/i78PIuhmyok2Lr5iJtNA9g8fVqzvHSJPnrQXClasEA evUm2rkUzajZdJP2twIBXtNeIpn7HQBw0uGEuUxt9mVvWKtnyB6FDYKyiLHyVv/vtTVM MfUI4bv08bIeyZDF1MdXe64U7MteFaZYeAV6ixNZpZ7Doc2NFP2XVHmDozyKlbihL4kR +xmqZCxLX74ONO+MQlGp3YgPS6dif8E9TmWbm1vm5nMx0z0/IXnkbvlY3WEYsee773ym aILQvGnsjvlGvf/U/bwKaFVZ0xzM09HrqfKOB4wmXiim4wtLCNYL3/8wzs4M3ZaV1gpo hzQA== X-Gm-Message-State: AOJu0YxKNzpPOs1E1moI7GjWILgOci5VVOqNQ7utDy08ts9hmo3AFjS+ gH0v9lVjStYXC7LO68vK8I1dl5/7ktUVPKSbZlilsgKxzYMhFwZu3sPsmLa0Lw== X-Google-Smtp-Source: AGHT+IGn7RPv4oRhTPX6TRLCEB8JivmlIYH+yA/PThHDLTC9T4xPLraCzCXnM0KUUW0ITL96uGw6tQ== X-Received: by 2002:a25:ab8d:0:b0:e03:9a27:feb0 with SMTP id 3f1490d57ef6-e041b0397c6mr11357459276.11.1720741931822; Thu, 11 Jul 2024 16:52:11 -0700 (PDT) Received: from google.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e041a981c92sm1175124276.51.2024.07.11.16.52.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jul 2024 16:52:11 -0700 (PDT) Date: Thu, 11 Jul 2024 16:52:09 -0700 From: Noah Misch To: Nazir Bilal Yavuz Cc: PostgreSQL Hackers Subject: Re: Use read streams in CREATE DATABASE command when the strategy is wal_log Message-ID: <20240711235209.f6.nmisch@google.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Apr 16, 2024 at 02:12:19PM +0300, Nazir Bilal Yavuz wrote: > I am working on using read streams in the CREATE DATABASE command when the > strategy is wal_log. RelationCopyStorageUsingBuffer() function is used in > this context. This function reads source buffers then copies them to the Please rebase. I applied this to 40126ac for review purposes. > a. Timings: > b. strace: > c. perf: Thanks for including those details. That's valuable confirmation. > Subject: [PATCH v1 1/3] Refactor PinBufferForBlock() to remove if checks about > persistence > > There are if checks in PinBufferForBlock() function to set persistence > of the relation and this function is called for the each block in the > relation. Instead of that, set persistence of the relation before > PinBufferForBlock() function. I tried with the following additional patch to see if PinBufferForBlock() ever gets invalid smgr_relpersistence: ==== --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -1098,6 +1098,11 @@ PinBufferForBlock(Relation rel, Assert(blockNum != P_NEW); + if (!(smgr_persistence == RELPERSISTENCE_TEMP || + smgr_persistence == RELPERSISTENCE_PERMANENT || + smgr_persistence == RELPERSISTENCE_UNLOGGED)) + elog(WARNING, "unexpected relpersistence %d", smgr_persistence); + if (smgr_persistence == RELPERSISTENCE_TEMP) { io_context = IOCONTEXT_NORMAL; ==== That still gets relpersistence==0 in various src/test/regress cases. I think the intent was to prevent that. If not, please add a comment about when relpersistence==0 is still allowed. > --- a/src/backend/storage/aio/read_stream.c > +++ b/src/backend/storage/aio/read_stream.c > @@ -549,7 +549,7 @@ read_stream_begin_relation(int flags, > { > stream->ios[i].op.rel = rel; > stream->ios[i].op.smgr = RelationGetSmgr(rel); > - stream->ios[i].op.smgr_persistence = 0; > + stream->ios[i].op.smgr_persistence = rel->rd_rel->relpersistence; Does the following comment in ReadBuffersOperation need an update? /* * The following members should be set by the caller. If only smgr is * provided without rel, then smgr_persistence can be set to override the * default assumption of RELPERSISTENCE_PERMANENT. */ > --- a/src/backend/storage/buffer/bufmgr.c > +++ b/src/backend/storage/buffer/bufmgr.c > +/* > + * Helper struct for read stream object used in > + * RelationCopyStorageUsingBuffer() function. > + */ > +struct copy_storage_using_buffer_read_stream_private > +{ > + BlockNumber blocknum; > + int64 last_block; > +}; Why is last_block an int64, not a BlockNumber? > @@ -4667,19 +4698,31 @@ RelationCopyStorageUsingBuffer(RelFileLocator srclocator, > /* Iterate over each block of the source relation file. */ > for (blkno = 0; blkno < nblocks; blkno++) > { > CHECK_FOR_INTERRUPTS(); > > /* Read block from source relation. */ > - srcBuf = ReadBufferWithoutRelcache(srclocator, forkNum, blkno, > - RBM_NORMAL, bstrategy_src, > - permanent); > + srcBuf = read_stream_next_buffer(src_stream, NULL); > LockBuffer(srcBuf, BUFFER_LOCK_SHARE); I think this should check for read_stream_next_buffer() returning InvalidBuffer. pg_prewarm doesn't, but the other callers do, and I think the other callers are a better model. LockBuffer() doesn't check the InvalidBuffer case, so let's avoid the style of using a read_stream_next_buffer() return value without checking. Thanks, nm