Change and initialize Postgresql 9.3 default data and log directories on Ubuntu 12.04 LTS

The reason of this error: "Error: cluster configuration already exists" is that the name main is already assigned to the cluster that gets initially created.

If you haven't any data in it, you may drop it before creating your own with:

pg_dropcluster 9.3 main

This will also have the desirable effect that your new cluster will be assigned the port number 5432 instead of the non-default 5433.

Whether you use a direct mount path or a symbolic link doesn't really matter, but note that configuration files will be created in /etc/postgresql/<version>/<clustername>/ outside of the data directory.

According to its manpage, pg_createcluster command expects the options before version and name, so the command would be:

pg_createcluster -d /mnt/pgdata/data -l /mnt/pgdata/log --start-conf auto 9.3 main

Also having the logfile in /mnt/pgdata makes it unreachable to logrotate, so it will grow endlessly. You may look at /etc/logrotate.d/postgresql-common to see how it's configured to process /var/log/postgresql/*.log