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 1taGYl-000Gou-Jg for pgsql-hackers@arkaria.postgresql.org; Tue, 21 Jan 2025 15:53:00 +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 1taGYk-000ks6-Hf for pgsql-hackers@arkaria.postgresql.org; Tue, 21 Jan 2025 15:52:58 +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 1taGYk-000kry-8b for pgsql-hackers@lists.postgresql.org; Tue, 21 Jan 2025 15:52:58 +0000 Received: from mail-il1-x130.google.com ([2607:f8b0:4864:20::130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1taGYh-000kBG-1Z for pgsql-hackers@lists.postgresql.org; Tue, 21 Jan 2025 15:52:57 +0000 Received: by mail-il1-x130.google.com with SMTP id e9e14a558f8ab-3ce7935d38cso17765515ab.3 for ; Tue, 21 Jan 2025 07:52:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737474774; x=1738079574; darn=lists.postgresql.org; 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=JHP+3QHsZzhLsRGFf8wDxI/+f0BIWe3Hzinu/Mxpuqs=; b=deFxJ64fAOzbcIow05SxhpStEUPFDt3hRAJTiNlOmiBn9L1dC7HYvNOM9g7e/lNtSu YhRvV+dfKSb5mJnLc6+tnXNPayT0u/uICsiIm+RHmV9Fi0zirrTy6aE3/rHt5+Iiey3V vq86d5rt1//nGnibtsEy3ofbhKreH86erJo118evYBymbx7ApuPi59QQC7GWqDbUJgIC H6Gi/9aoOTkBf43BmoM0Zji2D37NyQZSHFbvWfHbecR45xHGs9wi9mr4lur9S0+MyfuL 4gJwPNk9RfQVaf35zx/K5J0lgAyccZXqvpoJ5rfooMRfnGs3YEHH840YhEZUwZoq9Vrv eFUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737474774; x=1738079574; 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=JHP+3QHsZzhLsRGFf8wDxI/+f0BIWe3Hzinu/Mxpuqs=; b=k9x6/HPxH6Vq5hxndwdeI9FKRZebKgtP7VcvrJHWlZ1i6+Jrd5b8ZNBK7eNgNnobZ4 3hjF3siJJedQ5Tamte6PkuRH69WC1xkwsxkV9jWVnSspoJTsTbBOIXZo90iRh6aDxfLy Er25FzmZUgs42HVbUpBYIlph9zFdE5EHmhLAKGQi8RHEQTdOl08bShRzJM2D0U6XFWcL oYg3toPLqxM+1EOaDJdUgdr4Eu6KAw2IpO+XmCYd41MSItPIVch41ift2pp5mrp0MZBQ a0sHJByzueS9HoS9LzOnDz1nO/zyydHg8QODvGsMFURniGJ+AoDRl8FPa8QJjcO+FyyU 8dWQ== X-Forwarded-Encrypted: i=1; AJvYcCVDPpl7Rmlbz2dar9r+ExRK7P4SxMlAOH76mUxziv0dZ7UDMF/m5N9+dzRWLZwAhoKn60+/XuUAFBaLcU8m@lists.postgresql.org X-Gm-Message-State: AOJu0YwmAWQmKOxSck0VsvA4N8fBCYbvI/oMEu4O/qZt2FNe/IJxNfN2 CYfLGFl1hCxgUOiRoUIie9HGMxv1d2VLMwD8ZcvZmLq9OAj0H7Mu X-Gm-Gg: ASbGncu3C0L+Av4e4h01l3A1wR4S7cRDwwDvqfG1dQ8mhRRSZI2K3jsSy1ng9rwRF3I ygDNCvgQB8rfS4N0PITVRCGK+PEh3YVCFgUdoUOao7L63bUv6OmtvxBIiEokV910QlOGWOq45ow yHUdPTOVvn8Uj91/pLApWj6lqwZ86CGLxlpB26WA6d+0l6x+x0Z/KJ2xT4Kvbf2crKV2OAvG96d T6hji0TcD1e/0k7yTlivF3gsVvSWz9f9Xs/Y2cmUqtWnwxeT0B4IgTtOCNhqwmH+OkpWfRfAo12 qXfdbi3LPWpKNBrm03dCl7iF0SM1i1DH3GJy+2eU6LGS56Y/R4dLL5+PYej0 X-Google-Smtp-Source: AGHT+IHSPMKwDIWuyEfGpa84KFCj032HPtoLmQczqXir2YtYqTsjdoTC3wBfXhCoxB+FAZg3iyQsCw== X-Received: by 2002:a05:6e02:1849:b0:3ce:8b1b:2f with SMTP id e9e14a558f8ab-3cf7447bd09mr124201805ab.17.1737474773827; Tue, 21 Jan 2025 07:52:53 -0800 (PST) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3cf71a9e5bcsm30100795ab.28.2025.01.21.07.52.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jan 2025 07:52:53 -0800 (PST) Date: Tue, 21 Jan 2025 09:52:51 -0600 From: Nathan Bossart To: Andy Fan Cc: Justin Pryzby , Maxim Orlov , Pavel Borisov , "Bossart, Nathan" , Maxim Orlov , Andres Freund , pgsql-hackers@lists.postgresql.org Subject: Re: Pre-allocating WAL files Message-ID: References: <51BAAB3B-9D3C-4155-B125-42E4F06DCDF4@amazon.com> <163352276350.15435.3988688227048304232.pgcf@coridan.postgresql.org> <20220301144044.GG25269@telsasoft.com> <20220301150704.GA1030078@nathanxps13> <20220317231212.GB1415284@nathanxps13> <20220408203003.GA1630183@nathanxps13> <87sepc4zcg.fsf@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87sepc4zcg.fsf@163.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Jan 21, 2025 at 03:31:27AM +0000, Andy Fan wrote: > Come from [0] and thanks for working on this. Here are some design > review/question after my first going through the patch. Thanks for taking a look. > 1. walwriter vs checkpointer? I prefer to walwriter for now because.. > > a. checkpointer is hard to do it in a timely manner either because > checkpoint itself may take a long time or the checkpoint_timeout > is much bigger than commit_delay. but walwriter could do this timely. > I think this is an important consideration for this feature. > > b. We want walwriter to run with low latency to flush out async > commits. This is true, but preallocating a wal doesn't increase the > latency too much. After all, even user uses the aysnc commit, the walfile > allocating is done by walwriter already in our current implementation. I attempted to deal with this by having pre-allocation requests set the checkpointer's latch and performing the pre-allocation within the checkpointer's main loop and during write delays. However, checkpointing does a number of other things that could just as easily delay pre-allocation, so it's probably worth considering the WAL writer. > 2. How many xlogfile should be preallocated by checkpointer/walwriter > once. In your patch it is controled by wal-preallocate-max-size. How > about just preallocate *the next one* xlogfile for the simplification > purpose? We could probably start with something like that. IIRC it was difficult to create workloads where you'd need more than 1-2 at a time, provided whatever is pre-allocating refills the pool quickly. > 3. Why is the purpose of preallocated_segments directory? what in my > mind is we just prellocate the normal filename so that XLogWrite could > open it directly. This is same as what wal_recycle does and we can reuse > the same strategy to clean up them if they are not needed anymore. The purpose is to limit the use of pre-allocated segments to only situations where WAL recycling is not sufficient. Basically, if writing a record would require a new segment to be created, we can quickly pull a pre-allocated one instead of creating it ourselves. Besides simplifying matters, this prevents a lot of unnecessary pre-allocation, since many workloads will almost never need anything beyond the recycled segments. -- nathan