I'm a beginner in PostgreSQL. I wonder why the \l
command in psql shows databases template0
and template1
.
I searched the web but unfortunately didn't find the right resources. But I did find that after removing both (template0
& template1
) we can't create new databases any more.
A template is a form, mold or pattern used as a guide to make something. Here are some examples of templates: Website design. Creating a document. Knitting a sweater.
Whenever you create a new database in Postgres, you are actually basing it off an already present database in your cluster. This database, template1 , and another, called template0 , are standard system databases that exist in every newly created database cluster.
shared_buffers (integer) The shared_buffers parameter determines how much memory is dedicated to the server for caching data. The value should be set to 15% to 25% of the machine's total RAM. For example: if your machine's RAM size is 32 GB, then the recommended value for shared_buffers is 8 GB.
As the names indicate, those are template databases for creating new databases.
template1
is the one used by default. You can alter / add / remove objects there to affect every newly created DB. CREATE DATABASE
basically makes a copy of it on the file level (very fast) to create a new instance.
template0
starts out being the same and should never be changed - to provide a virgin template with original settings.
Their role is described in detail in the chapter "Template Databases" in the manual.
But you can use any database of the same cluster as template with the TEMPLATE
keyword - as long as there are no open connections to it. This is useful to populate new databases quickly. See:
How to clone a test database from a production one in one single action?
Shell script to execute pgsql commands in files
Truncating all tables in a Postgres database
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With