6 min read
|
Saved February 14, 2026
|
Copied!
Do you care about this?
This article explains how to use PostgreSQL's templating system to create fast, zero-copy database clones. It covers the new cloning strategies introduced in PostgreSQL 15 and 18, detailing the efficiency of using modern filesystems for cloning without additional storage costs.
If you do, here's more
Long-running database migration scripts can be nerve-wracking, especially when dealing with large databases. The article highlights how PostgreSQL can simplify the creation of database copies using its templating system. By default, PostgreSQL clones the standard template database, template1, whenever a new database is created. The real innovation comes with PostgreSQL 15, which introduced a parameter allowing users to choose how databases are created from templates. The new default method, WAL_LOG, improves I/O performance but can slow down cloning large databases. For those who need speed, the FILE_COPY strategy restores the original method.
PostgreSQL 18 brings further enhancements. It allows users to leverage modern filesystems' capabilities, enabling almost instant database cloning without additional disk space. By setting the file_copy_method to "clone," you can create a database that shares the same physical data blocks as the original. This results in significant time savings when cloning large databases. The article provides a benchmark showing a drastic improvement in cloning time, dropping from over 67 seconds to just over 200 milliseconds.
However, this shared storage can lead to confusion regarding database sizes. Both the original and cloned databases may report the same logical size, even though they share physical data. When data is modified in the cloned database, it triggers a copy-on-write process. This means that updates create new data entries, leading to divergence in physical storage over time. The article illustrates this with practical examples and commands for monitoring shared data blocks, showcasing the efficiency of using PostgreSQL's advanced features in database management.
Questions about this article
No questions yet.