Skip to content

Instantly share code, notes, and snippets.

@juike
Created November 21, 2014 06:40
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save juike/2b187f0b83cf2b0f5987 to your computer and use it in GitHub Desktop.
Save juike/2b187f0b83cf2b0f5987 to your computer and use it in GitHub Desktop.
Restoring a 'template1' database in PostgreSQL. (https://wiki.postgresql.org/wiki/Adventures_in_PostgreSQL,_Episode_1)
UPDATE pg_database SET datallowconn = TRUE WHERE datname = 'template0';
\c template0
UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';
DROP DATABASE template1;
CREATE DATABASE template1 WITH TEMPLATE = 'template0';
\c template1
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';
UPDATE pg_database SET datallowconn = FALSE WHERE datname = 'template0';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment