我的OpenProject管理软件安装了默认的postgresql 10.

我想升级我的Postgres数据库而不丢失数据库中的数据.

我在网上搜索,找不到一个逐步升级postgresql的方法.

请你指导我安装新的数据库,所有数据都应该在新的数据库中.

推荐答案

A) First create a backup of all the databases for that (You can continue from B if you dont need a backup)

  1. 以postgres用户身份登录
sudo su postgres
  1. 创建备份.所有数据库中所有数据的sql文件
pg_dumpall > backup.sql

B) Upgrade to PostgreSQL12

  1. 更新软件包并安装postgres 12
sudo apt-get update
sudo apt-get install postgresql-12 postgresql-server-dev-12
  1. 停止postgresql服务
sudo systemctl stop postgresql.service
  1. 迁移数据
/usr/lib/postgresql/12/bin/pg_upgrade \
--old-datadir=/var/lib/postgresql/10/main \
--new-datadir=/var/lib/postgresql/12/main \
--old-bindir=/usr/lib/postgresql/10/bin \
--new-bindir=/usr/lib/postgresql/12/bin \
--old-options '-c config_file=/etc/postgresql/10/main/postgresql.conf' \
--new-options '-c config_file=/etc/postgresql/12/main/postgresql.conf'
  1. 切换到普通用户
exit
  1. 交换旧版本和新版本的postgres端口.
#change port to 5432
sudo vim /etc/postgresql/12/main/postgresql.conf
#change port to 5433
sudo vim /etc/postgresql/10/main/postgresql.conf
  1. 启动postgresql服务
sudo systemctl start postgresql.service
  1. 以postgres用户身份登录
sudo su postgres
  1. 判断你的新postgres版本
psql -c "SELECT version();"
  1. 运行生成的新集群脚本
./analyze_new_cluster.sh
  1. 以普通(默认用户)用户身份返回,并清理旧版本的混乱
#uninstalls postgres packages     
sudo apt-get remove postgresql-10 postgresql-server-dev-10
#removes the old postgresql directory
sudo rm -rf /etc/postgresql/10/
#login as postgres user
sudo su postgres
#delete the old cluster data
./delete_old_cluster.sh
  1. 恭喜!您的postgresql版本现在已升级,如果B中一切正常,我们不必应用备份,因为我们已经将数据从旧版本迁移到了新版本,备份只是为了防止出现任何问题.

NOTE:.更改postgresql.形态和pg_hba.按您的要求配置

PS:请随意 comments 您的问题、建议或任何其他您想建议的修改

Postgresql相关问答推荐

Postgs SQL用于比较两个表之间的数据并填充到目标中

使用Spring data jpa和CriteriaQuery在jsonb列中搜索操作

Select 二维数组中的特定元素PostgreSQL

PostgreSQL:重新创建主键值以匹配记录计数

处理Ruust-DIESEL中的Jsonb PostgreSQL列

Postgres数据库系统已准备好接受连接和docker compose

如何使 Postgres 优化引擎具有确定性

如何计算过滤器中的百分比

PostgreSQL - 继承表的常见自动增量

使用 ON CONFLICT 从 INSERT 返回行,无需更新

运算符不存在:integer = integer[] 在使用 ANY 的查询中

在执行 postgresql 函数时提交事务

带有初始数据的 docker postgres 不会在提交中持久化

Postgres 图像未创建数据库

Postgresql - 在 Big Data 库中使用数组的性能

并发刷新materialized视图

在 PL/pgSQL 中声明行类型变量

在 postgreSQL 中更改序列名称

如何在 psql 中设置默认显示模式

如何更改 PostgreSQL 中的 REFERENCES?