Skip to content

Instantly share code, notes, and snippets.

@batdevis
Last active August 29, 2015 14:17
Show Gist options
  • Save batdevis/1da414812a158b91eabd to your computer and use it in GitHub Desktop.
Save batdevis/1da414812a158b91eabd to your computer and use it in GitHub Desktop.
$ psql -U postgres
psql (9.4.1)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+-----------------------
postgres | postgres | LATIN1 | en_US | en_US |
template0 | postgres | LATIN1 | en_US | en_US | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | LATIN1 | en_US | en_US | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)
postgres=# update pg_database set datallowconn = TRUE where datname = 'template0';
UPDATE 1
postgres=# \c template0
You are now connected to database "template0" as user "postgres".
template0=# update pg_database set datistemplate = FALSE WHERE datname = 'template1';
UPDATE 1
template0=# DROP DATABASE template1;
DROP DATABASE
template0=# CREATE DATABASE template1 with template = template0 encoding = 'UTF8' lc_ctype = 'en_US.UTF-8' lc_collate = 'en_US.UTF-8';
CREATE DATABASE
template0=# update pg_database set datistemplate = true WHERE datname = 'template1';
UPDATE 1
template0=# update pg_database set datallowconn = false where datname = 'template0';
UPDATE 1
template0=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | LATIN1 | en_US | en_US |
template0 | postgres | LATIN1 | en_US | en_US | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(3 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment