2

I am running Ubuntu 18.04. When I want to install the PostgreSQL database server package I get the default version 12.
I have unsuccessfully tried to follow multiple instructions on how to install the desired version 9.6.

# cat /etc/apt/sources.list.d/pgdg.list  
deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main  
# sudo apt-get install postgresql-9.6
Reading package lists... Done      
Building dependency tree    
Reading state information... Done    
The following additional packages will be installed:    
  postgresql-contrib-9.6  
Suggested packages:  
  libdbd-pg-perl  
The following NEW packages will be installed:  
  postgresql-9.6 postgresql-contrib-9.6  
0 upgraded, 2 newly installed, 0 to remove and 3 not upgraded.  
Need to get 0 B/4,827 kB of archives.  
After this operation, 23.9 MB of additional disk space will be used.  
Do you want to continue? [Y/n] y  
Preconfiguring packages ...  
Selecting previously unselected package postgresql-9.6.  
(Reading database ... 70763 files and directories currently installed.)  
Preparing to unpack .../postgresql-9.6_9.6.17-2.pgdg18.04+1_amd64.deb ...  
Unpacking postgresql-9.6 (9.6.17-2.pgdg18.04+1) ...  
Selecting previously unselected package postgresql-contrib-9.6.  
Preparing to unpack .../postgresql-contrib-9.6_9.6.17-2.pgdg18.04+1_amd64.deb ...  
Unpacking postgresql-contrib-9.6 (9.6.17-2.pgdg18.04+1) ...  
Setting up postgresql-9.6 (9.6.17-2.pgdg18.04+1) ...  
Setting up postgresql-contrib-9.6 (9.6.17-2.pgdg18.04+1) ...  
Processing triggers for postgresql-common (213.pgdg18.04+1) ...  
Building PostgreSQL dictionaries from installed myspell/hunspell packages...  
Removing obsolete dictionary files:  
# service postgresql start
# su postgres 
postgres@ubuntu-vm-template:~$ psql
psql (12.2 (Ubuntu 12.2-2.pgdg18.04+1))  
Type "help" for help.  

postgres=# SELECT version();
                                                              version  
-----------------------------------------------------------------------------------------------------------------------------------  
 PostgreSQL 12.2 (Ubuntu 12.2-2.pgdg18.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0, 64-bit  
(1 row)  
root@ubuntu-vm-template:~# dpkg -l|grep -i postgres
ii  libpq-dev                             12.2-2.pgdg18.04+1                              amd64        header files for libpq5 (PostgreSQL library)
ii  libpq5:amd64                          12.2-2.pgdg18.04+1                              amd64        PostgreSQL C client library
ii  pgdg-keyring                          2018.2                                          all          keyring for apt.postgresql.org
ii  postgresql-12                         12.2-2.pgdg18.04+1                              amd64        object-relational SQL database, version 12 server
ii  postgresql-9.6                        9.6.17-2.pgdg18.04+1                            amd64        object-relational SQL database, version 9.6 server
ii  postgresql-client-12                  12.2-2.pgdg18.04+1                              amd64        front-end programs for PostgreSQL 12
ii  postgresql-client-9.6                 9.6.17-2.pgdg18.04+1                            amd64        front-end programs for PostgreSQL 9.6
ii  postgresql-client-common              213.pgdg18.04+1                                 all          manager for multiple PostgreSQL client versions
ii  postgresql-common                     213.pgdg18.04+1                                 all          PostgreSQL database-cluster manager
ii  postgresql-contrib                    12+213.pgdg18.04+1                              all          additional facilities for PostgreSQL (supported version)
ii  postgresql-contrib-9.6                9.6.17-2.pgdg18.04+1                            amd64        additional facilities for PostgreSQL

My Question

The output of apt-get install says "9.6". Why doesn't the output of SELECT version(); do so?

2
  • Please show dpkg -l|grep -i postgres. It's strange that you have version 12 installed - Ubuntu 18.04 is supposed to ship with version 10 (postgresql-10). Only Ubuntu Focal ships with postgresql-12 from the default Ubuntu repos. – Claudio Kuenzler Apr 21 '20 at 10:48
  • Hi @ClaudioKuenzler, i have appended the output to the description. Cheers Jens – Jens Kisters Apr 22 '20 at 8:08
1

Ubuntu does support multiple instances of PostgreSQL running simultaneously, with possibly different versions, but it needs a bit of manual management.

Once apt-get install postgresql-9.6 is done, PostgreSQL 9.6 binaries are installed, but to have an actual running instance/service, a command like this is required:

$ sudo pg_createcluster 9.6 main

See pg_createcluster, pg_lsclusters and pg_wrapper manpages for more.

You may also want to manually remove PostgreSQL 12 if you don't need it.

0

I finally managed to solve it like this based on the answer of Daniel Vérité. The 9.6 cluster was already existent, so was a postgres 12 cluster.

sudo apt-get remove postgresql-12
pg_dropcluster 12 main
sudo systemctl daemon-reload

Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.