Skip to Main Content
  • Questions
  • alter column of a huge table 300million records with partitions

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, padmaja.

Asked: December 03, 2014 - 2:40 pm UTC

Last updated: December 03, 2014 - 8:06 pm UTC

Version: 10.2.0

Viewed 10K+ times! This question is

You Asked

Hello Tom,

Can you explain steps to take to alter monthly partitioned table which has 300million records. I need to alter table column from varchar2(30) to varchar2(50) .
This column is not A key column.
I am new to dba. My question is ' is it ok to just execute command
ALTER TABLE EMP
MODIFY (ENAME VARCHAR2(50) );
do i need to do any thing else...

I have tested this on 3 months partitioned data of 900000 records worked ok.

Thank you for your time..
Padmaja

and Tom said...

that alter doesn't have to touch any of the data. It won't touch the table, just the table metadata.

go for it - best to test in test first as always - but it won't generate undo/redo or lock the table for an extended period of time (it'll lock the table briefly to update the metadata and invalidate stuff)

big_table%ORA11GR2> desc big_table
 Name                                     Null?    Type
 ---------------------------------------- -------- ----------------------------
 ID                                       NOT NULL NUMBER
 OWNER                                    NOT NULL VARCHAR2(30)
 OBJECT_NAME                              NOT NULL VARCHAR2(30)
 SUBOBJECT_NAME                                    VARCHAR2(30)
 OBJECT_ID                                NOT NULL NUMBER
 DATA_OBJECT_ID                                    NUMBER
 OBJECT_TYPE                                       VARCHAR2(19)
 CREATED                                  NOT NULL DATE
 LAST_DDL_TIME                            NOT NULL DATE
 TIMESTAMP                                         VARCHAR2(19)
 STATUS                                            VARCHAR2(7)
 TEMPORARY                                         VARCHAR2(1)
 GENERATED                                         VARCHAR2(1)
 SECONDARY                                         VARCHAR2(1)

big_table%ORA11GR2> select count(*) from big_table;

  COUNT(*)
----------
   1000000

big_table%ORA11GR2> @mystat undo
big_table%ORA11GR2> set echo off

STAT_NAME                                                             VALUE
---------------------------------------------------------------- ----------
undo change vector size                                                 756

16 rows selected.

big_table%ORA11GR2> @mystat redo
big_table%ORA11GR2> set echo off

STAT_NAME                                                             VALUE
---------------------------------------------------------------- ----------
redo entries                                                              7
redo size                                                              2848
redo subscn max counts                                                    1
redo synch time (usec)                                                  126
redo synch writes                                                         1

33 rows selected.

big_table%ORA11GR2> set timing on
big_table%ORA11GR2> alter table big_table modify object_type varchar2(50);

Table altered.

Elapsed: 00:00:00.07
big_table%ORA11GR2> set timing off
big_table%ORA11GR2> @mystat undo
big_table%ORA11GR2> set echo off

STAT_NAME                                                             VALUE
---------------------------------------------------------------- ----------
undo change vector size                                                1896

16 rows selected.

big_table%ORA11GR2> @mystat redo
big_table%ORA11GR2> set echo off

STAT_NAME                                                             VALUE
---------------------------------------------------------------- ----------
redo entries                                                             15
redo size                                                              6356
redo subscn max counts                                                    1
redo synch time (usec)                                                  571
redo synch writes                                                         2

33 rows selected.


the undo/redo for the above was for the data dictionary changes, the table itself wasn't really touched...

Is this answer out of date? If it is, please let us know via a Comment