Keith John Hutchison
Keith John Hutchison

Reputation: 5277

How to explicitly start one version of postgres on startup?

I manage an old ubuntu server 12.04 that has postgresql 9.1 on it.

I successfully installed postgresql 9.6 for a new application that we want to use.

The problem I'm facing is for some reason

service postgresql start
* Starting PostgreSQL 9.1 database server                                                                                                       
[ OK ] 
* Starting PostgreSQL 9.6 database server 
[ OK ]

starts the 9.1 server and the 9.6 server.

I'm looking for a way to only start the 9.6 server on the default port.

I've looked at /etc/inid.d/postgresql. This extract looks like it might be the key.

# versions can be specified explicitly
if [ -n "$2" ]; then
    versions="$2 $3 $4 $5 $6 $7 $8 $9"
else
    get_versions
fi

looks like I just have to pass in the version on the command line.

service postgresql start 9.6

and yes ... it worked.

So my question is ... how do I make this automatically happen in the instance of a reboot?

Upvotes: 3

Views: 5554

Answers (2)

PaxPrz
PaxPrz

Reputation: 1928

If you have multiple instance of postgresql, you can start just one service by following command:

systemctl start postgresql@<version>-main

For example, I have version 11, 12 & 13 installed in my PC. I can start version 13 only by:

systemctl start postgresql@13-main

OR using service command

service postgresql@13-main start

Upvotes: 5

Keith John Hutchison
Keith John Hutchison

Reputation: 5277

One solution is to remove 9.1

apt-get --purge remove postgresql-9.1

and change the port in the config file for 9.6 to 5432

su postgres
psql

psql (10.3 (Ubuntu 10.3-1.pgdg14.04+1), server 9.6.8)
Type "help" for help.

postgres=# 
    SHOW config_file;
config_file                
------------------------------------------
/etc/postgresql/9.6/main/postgresql.conf
(1 row)
    \quit
exit
vi /etc/postgresql/9.6/main/postgresql.conf
    /port

change the port to 5432 and write and close the config file

    :wq

service postgresql stop
service postgresql start

Upvotes: 2

Related Questions