Re: datistemplate of pg_database does not behave as per description in documentation

From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Rajeev rastogi <rajeev(dot)rastogi(at)huawei(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: datistemplate of pg_database does not behave as per description in documentation
Date: 2014-03-27 08:38:32
Message-ID: CABUevEwOHzwSPnzXKk5dy3hQP9GOsd=b7s9cK1VwewywEYqBtA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Mar 27, 2014 at 9:12 AM, Rajeev rastogi
<rajeev(dot)rastogi(at)huawei(dot)com>wrote:

> As per the documentation, datistemplate of pg_database is used in
> following way:
>
>
>
> datistemplate
>
> Bool
>
> If true then this database can be used in the TEMPLATE clause of CREATE
> DATABASE to create a new database as a clone of this one
>
>
>
> But current code does not behave in this manner. Even if dbistemplate of
> database is false, still it allows to be used as template database.
>
>
>
> postgres=# select datname, datistemplate from pg_database;
>
> datname | datistemplate
>
> -----------+---------------
>
> template1 | t
>
> template0 | t
>
> *postgres | f*
>
> (3 rows)
>
>
>
> *postgres=# create database tempdb template postgres;
> ---Actually this should fail.*
>
> *CREATE DATABASE*
>
>
>
> Though I am not sure if we have to modify source code to align the
> behavior with documentation or we need to change the documentation itself.
>
> To me it looks like code change will be better, so I am attaching the
> current patch with source code change. After modification, result will be
> as follows:
>
>
>
> *postgres=# create database newtempdb template postgres;*
>
> *ERROR: DB name "postgres" given as template is not a template database*
>
>
>
> Please provide your feedback.
>
>
>
AFAICT, the *only* thing datistemplate is used is to set parameters in
autovacuum.

So clearly we should do something. Changing the code that way carries the
risk of breaking applications (or at least DBA scripts) for no apparent
reason. I think it's better to document it.

However, that also raises a third option. We could just drop the idea if
datistemplate completely, and remove the column. Since clearly it's not
actually doing anything, and people seem to have been happy with that for a
while, why do we need it in the first place?

--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Etsuro Fujita 2014-03-27 08:55:41 Re: inherit support for foreign tables
Previous Message Rajeev rastogi 2014-03-27 08:12:38 datistemplate of pg_database does not behave as per description in documentation