因为我们公司在最开始安装数据库的时候使用的是apt在线安装的postgresql9.6的数据库,最近服务要上容器化,所以需要迁移数据库,但是由于是apt安装的不同于源码安装的数据库迁移方式。
首先我这次测试用的是ubuntu16.04 数据库版本是postgresql9.6
迁移数据库的前提是数据库版本跟服务器系统要跟迁移之前的信息一致
然后在新的机器上按照apt安装的方式安装跟之前相同版本的postgresql数据库
1、安装postgreSQL
sudo add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main"
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.6
安装完后修改postgresql的配置文件
vim /etc/postgresql/9.6/main/postgresql.conf
修改data_directory = '/opt/pgdata' pgdata是你从其他服务器上拉取过来的目录
然后systemctl restart postgresql
可能遇到的问题
psql: FATAL: database locale is incompatible with operating system
DETAIL: The database was initialized with LC_COLLATE "zh_CN.UTF-8", which is not recognized by setlocale().
HINT: Recreate the database with another locale or install the missing locale.
解决方案
localedef -f UTF-8 -i zh_CN zh_CN.UTF-8
然后再重启postgresql后,查看数据库信息就为新的数据库信息