暂无图片
救命!!!4TB的大表新增字段加了一晚上没完成
我来答
分享
刘广
2021-11-12
救命!!!4TB的大表新增字段加了一晚上没完成
暂无图片 25M

表数据量有2亿,表大小加上BLOB的大字段大小加起来有近4TB。

Oracle 11.2.0.1单机

Windows Server 2008 R2

截止现在,已经8个小时了还没完成。

SQL如下:

alter table t_photo add zpsj date default  sysdate not null;

执行期间,整个表都锁了,查都查不了,11g新特性不是可以不影响吗?


哪位专家知道有没有优化的办法呢,由于业务要恢复,已经终止了。

我来答
添加附件
收藏
分享
问题补充
3条回答
默认
最新
你好我是李白

根据Oracle官方文档,直到Oracle 12.1.0.1的New Feature Guide才有下面描述:

The default values of columns are maintained in the data dictionary for columns
specified as NULL.
Adding new columns with DEFAULT values no longer requires the default value to be
stored in all existing records. This not only enables a schema modification in
sub-seconds and independent of the existing data volume, it also does not consume
any space.

详细参考下面链接2.5.5.5小节

https://docs.oracle.com/database/121/NEWFT/chapter12101.htm#FEATURENO09742

而11.2的Administrator Guide描述如下:

If a new column is added to a table, the column is initially NULL unless you specify the
DEFAULT clause. When you specify a default value, the database immediately updates
each row with the default value. Note that this can take some time, and that during the
update, there is an exclusive DML lock on the table. For some types of tables (for
example, tables without LOB columns), if you specify both a NOT NULL constraint and
a default value, the database can optimize the column add operation and greatly
reduce the amount of time that the table is locked for DML.  


所以,这个新特性在11g中其实并不存在,根据11.2的Administrator Guide描述,只有某些表(不包含LOB列),如果你同时指定新增列有NOT NULL约束与DEFAULT VALUE,会大大减少表锁定DML时间。


所以,还是要参考官方文档,以及在做之前进行测试环境1:1测试为上策啊。

暂无图片 评论
暂无图片 有用 2
暂无图片
Uncopyrightable

show code?

暂无图片 评论
暂无图片 有用 0
不太冷

一般可以新建表,数据存过去再重命名回来,比较稳妥

暂无图片 评论
暂无图片 有用 0
回答交流
提交
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~
暂无图片墨值悬赏