8

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

4
  • I'm confused. A PostgreSQL cluster does not have a name.
    – user1822
    Jul 24, 2012 at 22:07
  • @a_horse_with_no_name, I added pg_lsclusters output above. I'm new to this, but I believe you can have multiple clusters, and you have to identify which cluster you are talking to by its name (or maybe directory name, I'm not sure). Jul 24, 2012 at 23:43
  • @a_horse_with_no_name: Cluster names are specific to multi-version/multi-cluster architecture in Debian, Ubuntu & friends. I hope my answer can shed some light on this. Jul 25, 2012 at 3:28
  • @ErwinBrandstetter: thanks I didn't know that. You live and learn ;)
    – user1822
    Jul 25, 2012 at 6:38

2 Answers 2

10

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/<version>/<cluster> 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' ./*
3
  • Thanks @Erwin_Brandstetter! Nice detailed answer with useful link to Martin Pitt's architecture. I will give your answer a try. Jul 25, 2012 at 15:09
  • The link to people.debian.org/~mpitt/architecture.html no longer works
    – user1822
    Jun 19, 2017 at 7:30
  • @a_horse_with_no_name: Thanks, I updated accordingly. Jun 19, 2017 at 12:39
7

Debian/Ubuntu has a pg_renamecluster command (available in "postgresql-common" package) which does just what you need:

  • renames config and data directory,
  • renames existing log files,
  • changes a number of settings in the postgresql.conf.

Man page.

Note for Systemd users: generators are used to create unit file (i.e. service) for each PostgreSQL cluster. So after the pg_renamecluster you should reload Systemd config, enable and start new service: sudo systemctl daemon-reload sudo systemctl enable postgresql@<version>-<new cluster name>.service sudo systemctl start postgresql

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.