I did not know that template0
and template1
database templates are required in order to create empty databases. I deleted them in order to clear up postgres. Now I'm not able to create any new database. Gives me this error :
ERROR: template database "template1" does not exist
What can I do to get things going once again. I'll be very thankful for any help.
“template0” is also a template database. It contains the same default database objects as “template1,” except you shouldn't modify it because it's meant to be a pristine database copy and ICD for PostgreSQL prevents you from doing so.
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.
An Access template is a file that, when opened, creates a complete database application. The database is ready to use, and contains all the tables, forms, reports, queries, macros, and relationships that you need to start working.
datistemplate can be set to indicate that a database is intended as a template for CREATE DATABASE . If this flag is set, the database can be cloned by any user with CREATEDB privileges; if it is not set, only superusers and the owner of the database can clone it.
Luckily I had postgres
database preserved because it was required for the postgres
user to log into psql
. Thus, created a template0
and template1
database :
create database template0 TEMPLATE postgres;
and same for template1. Then executed :
update pg_database set datistemplate=true where datname='template0';
for both databases to stop myself from accidentally deleting these templates again.
Everything works fine now :)
On my CentOS 7 box, I was not so lucky as to still have a database to connect to. However:
su postgres -c "initdb /var/lib/pgsql/data"
(as root) created a template0 and template 1 to work with.
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