安装 Postgresql 9.6 而不是 Postgresql 12

安装 Postgresql 9.6 而不是 Postgresql 12

我正在运行 Ubuntu 18.04。当我想安装 PostgreSQL 数据库服务器包时,我得到的是默认版本 12。
我尝试按照多个说明安装所需的版本 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

我的问题

apt-get install 的输出显示“9.6”。为什么 的输出不是SELECT version();这样?

答案1

Ubuntu 确实支持同时运行多个 PostgreSQL 实例,可能有不同的版本,但需要一些手动管理。

完成后 apt-get install postgresql-9.6,PostgreSQL 9.6 二进制文件就安装好了,但要实际运行实例/服务,需要执行如下命令:

$ sudo pg_createcluster 9.6 main

pg_createcluster参见 pg_lsclusterspg_wrapper更多信息请参见手册页。

如果您不需要 PostgreSQL 12,您可能还想手动删除它。

答案2

我最终根据 Daniel Vérité 的回答成功解决了这个问题。9.6 集群已经存在,postgres 12 集群也已经存在。

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

多谢!

相关内容