如何在Ubuntu 18.04上升级到PostgreSQL 11?

15
如标题所示,我想将我的 postgresql-10 升级到 postgresql-11
我正在使用 ubuntu-18.04
3个回答

26

你可以关注这篇博客在Ubuntu上设置PostgreSQL-11。我发现它很容易和简单。

在你的Ubuntu机器上添加PostgreSQL软件包仓库。

echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main 11" | sudo tee /etc/apt/sources.list.d/pgsql.list

添加 PostgreSQL 软件包仓库的 GPG 密钥:

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
更新APT并安装postgresql-11
sudo apt update && sudo apt install postgresql-11

出现"Invalid operation postgresql-11"错误。 - Zia Ul Rehman Mughal
11
这难道不是只安装了第二个实例,并将与第一个同时运行吗? - dangel
4
@dangel,可以的。我按照这个教程操作,成功移除了第一个版本:https://www.paulox.net/2019/05/28/upgrading-postgresql-from-version-10-to-11-on-ubuntu-19-04-disco-dingo/。 - Noah Martin
此解决方案不适用于Ubuntu 18.04,因为postgresql-11不是18.04存储库的一部分。 - Ubaid Qureshi

13

将Postgres升级到最新版本(目前为13)或中间版本(例如11),应通过运行以下命令完成:

sudo apt install postgresql-common
sudo sh /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh

这是在https://wiki.postgresql.org/wiki/Apt上记录的。这将在您的计算机上运行一个bash脚本。如果您希望手动运行步骤,请参阅那里。
一旦您安装了Postgres,在Ubuntu上进行升级的最简单方法是使用pg_upgradecluster
备份您的数据。您将删除数据库,所以不要冒险!
sudo -u postgres pg_dumpall > all.sql
  1. 升级。
// Install latest Postgres. Use `postgresql-11` for v11 instead of `postgresql` for latest.   
sudo apt-get install -y postgresql
    
// The install sets up a cluster, which needs then to be removed for the upgrade. 
// Stop and remove the newly installed cluster. Use `11` instead of `13` for v11
sudo pg_dropcluster 13 main --stop
    
// Upgrade the db. Takes the OLD version and OLD schema as required arguments
sudo pg_upgradecluster 10 main
    
// Test. Once you are satisfied, remove OLD cluster.
sudo pg_dropcluster 10 main

非常有用的回复!我错过了安装新版本的一些扩展(postgis),在升级过程中出现了许多错误。安装扩展包,然后运行dropcluster,再次运行upgradecluster解决了问题! - peschü

-2

使用此命令:

sudo apt update && sudo apt install postgresql-11

9
PostgreSQL 11 不包含在 18.04 软件库中。 - dangel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接