问题背景:
接用户报障,数据库每天晚上正常的expdp备份,从2天前开始出现奇怪的备份报错LPX-00217: invalid character 3
问题分析:
检查expdp备份的日志,从2天前晚上开始的备份均出现LPX-00217: invalid character 3的报错,报错均由同一张表"TEST"."TABLE_ASSOCIATION"导出时导致
通过对不开并行以及不开压缩单独expdp导出表,并设置trace=480300进行跟踪,依然发生报错,排除了并行和压缩导致的问题
查看dw导出进程的480300跟踪trc文件,除了看到报错是发生在卸载数据写入dumpfile文件之外,并没有其他明显的报错信息指向
通过全表方式查询以及CATS方式复制数据创建备份表均可以正常完成,没有出现ORA-错误以及数据坏块报错,怀疑有可能是表结构或者数据存储了特殊字符与expdp导出存在冲突。导致报错无效字符3
--CATS复制数据备份正常
create table BACKUPINFO.TABLE_ASSOCIATION_BAK tablespace USERS as select * from TEST.TABLE_ASSOCIATION;
--全表扫描正常
select /*+full(a) */ count(column_name) from TEST.TABLE_ASSOCIATION a;
查看表的列定义,发现列PK名存在特殊的ASCII值3,4,正常的P,K值分别对应ASCII码值80以及75,列长度应该为2,但当前的列PK长度为4,里面还包含了其他的两位ASCII值3,4
select table_name,column_name, dump(COLUMN_NAME) as charcode
from user_tab_columns
where table_name in ('TABLE_ASSOCIATION')
order by 3;
查看ASCII码表,ASCII值3,4分别对应控制字符3(^C End of text)以及4(^D End of transmission),而expdp卸载数据时无法识别遇到的字符3,导致报无效字符3错判LPX-00217: invalid character 3
问题修复:
1 对表的列PK进行重建,删除无效的控制字符
测试创建测试表删除特殊的控制字符(^C End of text)以及(^D End of transmission)再进行导出,删除特殊字符后可以正常导出没有报错
#创建测试表,正常的PK字段,没有特殊的控制字符
SQL> CREATE TABLE "BACKUP"."TABLE_TEST"
( "ID" VARCHAR2(50),
"LINES" CLOB,
"NAME" VARCHAR2(100),
"TYPE" VARCHAR2(50),
"TYPE" VARCHAR2(50),
"PK" VARCHAR2(512)
);
Table created.
#插入数据
SQL> insert into "BACKUP"."TABLE_TEST" select * from TEST.TABLE_ASSOCIATION;
7944 rows created.
SQL> commit;
Commit complete.
#进行导出
userid=""
directory=backupdir
parallel=1
cluster=n
dumpfile=TABLE_TEST.dat
logfile=TABLE_TEST.log
tables=BACKUP.TABLE_TEST
compression=all
~
--正常导出,没有再遇到报错
expdp parfile=expdp_test.par
Export: Release 11.2.0.4.0 - Production on Tue Jun 27 15:11:04 2023
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "BACKUP"."SYS_EXPORT_TABLE_08": BACKUP/******** parfile=expdp_test.par
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 84 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
. . exported "BACKUP"."TABLE_TEST" 12.29 MB 7944 rows
Master table "BACKUP"."SYS_EXPORT_TABLE_08" successfully loaded/unloaded
******************************************************************************
Dump file set for BACKUP.SYS_EXPORT_TABLE_08 is:
/backup/TABLE_TEST.dat
Job "BACKUP"."SYS_EXPORT_TABLE_08" successfully completed at Tue Jun 27 15:11:08 2023 elapsed 0 00:00:04
2 对表单独采用expdp access_method=external_table方式,通过SQL层导出规避无效字符错误
在Oracle官方DataPump Export (EXPDP) Fails With Error LPX-216 Invalid Character (Doc ID 1302916.1)可以查到类似的expdp采用默认的direct_path方式卸载数据时遇到无效字符报错,,给出的临时规避方法是ACCESS_METHOD=EXTERNAL_TABLE,测试导出同样成功