# DBLab vs CREATE DATABASE TEMPLATE: thin clones vs in-server copies

> CREATE DATABASE ... TEMPLATE copies a database inside the same PostgreSQL server, built in and free. DBLab makes thin clones of a full database on its own machine.

Checked on 2026-11-18. Page: https://postgres.ai/compare/dblab-vs-postgres-template-cloning. All comparisons: https://postgres.ai/compare.

## Short answer

CREATE DATABASE with TEMPLATE copies one database into a new database in the same PostgreSQL server. It is built in, and in PostgreSQL 18 STRATEGY FILE_COPY with file_copy_method = clone lets the kernel share disk blocks on file systems that support it. The docs say it is not yet intended as a general-purpose COPY DATABASE facility: no other session may be connected to the source while it is copied, and the copy lives in the same server. DBLab makes thin clones on its own machine, each an ordinary PostgreSQL server. To copy a database that nobody is connected to, such as a test fixture, the built-in command needs nothing else.

## Where DBLab is ahead of CREATE DATABASE ... TEMPLATE

1. **Clones the Postgres you already run.**
   - DBLab: Any PostgreSQL from version 10 up, wherever it runs: Amazon RDS, Aurora, Cloud SQL, Supabase or your own servers. ([DBLab data sources](https://postgres.ai/docs/dblab-howtos/administration/data), [Supported PostgreSQL versions and extensions](https://postgres.ai/docs/database-lab/supported-databases))
   - CREATE DATABASE ... TEMPLATE: CREATE DATABASE ... TEMPLATE copies a database into the same PostgreSQL cluster. No other session may be connected to the template while it is copied, and the docs say it is not yet intended as a general-purpose COPY DATABASE facility. [1][2]
2. **One copy of the data, many clones.**
   - DBLab: Clones share one physical copy on one machine and take extra disk space only for what they change. DBLab SE is billed by the size of that machine, not by database size or number of clones. ([DBLab Engine](https://postgres.ai/docs/database-lab), [Pricing](https://postgres.ai/pricing))
   - CREATE DATABASE ... TEMPLATE: With the default WAL_LOG strategy, the copy writes every block again and to WAL, in the same server. With FILE_COPY and file_copy_method = clone (PostgreSQL 18), the kernel may share disk blocks on some file systems. [1][3]
3. **Catches a dangerous migration in CI.**
   - DBLab: DB Migration Checker runs pending migrations on a clone in CI and fails those that hold dangerous locks longer than a limit, 10 seconds by default. ([DB Migration Checker](https://postgres.ai/docs/database-lab/db-migration-checker))
   - CREATE DATABASE ... TEMPLATE: A CI job can run CREATE DATABASE ... TEMPLATE or createdb -T while no other session is connected to the template. The sources we reviewed do not describe running migrations on the copy or checking the locks they take. [1][5]

## Try a clone before you install anything

```
dblab clone create --username dev --password "$PASSWORD" --id test
```

The public demo runs DBLab Engine: open it with the token demo-token, create a clone and connect to it. DBLab Engine is open source, so the next step is a machine of your own.

- [Open the DBLab demo](https://demo.dblab.dev)
- [Install DBLab Engine](https://postgres.ai/docs/dblab-howtos/administration/install-dle-manually)

## Side by side

| | DBLab | CREATE DATABASE ... TEMPLATE |
|---|---|---|
| What it is | Open-source software that gives every developer, CI job and AI agent a writable, full-size copy of a PostgreSQL database in seconds. Thin clones share one physical copy of the data on one machine. | A built-in SQL command. CREATE DATABASE works by copying an existing database, template1 by default; TEMPLATE name copies another database in the same cluster. The docs say this is "not (yet) intended as a general-purpose 'COPY DATABASE' facility." [1][2] |
| Which databases it can copy | Any Postgres source: yes. Any PostgreSQL from version 10 up, wherever it runs. Managed services such as Amazon RDS, Aurora, Cloud SQL and Supabase are copied with dump and restore; self-managed servers can also be copied physically with WAL-G, pgBackRest or pg_basebackup. | Any Postgres source: partly. Any database in the same PostgreSQL cluster, on any server where you may create databases. Any user with CREATEDB can copy a database marked as a template; otherwise only superusers and the owner can. Source and copy are in the same cluster. [1][2] |
| How a copy is made | Copy-on-write in the file system, with ZFS or LVM. Clones share unchanged blocks, so a clone takes extra disk space only for what it changes. | WAL_LOG, the default, copies block by block and writes each block to WAL. FILE_COPY copies directories at file system level, with a checkpoint before and after. In PostgreSQL 18, file_copy_method = clone makes FILE_COPY use copy_file_range() (Linux, FreeBSD) or copyfile (macOS), letting the kernel share disk blocks on some file systems. [1][3][4] |
| Time to get a copy | A few seconds whatever the database size: under 2 seconds for a 10 TiB database with one user, up to 30 seconds with 15 users at once. The first copy of the source is slow; about 1 TiB an hour is a good speed. | The docs give no times. WAL_LOG is described as the most efficient strategy when the template is small. FILE_COPY reduces WAL volume for a large template but forces two checkpoints. Whether clone shares blocks depends on the file system; the docs do not name which ones do. [1][3] |
| Data in a copy | Full-size data: yes. The whole database as of the chosen snapshot. Physical mode can follow the source continuously; logical mode is refreshed in full, on a schedule. | Full-size data: yes. The whole source database. Database-level settings (set with ALTER DATABASE) and database-level GRANT permissions are not copied. Encoding and locale must match the template, except when template0 is used. [1][2] |
| Masking sensitive data | Masking: yes. Documented options: load an anonymized dump, or apply SQL transformations or PostgreSQL Anonymizer before snapshots are taken. You define the rules. | Not documented in the sources we reviewed. CREATE DATABASE copies the template database as it is. [1][2] |
| CI and migration testing | CI integration: yes. DB Migration Checker runs pending migrations on a clone in CI, fails those that hold dangerous locks longer than a limit (10 seconds by default) and collects statistics. Any CI job can also create clones through the API or CLI. | CI integration: partly. No CI feature is documented. A CI job can run CREATE DATABASE ... TEMPLATE or createdb -T, as long as no other session is connected to the template at that moment. [1][5] |
| API, CLI and agent access | REST API, web UI and the dblab CLI. Joe, also available as pgai joe, returns EXPLAIN plans and timings from a clone, not rows. | SQL: CREATE DATABASE with TEMPLATE, STRATEGY and IS_TEMPLATE. The createdb program connects to the postgres database and issues the same command. [1][5] |
| Where it runs | Self-hosted: yes. On a machine you control, in any cloud or on-premises. DBLab SE installs from the PostgresAI Console or AWS Marketplace. | Self-hosted: yes. Inside the PostgreSQL server that holds the source. The new database is in the same cluster, served by the same server; the docs warn that FILE_COPY's checkpoints may have a noticeable negative impact on overall system performance. [1][2] |
| Open source | Yes. DBLab Engine is open source under Apache 2.0. | Yes. Part of PostgreSQL, released under the PostgreSQL License, which the project describes as a liberal open-source license similar to BSD or MIT. [6] |
| Documented limits | DBLab SE: 2,000 GiB per instance and a single user. All clones share one machine, and copy-on-write storage has different I/O performance, so timings on a clone should not be compared directly with production. | No other session may be connected to the template: CREATE DATABASE fails if one is, and new connections to it are blocked until the copy completes. Encoding and locale must match (except for template0). Database-level settings and GRANTs are not copied. file_copy_method = clone needs operating system support. [1][2][3] |
| What you pay for | One machine and one physical copy of the data, however many clones run. DBLab SE is billed hourly by the size of that machine, not by database size or number of clones. | Free, part of PostgreSQL. Copies use disk in the same server: WAL_LOG writes each block again and to WAL. With FILE_COPY and file_copy_method = clone, the kernel may share blocks on file systems that support it. [1][3][6] |

## When CREATE DATABASE ... TEMPLATE is the better choice

- Built into every PostgreSQL server: one SQL command, or createdb -T, with no extra software, machine or license.
- You can make your own template databases: mark one with IS_TEMPLATE and any user with the CREATEDB privilege can copy it.
- Objects added to a template are in every copy. The docs give the example of a procedural language installed in template1 being available in every new database.
- In PostgreSQL 18, STRATEGY FILE_COPY with file_copy_method = clone uses copy_file_range() on Linux and FreeBSD or copyfile on macOS, so the kernel can share disk blocks on some file systems.
- The copy is an ordinary database in the server you already run, with no second server to start, connect to or pay for.

## Pricing

| Product | Plan | List price | Notes |
|---|---|---|---|
| DBLab | DBLab Engine | Free | Open source, Apache 2.0; you run it |
| DBLab | DBLab SE | From $62/month | Billed hourly by machine size, plus your own cloud costs; 2,000 GiB limit; single user |
| DBLab | DBLab EE | Custom | Annual contract, from $0.2662 per 100 GiB per hour; unlimited database size, SSO |
| CREATE DATABASE ... TEMPLATE | Open source | Free | Part of PostgreSQL, PostgreSQL License [6] |

DBLab prices: https://postgres.ai/pricing.

## Questions

### Can I copy a production database with CREATE DATABASE ... TEMPLATE?

Only when no other session is connected to it. CREATE DATABASE fails if any other connection exists when it starts, and new connections to the source are blocked during the copy. The docs say this is not yet intended as a general-purpose COPY DATABASE facility. The copy also lives in the same server as the source. [1][2]

### What does file_copy_method = clone do in PostgreSQL 18?

It changes how CREATE DATABASE ... STRATEGY=FILE_COPY and ALTER DATABASE ... SET TABLESPACE copy files. The default is COPY. CLONE uses copy_file_range() on Linux and FreeBSD or copyfile on macOS, giving the kernel the opportunity to share disk blocks. The setting was added in PostgreSQL 18. [3][4]

### Which file systems support cloning with file_copy_method?

The PostgreSQL docs do not name any. They say CLONE uses copy_file_range() or copyfile, "giving the kernel the opportunity to share disk blocks or push work down to lower layers on some file systems." Check your file system's own documentation. [3]

### Who can copy a database with TEMPLATE?

Creating a database needs superuser or the CREATEDB privilege. If the source is marked as a template (IS_TEMPLATE, datistemplate), any user with CREATEDB can copy it; if not, only superusers and the owner of the database can. [1][2]

### How is DBLab different from a template copy?

A template copy is a new database in the same server as its source. DBLab copies any PostgreSQL from version 10 up, including Amazon RDS, onto its own machine, then makes thin clones of that copy; each clone is an ordinary PostgreSQL server. [1][2]

## Sources for DBLab

- [DBLab data sources](https://postgres.ai/docs/dblab-howtos/administration/data)
- [Supported PostgreSQL versions and extensions](https://postgres.ai/docs/database-lab/supported-databases)
- [DBLab Engine](https://postgres.ai/docs/database-lab)
- [Pricing](https://postgres.ai/pricing)
- [DB Migration Checker](https://postgres.ai/docs/database-lab/db-migration-checker)
- [DBLab Engine product page](https://postgres.ai/products/dblab_engine)
- [Full refresh in logical mode](https://postgres.ai/docs/dblab-howtos/administration/logical-full-refresh)
- [Data masking and obfuscation](https://postgres.ai/docs/database-lab/masking)
- [Joe commands: what is returned](https://postgres.ai/docs/reference-guides/joe-bot-commands-reference)
- [Run Joe from the CLI](https://postgres.ai/docs/postgresai-howtos/joe-cli)
- [Query timing on clones and in production](https://postgres.ai/docs/database-lab/timing-estimator)

## Sources for CREATE DATABASE ... TEMPLATE

1. [PostgreSQL docs: CREATE DATABASE](https://www.postgresql.org/docs/current/sql-createdatabase.html)
2. [PostgreSQL docs: Template Databases](https://www.postgresql.org/docs/current/manage-ag-templatedbs.html)
3. [PostgreSQL docs: file_copy_method](https://www.postgresql.org/docs/current/runtime-config-resource.html#GUC-FILE-COPY-METHOD)
4. [PostgreSQL 18 docs: Release 18](https://www.postgresql.org/docs/18/release-18.html)
5. [PostgreSQL docs: Creating a Database](https://www.postgresql.org/docs/current/manage-ag-createdb.html)
6. [PostgreSQL License](https://www.postgresql.org/about/licence/)

## How we compare

These pages compare what each product does for PostgreSQL; other databases and the rest of the stack are out of scope. What we say about the other product comes from its own documentation, pricing page, changelog or source repository, read on the date shown; each row cites its source. "Not documented" means we did not find it in those sources, not that the product cannot do it. Prices are list prices and the billing units differ, so they are not a total-cost comparison. Product names are trademarks of their owners.
