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 1qc3bE-00DiEJ-L7 for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Sep 2023 12:50:09 +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 1qc3bC-00EP3k-C7 for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Sep 2023 12:50:06 +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 1qc3bA-00EP3O-Nk for pgsql-hackers@lists.postgresql.org; Fri, 01 Sep 2023 12:50:05 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qc3b6-002LFb-GP for pgsql-hackers@postgresql.org; Fri, 01 Sep 2023 12:50:03 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 3C4C55C00A2; Fri, 1 Sep 2023 08:49:57 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Fri, 01 Sep 2023 08:49:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eisentraut.org; h=cc:cc:content-transfer-encoding:content-type:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to; s=fm3; t=1693572597; x=1693658997; bh=HIt28m31+bNVhV7JV1fKu5xdh YJlfWH9jVrO2aF6Lnc=; b=ffmZxNxIOOwJ4BrWiVnNISTjFZ2JKeAJQCdUgqbdP BAQh80sZKAnakVZzTnXIX72zxoRume0wKR0DzywTsBHNUDpJnZLpDMSvijNQnwa9 9hgUwrcgQBN6kmSHeh5cTK8RagH4FxVEirJKpTBUfZ5eKhKOzTur3FR7v2+9XrUL FAGqcGHr/e0yKn49wbRgSlfGXvZB3s281JJxCU+cmwR0cECu1mWljsK0eSHOP8wR SKkgqBY1SoHJe4Gcwy+P4D7l/aLpTj51Y1QK+M1kX51Q+tzCDlDa4igGLrE87eAf JoPI5bxfiNPEuDVPY0M/u4MvBr6SjHmvUTe6BqCYVXLMQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1693572597; x=1693658997; bh=HIt28m31+bNVhV7JV1fKu5xdhYJlfWH9jVr O2aF6Lnc=; b=1BEev7Po5Zb+BPnJ3PM3utJsVL1WtqSy+dUbhlEUPveLPDqOsyj d7XpMfY8fOIfTr7V2t5P+iV6n0x6/d6zJGXHhiSAdxWPc/Tiir4by0amNrz8lATL 4j8iQF4VqrXRIi7axHFkXZHd3Sh21JmFuCiUhGCfuawbAs3+YxumuSnZYj4sWRaO zuXH08jwCN65F5UPceyVoKb2bR3XDG8UPMneZJF3SY1fvycTw9UfrB+65Y8wgwg/ TIl0D4BCns15/wFTYXcAPMPVvET/WKRw6SNQj6x3c+fNqvYEddOb7MCXedXPL9W1 XgP7ea03+ciZk6KA8oAKloKkaJQig45SvBw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudegvddgheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtkeertddtfeejnecuhfhrohhmpefrvght vghrucfgihhsvghnthhrrghuthcuoehpvghtvghrsegvihhsvghnthhrrghuthdrohhrgh eqnecuggftrfgrthhtvghrnhepledvgfefudejjeduvdffkeekkedvfeeifeelieefgffh ieeiveduveeiheeifeejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphgvthgvrhesvghishgvnhhtrhgruhhtrdhorhhg X-ME-Proxy: Feedback-ID: ie0a040ee:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 1 Sep 2023 08:49:56 -0400 (EDT) Message-ID: Date: Fri, 1 Sep 2023 14:49:52 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: Unlogged relations and WAL-logging Content-Language: en-US To: Heikki Linnakangas , Robert Haas Cc: pgsql-hackers References: <6e5bbc08-cdfc-b2b3-9e23-1a914b9850a9@iki.fi> <868b64cf-0d0f-7d49-d985-a0574a8678e1@iki.fi> <0fc6970f-b24d-1f3f-0ebc-2b9a0b14a497@iki.fi> From: Peter Eisentraut In-Reply-To: <0fc6970f-b24d-1f3f-0ebc-2b9a0b14a497@iki.fi> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Is the patch 0003-Remove-unnecessary-smgrimmedsync-when-creating-unlog.patch still relevant, or can this commitfest entry be closed? On 23.08.23 16:40, Heikki Linnakangas wrote: >>>> 5. In heapam_relation_set_new_filenode(), we do this: >>>> >>>>> >>>>>         /* >>>>>          * If required, set up an init fork for an unlogged table >>>>> so that it can >>>>>          * be correctly reinitialized on restart.  An immediate >>>>> sync is required >>>>>          * even if the page has been logged, because the write did >>>>> not go through >>>>>          * shared_buffers and therefore a concurrent checkpoint may >>>>> have moved the >>>>>          * redo pointer past our xlog record.  Recovery may as well >>>>> remove it >>>>>          * while replaying, for example, XLOG_DBASE_CREATE or >>>>> XLOG_TBLSPC_CREATE >>>>>          * record. Therefore, logging is necessary even if >>>>> wal_level=minimal. >>>>>          */ >>>>>         if (persistence == RELPERSISTENCE_UNLOGGED) >>>>>         { >>>>>                 Assert(rel->rd_rel->relkind == RELKIND_RELATION || >>>>>                            rel->rd_rel->relkind == RELKIND_MATVIEW || >>>>>                            rel->rd_rel->relkind == >>>>> RELKIND_TOASTVALUE); >>>>>                 smgrcreate(srel, INIT_FORKNUM, false); >>>>>                 log_smgrcreate(newrnode, INIT_FORKNUM); >>>>>                 smgrimmedsync(srel, INIT_FORKNUM); >>>>>         } >>>> >>>> The comment doesn't make much sense, we haven't written nor WAL-logged >>>> any page here, with nor without the buffer cache. It made more sense >>>> before commit fa0f466d53. >>> >>> Well, it seems to me (and perhaps I am just confused) that complaining >>> that there's no page written here might be a technicality. The point >>> is that there's no synchronization between the work we're doing here >>> -- which is creating a fork, not writing a page -- and any concurrent >>> checkpoint. So we both need to log it, and also sync it immediately. >> >> I see. I pushed the fix from the other thread that makes smgrcreate() >> call register_dirty_segment (commit 4b4798e13). I believe that makes >> this smgrimmedsync() unnecessary. If a concurrent checkpoint happens >> with a redo pointer greater than this WAL record, it must've received >> the fsync request created by smgrcreate(). That depends on the fact that >> we write the WAL record *after* smgrcreate(). Subtle.. >> >> Hmm, we have a similar smgrimmedsync() call after index build, because >> we have written pages directly with smgrextend(skipFsync=true). If no >> checkpoints have occurred during the index build, we could call >> register_dirty_segment() instead of smgrimmedsync(). That would avoid >> the fsync() latency when creating an index on an empty or small index. >> >> This is all very subtle to get right though. That's why I'd like to >> invent a new bulk-creation facility that would handle this stuff, and >> make the callers less error-prone. > > Having a more generic and less error-prone bulk-creation mechanism is > still on my long TODO list.. >