How I changed the encoding of template1 after the fact - Mailing list pgsql-general

From Kevin Murphy
Subject How I changed the encoding of template1 after the fact
Date
Msg-id 43FE1E65.3030000@genome.chop.edu
Whole thread Raw
Responses Re: How I changed the encoding of template1 after the fact  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
I wanted to change the encoding of the template1 database, but when I
tried to drop template1, I get the message, "ERROR:  cannot drop a
template database".

The docs
(http://www.postgresql.org/docs/8.1/interactive/manage-ag-templatedbs.html)
say that this is possible, but a user comment on that page says you can't.

Actually, you *can* drop a template database, if you first convert it
into a non-template database, as per
http://techdocs.postgresql.org/techdocs/pgsqladventuresep1.php

Here's a condensed example, in which template1 is recreated to change
its default encoding:

-- Connect as the postgres superuser,
e.g.:

-- psql -U postgres
template1

-- Then
run:


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 encoding = 'UNICODE';
UPDATE pg_database SET datistemplate = TRUE where datname = 'template1';
\c template1
UPDATE pg_database SET datallowconn = FALSE where datname = 'template0';

If you just wanted to clone template0, you would leave out the "encoding
= 'UNICODE'" clause.

Gurus, any corrections or safety advisories you care to make?

Kevin Murphy


pgsql-general by date:

Previous
From: "Brandon Metcalf"
Date:
Subject: subtracting minutes from date
Next
From: Emi Lu
Date:
Subject: Re: SQL TYPE MAP such as SQL_CHAR, SQL_NUMERIC , etc