# Postgres: multiple clusters rc.d support



## hopla (Nov 8, 2010)

Hi,

If I want to run multiple Postgres clusters (see below for what I mean by cluster * ) from one Postgres install (standard install from ports), what is the best way to do it?

/usr/local/etc/rc.d/postgresql has options to set a custom data directory. But not multiple directories/clusters. That's understandable, as it would be hard to manage multiple daemons from one rc script.

So, I was thinking of copying /usr/local/etc/rc.d/postgresql to e.g. /usr/local/etc/rc.d/postgresql_cluster2 and renaming all the variables. So then I can set:


```
postgresql_cluster2_enable="YES"
postgresql_cluster2_data="/usr/local/pgsql/cluster2"
```
in /etc/rc.conf.

Sounds good? How are others doing it? (Mind you, I do know about Jails, but I don't want to run Postgres in a Jail because of the sysVipc troubles. Once FreeBSD Jails also separate sysVipc, then it's a no-brainer of course.)

* Postgres cluster (this definition stolen from http://wiki.postgresql.org/wiki/Prioritizing_databases_by_separating_into_multiple_clusters ):


> In this context, "cluster" doesn't mean a cluster of separate machines working together, as is the usual usage. Rather, when talking about PostgreSQL installs a "cluster" is a set of PostgreSQL databases controlled by one postmaster. The cluster shares a postmaster, data directory, background writer, block of shared memory, etc. The same postgresql.conf and pg_hba.conf apply to the entire cluster. All connections to any database in the cluster come in on the same port or unix socket to the postmaster, which starts a backend using the appropriate database in the cluster to service the connection. While it's typical to have only one PostgreSQL cluster on a machine, and most canned installs of PostgreSQL only provide for one cluster, nothing stops you creating more than one.


----------

