I wanted to switch over my data directory for postgres DB from the main partition to save some space. After doing some investigation – here’s what I did in order to achieve the results:
1. Create a new DB Cluster – this would setup the config files and directory structure to the required location
sudo pg_createcluster -d /var/db/postgres 9.1 custom
This would also setup a configuration named “custom” under the version 9.1. Now the directory /etc/postgresql/9.1 contains two directories – “main” and “custom”. The directories have their specific configuration files – so that the ports, data directories, etc can be setup for each of these configurations. The port number for the custom cluster will have default port 5433 (could be different if you had setup more clusters on the box) and the main cluster has default Postgres Port 5432.
2. To connect to the default cluster using the postgres user, type in
3. To connect to the new custom cluster using postgres user, type in
The changes that you make in either of these clusters will be independent of the other. This way – you can have two different clusters running on the same server and have their independent databases, data directories, port numbers, etc.