GaussDB中数据库字符编码变更

GBK改UTF8
GaussDB内核版本:Kernel 505.2.T3
IP: 192.168.xx.xx
库: test_gaussdb 兼容模式 :oracle
**

修改前库信息

**

test_gaussdb | test1 | GBK      | C       | C     | =Tc/test1                +| 14 GB  | pg_default
                  |          |          |         |       | test1=CTc/test1       +|        |           
                  |          |          |         |       | gs_catalog=CTc/test1     +|        |           
                  |          |          |         |       | gs_catalog=APm/test1     +|        |           
                  |          |          |         |       | u1_info=CTc/test1     +|        |           
                  |          |          |         |       | u1_info=APm/test1     +|        |           
                  |          |          |         |       | u1_busi=CTc/test1     +|        |           
                  |          |          |         |       | u1_busi=APm/test1     +|        |           
                  |          |          |         |       | u1_mont_01=CTc/test1  +|        |           
                  |          |          |         |       | u1_mont_01=APm/test1  +|        |           
                  |          |          |         |       | u1_fund_01=CTc/test1  +|        |           
                  |          |          |         |       | u1_fund_01=APm/test1  +|        |           
                  |          |          |         |       | u1_scheduler=CTc/test1+|        |           
                  |          |          |         |       | u1_scheduler=APm/test1+|        |           
                  |          |          |         |       | u1_frame=CTc/test1       +|        |           
                  |          |          |         |       | u1_frame=APm/test1       +|        |           
                  |          |          |         |       | u1flow=CTc/test1       +|        |           
                  |          |          |         |       | u1flow=APm/test1       +|        |           
                  |          |          |         |       |

**

操作步骤

**
1、gs_dump导出表结构和数据,转储为utf8编码
gs_dump -E UTF8 test_gaussdb -f /opt/dbbak/test_gaussdb _utf81119.tar -F t > /opt/dbbak/test_gaussdb _utf81119.log 11分多
/按GBK备份/
gs_dump test_gaussdb -f /opt/dbbak/test_gaussdb _gbk81119.tar -F t > /opt/dbbak/test_gaussdb _gbk81119.log 8分钟
2、更改旧库名为 test_gaussdb _bak
/* 如果库有连接需要先kill掉,再变更名称
SELECT CAST(pg_terminate_backend(pid) AS VARCHAR(10)) FROM pg_stat_activity WHERE datname=‘test_gaussdb’;
*/
alter database test_gaussdb rename to test_gaussdb _bak;
3、建utf8编码的新库
create database test_gaussdb owner hs_test1;
检查新创建的库是否为utf8 \l+
4、导入数据
gs_restore /opt/dbbak/test_gaussdb _utf81119.tar -d test_gaussdb > /opt/dbbak/test_gaussdb _utf81119_restore.log

**

导入问题处理

**
1、u1_info.ch_bd_cee表的字段名带双引号,字段名都是大写
2、导入过程中有些表的字段需要扩大

处理:
1、从备份库单独导出表为SQL格式,去掉双引号,扩字段大小,再导入
gs_dump -E UTF8 test_gaussdb _bak -f /opt/dbbak/ch_bd_cee_utf81119.sql -t u1_info.ch_bd_cee
vim /opt/dbbak/ch_bd_cee_utf81119.sql 扩大字段为原来1.5倍 APPPE VARCHAR(1500)
drop table u1_info.ch_bd_cee;
gsql -f /opt/dbbak/ch_bd_cee_utf81119.sql -d test_gaussdb > /opt/dbbak/ch_bd_cee_utf81119_restore.log

2、扩大提示出错的字段,按开发需求为原来的1.5倍

alter table u1_info.version modify err_info VARCHAR(3000);
alter table u1_info.wd_dimap modify dtl_i_code VARCHAR(30);
alter table u1_mont_01.tm_conparam modify pa_name VARCHAR(48);
alter table u1_mont_01.tm_moex modify  idx_name VARCHAR(96);
alter table u1_mont_01.tm_moram modify pm_name VARCHAR(48);
alter table u1_mont_01.tm_conaram modify pa_deflue VARCHAR(200);
alter table u1_busi.tp_pater modify pa_name VARCHAR(72);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值