psql14容器数据库迁移至本地二进制部署的psql14.11

#背景:系统迁移#

方法一:所有环境都是在用情况。
docker exec -it postgres /bin/bash #进去docker部署的pg容器
mkdir back

cd back

pg_dump -h localhost -p 5432 -U postgres -d dataname -s -f table.sql #-s先导出表结构

pg_dump -h localhost -p 5432 -U postgres -d dataname -a -f shuju.sql #-a只导出数据

exit

docker cp postgres:/back/ ./ #c从容器拷贝到宿主机

宿主机执行导入,创建数据库;导入结构,再导入数据:

psql -U postgres 

CREATE DATABASE dclm_account;

exit or \q
psql -h localhost -p 36432 -U postgres -d dataname < table.sql

psql -h localhost -p 36432 -U postgres -d dataname < shuju.sql

导入数据过程中遇到错误:

说是没找到这个函数,这个函数是表结构的一个sql,手工执行提示已存在,

但是postgis安装了,导入数据之前也create extension postgis;

手工执行 select ST_GeomFromText('POINT(30 10)');返回也有值。

#部署文章centos7.5离线安装postgresql14和postgis-CSDN博客

所以弄了半天也没结果。所以做了第二个方法。

方法二:docker部署的在用,二进制新部署的

将docker挂载出来的数据路径的data目录,全部拷贝至新部署的postgresql,

cp前先将二进制部署的postgresql.conf    pg_hba.conf  先备份至上级目录,

因为配置不同不能覆盖。

#cd 到挂载出来的数据目录
pwd

/home/pg/
ls
data

#将data下所有文件打包
tar -cvf data.tar data/

#data.tar 移动至二进制部署路径
mv data.tar /home/psql/14/

#停止psql,删除原有data,解压
systemctl stop postgresql-14

rm -fr data/

tar -xvf data.tar

#更改属主
cd ..
chown -R postgres:postgres 14/

#覆盖配置文件
cd 14
cp pg_hba.conf ./data
cp postgresql.conf ./data

#启动pg
systemctl start postgresql-14

#连接
[root@master data]# psql -U postgres
psql (14.11)
输入 "help" 来获取帮助信息.

postgres=# \l
                                       数据库列表
     名称     |  拥有者  | 字元编码 |  校对规则   |    Ctype    |       存取权限        
--------------+----------+----------+-------------+-------------+-----------------------
 dclm_account | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 postgres     | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 template0    | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
              |          |          |             |             | postgres=CTc/postgres
 template1    | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
              |          |          |             |             | postgres=CTc/postgres
(4 行记录)

postgres=# 

客户端连接查看数据就行。

  • 10
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值