Re: vacuumdb maintenance-db??

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Ron <ronljohnsonjr(at)gmail(dot)com>, pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: vacuumdb maintenance-db??
Date: 2022-11-09 21:42:03
Message-ID: 37463.1668030123@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Wed, Nov 9, 2022 at 1:54 PM Ron <ronljohnsonjr(at)gmail(dot)com> wrote:
>> But this raises a different question: when does the postgres database not
>> exist?

> You are giving it too much specialness. Both ALTER DATABASE ... RENAME and
> DROP DATABASE can be used on it.

The template databases aren't all that special either. There is a defense
against dropping them accidentally:

regression=# drop database template1;
ERROR: cannot drop a template database

but you can override that if you really mean it:

regression=# alter database template1 with is_template false;
ALTER DATABASE
regression=# drop database template1;
DROP DATABASE

This might seem pretty scary, but it's intentional, per the comments
in IsPinnedObject:

* Databases are never pinned. It might seem that it'd be prudent to pin
* at least template0; but we do this intentionally so that template0 and
* template1 can be rebuilt from each other, thus letting them serve as
* mutual backups (as long as you've not modified template1, anyway).

regards, tom lane

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Rui DeSousa 2022-11-09 22:12:06 Re: vacuumdb maintenance-db??
Previous Message Ron 2022-11-09 21:36:41 Re: vacuumdb maintenance-db??