DB Internals AtlasPostgreSQL 18.6 Home About

Parameter · Resource Usage / Disk

file_copy_method

Selects the file copy method.

  • Default: copy
  • Type: enum
  • Values: copy · clone
  • Applies: Session (any user)

In plain words

Some commands copy whole database directories file by file. With copy, PostgreSQL reads and writes every byte. With clone, it asks the filesystem to share the blocks instead (copy-on-write filesystems such as XFS with reflink, Btrfs, ZFS, APFS), which can be nearly instant.

For DBAs and operators

New in PostgreSQL 18. Affects CREATE DATABASE … STRATEGY = FILE_COPY and ALTER DATABASE … SET TABLESPACE. (The default strategy since PostgreSQL 15 is WAL_LOG, which copies block by block through WAL and is not affected.) clone uses copy_file_range() on Linux/FreeBSD or copyfile() on macOS; on filesystems with reflink support the kernel shares blocks, making a copy of a large template database very fast and space-efficient. On Linux, copy_file_range() also works on filesystems without block sharing (the kernel then copies the data itself); on macOS cloning is forced and fails with ERROR: could not clone file … where the filesystem cannot clone.

Use case: quickly creating test databases from a big template: SET file_copy_method = clone; CREATE DATABASE test1 TEMPLATE prod_snapshot STRATEGY = FILE_COPY;. FILE_COPY forces a checkpoint before and after.

How to change it

Any user can change it for their session with SET.

See it in context

Physical layout on disk Logical structure

Related parameters

file_extend_method

All Resource Usage parameters