如何在不丢失 openproject 数据的情况下将 postgresql 数据库从 10 升级到 12 [英] How to upgrade postgresql database from 10 to 12 without losing data for openproject

查看:52
本文介绍了如何在不丢失 openproject 数据的情况下将 postgresql 数据库从 10 升级到 12的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 OpenProject 管理软件安装了默认的 postgresql 10.目前 postgresql DB 是 12,它有很多新功能.

My OpenProject management software is installed with default postgresql 10. Currently the postgresql DB is 12, It is having lot of new features.

我想在不丢失数据库中的数据的情况下升级我的 Postgres 数据库.我的系统是 ubuntu 18.04 并托管了 openproject.

I want to upgrade my Postgres DB without losing the data in the DB. My system is ubuntu 18.04 and hosted openproject.

我在网上搜索,找不到升级 postgresql 的步骤.

I searched the internet and could not find a step by step to upgrade postgresql.

你能指导我安装新数据库吗,所有数据都应该在新数据库中.感谢您的帮助.

Can you please guide me to install new DB and all data should be in the new DB. thanks for your help.

推荐答案

A) 首先为此创建所有数据库的备份(如果不需要备份,可以从 B 继续)

  1. 以 postgres 用户身份登录

    sudo su postgres

  1. 为所有数据库中的所有数据创建一个备份 .sql 文件

    pg_dumpall > backup.sql

B) 升级到 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 版本的端口.

     sudo vim /etc/postgresql/12/main/postgresql.conf
     #change port to 5432
     sudo vim /etc/postgresql/10/main/postgresql.conf
     #change port to 5433

  1. 启动 postgresql 服务

     sudo systemctl start postgresql.service

  1. 以 postgres 用户身份登录

     sudo su postgres

  1. 检查您的新 postgres 版本

     psql -c "SELECT version();"

  1. 运行生成的新集群脚本

     ./analyze_new_cluster.sh

  1. 以普通(默认用户)用户身份返回并清理旧版本的烂摊子

     sudo apt-get remove postgresql-10 postgresql-server-dev-10
     #uninstalls postgres packages
     sudo rm -rf /etc/postgresql/10/
     #removes the old postgresql directory
     sudo su postgres
     #login as postgres user
     ./delete_old_cluster.sh
     #delete the old cluster data

  1. 恭喜!您的 postgresql 版本现已升级,如果在 B 中一切正常,我们不必应用备份,因为我们已经将数据从旧版本迁移到新版本,备份以防万一出现问题.

注意:根据您的要求更改 postgresql.conf 和 pg_hba.conf

NOTE: Change the postgresql.conf and pg_hba.conf as per your requirement

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

PS: Feel free to comment your issues, suggestions or anyother modifications you would like to suggest

这篇关于如何在不丢失 openproject 数据的情况下将 postgresql 数据库从 10 升级到 12的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆