HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlModerate

How to rename a PostgreSQL cluster?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqlclusterrenamehow

Problem

I googled and found this old web page, which said just to change the name of the directory. I tried it but it didn't work:

$ pg_lsclusters 
Version Cluster   Port Status Owner    Data directory                     Log file
8.4     main      5432 down   postgres /var/lib/postgresql/8.4/main       /var/log/postgresql/postgresql-8.4-main.log
9.1     main      50420 online postgres /var/lib/postgresql/9.1/main       /var/log/postgresql/postgresql-9.1-main.log$ pg_ctlcluster 9.1 main stop

$ pwd
/var/lib/postgresql/9.1

$ ls
main

$ mv main oldmain

$ pg_ctlcluster 9.1 oldmain start
Error: specified cluster does not exist


PostgreSQL 9.1.4, Ubuntu 11.10

Solution

Update: version 166 of the postgresl-common package added pg_renamecluster. See Ilya's new answer about that.

In older versions (including Postgres 9.1.4 on Ubuntu 11.10) the name of a cluster is bound to the name of the data directory in the "Multi-Version/Multi-Cluster PostgreSQL architecture" introduced by Martin Pitt. This is shipped with Debian packages (Debian, Ubuntu and related distributions). For a detailed description of the architecture, see:

/usr/share/doc/postgresql-common/README.Debian.gz


Or browse the file online here.

Other installations do not have all of these features, so some people may be confused when you talk about cluster names.

Just renaming the data directory does not work, because you have to change the directory in/etc/postgresql// accordingly.

And there are a couple of settings in your postgresql.conf, that have to be adjusted, too. Run a grep in the directory to see:

postgres@db:/etc/postgresql/9.1/main$ grep 'main' ./*

Code Snippets

/usr/share/doc/postgresql-common/README.Debian.gz
postgres@db:/etc/postgresql/9.1/main$ grep 'main' ./*

Context

StackExchange Database Administrators Q#21426, answer score: 10

Revisions (0)

No revisions yet.