How to Use a Custom Template Database in PostgreSQL

Опубликовано: 30 Май 2019
на канале: PG Casts by Hashrocket
1,977
12

This PG Casts episode is sponsored by Hashrocket, a consultancy specializing in PostgreSQL; learn more at https://hashrocket.com. To see more PG Casts videos, visit our YouTube channel or https://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!


Смотрите видео How to Use a Custom Template Database in PostgreSQL онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь PG Casts by Hashrocket 30 Май 2019, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 1,977 раз и оно понравилось 12 людям.