From 9adbbd8aab0e46d3563d1206cd28a16b4007eef3 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Thu, 9 Jul 2020 15:41:18 -0500 Subject: [PATCH] Add Create Database Uses Template1 as a postgres til --- README.md | 3 ++- postgres/create-database-uses-template1.md | 30 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 postgres/create-database-uses-template1.md diff --git a/README.md b/README.md index 2e04a35..a4ed18d 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ and pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud). -_933 TILs and counting..._ +_934 TILs and counting..._ --- @@ -449,6 +449,7 @@ _933 TILs and counting..._ - [Count The Number Of Trues In An Aggregate Query](postgres/count-the-number-of-trues-in-an-aggregate-query.md) - [Create A Composite Primary Key](postgres/create-a-composite-primary-key.md) - [Create An Index Without Locking The Table](postgres/create-an-index-without-locking-the-table.md) +- [Create Database Uses Template1](postgres/create-database-uses-template1.md) - [Create hstore From Two Arrays](postgres/create-hstore-from-two-arrays.md) - [Create Table Adds A Data Type](postgres/create-table-adds-a-data-type.md) - [Creating Conditional Constraints](postgres/creating-conditional-constraints.md) diff --git a/postgres/create-database-uses-template1.md b/postgres/create-database-uses-template1.md new file mode 100644 index 0000000..221dc85 --- /dev/null +++ b/postgres/create-database-uses-template1.md @@ -0,0 +1,30 @@ +# Create Database Uses Template1 + +Whenever you use the [`create +database`](https://www.postgresql.org/docs/current/sql-createdatabase.html) +query, unless otherwise specified, it will create it by cloning `template1` by +default. + +You can view, inspect, and even modify this database template by connecting to +it. + +```sql +\c template1 +``` + +Every Postgres cluster starts with two templates. + +```sql +select datname from pg_database where datistemplate = true; + datname +----------- + template1 + template0 +(2 rows) +``` + +You cannot however connect to and modify `template0`. It is a fallback clone of +`template1` that you can utilize if you ever modify `template1` and need to +restore it. + +[source](https://supabase.io/blog/2020/07/09/postgresql-templates/)