Ubuntu being a Debian-based system has the ability to run multiple instances of Postgres as you are seeing. Generally unless configured otherwise the first instance started will have the default Postgres port and each subsequent instance will take the next higher port if it is available. These ports can be defined in the config files under
/etc/postgresql/<version>/<cluster>/ so that they don't change should you need to but I'd actually need to. In fact a cursory look at the
/etc/init.d/postgresql would also show you that you can set environment variables through
The package managers were even nice enough to include
/usr/share/doc/postgresql-common/README.Debian.gz which has a section that quickly explains how the cluster management is handled including the
pg_lsclusters command which will give you the Postgres version and port number along with other nice details about each configured cluster.
To answer question in comment regarding stopping an instance... You can edit the
start.conf file under
/etc/postgresql/<version>/<cluster>/ and change it from auto to disabled or manual. To quote the default
start.conf file itself...
# Automatic startup configuration
# auto: automatically start/stop the cluster in the init script
# manual: do not start/stop in init scripts, but allow manual startup with
# disabled: do not allow manual startup with pg_ctlcluster (this can be easily
# circumvented and is only meant to be a small protection for