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 1teGMp-00CmLY-Ap for pgsql-general@arkaria.postgresql.org; Sat, 01 Feb 2025 16:29:12 +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 1teGMo-005y7Z-FR for pgsql-general@arkaria.postgresql.org; Sat, 01 Feb 2025 16:29:10 +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 1te3Gg-003iiR-2h for pgsql-general@lists.postgresql.org; Sat, 01 Feb 2025 02:29:58 +0000 Received: from gondor.xen.prgmr.com ([71.19.157.29]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1te3Gd-002YjI-0i for pgsql-general@lists.postgresql.org; Sat, 01 Feb 2025 02:29:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tozzi.eu; s=gondor; t=1738376992; bh=GPZsM6OUGTTo+Mv2XVsM7I+wwvGy6/TFf50QuHSnhBY=; h=Date:To:From:Subject:From; b=p9o6vbf4H2gZL+pEBKprwnt1ou9AL+D8wMRxmJNQMoNPhymnLXRxUWor3L3RZpdUi raUNTmLBWm/3GLZT8gZxfdOIBA+hbTxLGGgUMWP0Jc38Ihg9PY9ocZJ4z7V9U1eLAu WwgFNxJWMyZ1x5BBAbqoTIbu0yUjarr8n0THGJjXNKaISLYqfl9Qyx8hMbYV1xcLRM v127eO++qmZ80RfB7tPHodd5vpP3kdkPsR4kcmgvTZCPVDwMgCNB4rGb+xUJprDjpN hBX/35/K3Q3j6HUGrtJnL0+jvRTlGUhKY7tIs0ANZBd3Z5Mm5gr8p1S7B0z/s8EiYs e1AghvbKNqlGA== Received: from orthanc.isengard.local (host-87-20-18-100.retail.telecomitalia.it [87.20.18.100]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by gondor.xen.prgmr.com (Postfix) with ESMTPSA id C054887 for ; Sat, 1 Feb 2025 02:29:52 +0000 (UTC) Received: from [172.30.147.2] (unknown [172.30.147.2]) by orthanc.isengard.local (Postfix) with ESMTPS id CA42C1439FF4 for ; Sat, 1 Feb 2025 03:29:49 +0100 (CET) Message-ID: Date: Sat, 1 Feb 2025 03:29:49 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: pgsql-general@lists.postgresql.org From: Gabriele Tozzi Subject: Toughs for CREATE DATABASE performance improvement Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi there, i am relying on PgSQL's template system for most activities by using the command "CREATE DATABASE newdb WITH TEMPLATE oldb STRATEGY FILE_COPY" to clone big databases. I have noticed the FILE_COPY strategy works best in my scenario, as pointed out in the docs, but it still gives me quite long wait times. By peeking into the source code, i've also noticed that the copy operation takes place in src/backend/storage/file/copydir.c; there the copy_file() function allocates a buffer to copy file data. Most modern CoW filesystems support "reflinks" (fclonefileat syscall usually) allowing a file to be cloned almost instantly without the need to physically duplicate data. This behavior would be beneficial both for performance (clone speed) and space efficiency. I see the pg_upgrade tool already implements this strategy via the "--clone" switch. Do you think it would be hard or beneficial to make it available also in the main daemon? In Posix systems, the standard file copy "cp" command switched its default behavior in 2021 (coreutils 9+) to always try to copy files by using reflinks first, so it should be a safe approach, it then automatically falls back to the old behavior if reflinking can't take place. What are your toughs? Could this fit in a feature request? If yes, how can i structure it correctly? I've seen bug reporting guidelines but not FR guidelines. Thanks, Gabriele Tozzi -- GPG Key Fingerprint: DAD1 E3E3 C3E9 36FB C570 F405 9B5F 7108 A1D0 2FFF