This PG Casts episode is sponsored by Hashrocket, a consultancy specializing in PostgreSQL; learn more at hashrocket.com. To see more PG Casts videos, visit our RU-vid channel or www.pgcasts.com
Transcript:
Hey everyone, today we're going to look at how to create and use a custom template database in Postgres.
To create a new template database, we use the normal "create database" command, passing the parameter "is_template" with a value of "true".
If we are customizing locales or encoding on our new custom template, we should make sure that we are cloning from Postgres's `template0`, rather than the default `template1`.
```sql
create database example is_template true encoding 'SQL_ASCII' template template0;
```
We can see our new template database with the list command.
```
\l
```
And we can verify that it is a template by checking out the pg_database data.
```sql
select datistemplate from pg_database where datname = 'example';
```
To create a new database cloned from our custom template, we use the "create database" command, passing our template name to the template parameter.
```sql
create database test template example;
```
Using the list metacommand again, we can see that our new database has the SQL_ASCII encoding from our custom template.
```
\l
```
Thanks for watching!
18 сен 2024