I just had to guide one of our DBA this morning.
How to get free of segments in SYSTEM tablespace :
- tables
SQL> select owner, table_name from dba_tables where tablespace_name=’SYSTEM’ and owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
OWNER TABLE_NAME
—– ———-
SCOTT TSQL> alter table scott.t move tablespace users;
Table altered.
SQL> select owner, table_name from dba_tables where tablespace_name=’SYSTEM’ and owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
no rows selected
If the table has a LONG datatype, than I need to exp/drop/create/imp the table
SQL> select owner, table_name from dba_tables where tablespace_name=’SYSTEM’ and owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
OWNER TABLE_NAME
—– ———-
SCOTT TSQL> alter table scott.t move tablespace users;
alter table scott.t move tablespace users
*
ERROR at line 1:
ORA-00997: illegal use of LONG datatypeSQL> ! exp file=t.dmp tables=t userid=scott/tiger
Export: Release 10.2.0.2.0 – Production on Mon Aug 14 14:24:29 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 – Production
With the Partitioning, OLAP and Data Mining options
Export done in WE8ISO8859P1 character set and AL16UTF16 NCHAR character setAbout to export specified tables via Conventional Path …
. . exporting table T 3 rows exported
Export terminated successfully without warnings.SQL> select dbms_metadata.get_ddl(‘TABLE’,’T’,’SCOTT’) from dual;
DBMS_METADATA.GET_DDL(‘TABLE’,’T’,’SCOTT’)
—————————————————————————————————————————————
CREATE TABLE “SCOTT”.”T”
( “L” LONG
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE “SYSTEM”SQL> drop table scott.t;
Table dropped.
SQL> CREATE TABLE “SCOTT”.”T”
2 ( “L” LONG
3 ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
4 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
5 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
6 TABLESPACE “USERS”;Table created.
SQL> ! imp file=t.dmp tables=t userid=scott/tiger ignore=y
Import: Release 10.2.0.2.0 – Production on Mon Aug 14 14:27:05 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 – Production
With the Partitioning, OLAP and Data Mining optionsExport file created by EXPORT:V10.02.01 via conventional path
import done in WE8ISO8859P1 character set and AL16UTF16 NCHAR character set
. importing SCOTT’s objects into SCOTT
. importing SCOTT’s objects into SCOTT
. . importing table “T” 3 rows imported
Import terminated successfully without warnings.
- Indexes
SQL> select owner, index_name from dba_indexes where tablespace_name=’SYSTEM’ and owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
OWNER INDEX_NAME
—– ———-
SCOTT ISQL> alter index scott.i rebuild tablespace users;
Index altered.
SQL> select owner, index_name from dba_indexes where tablespace_name=’SYSTEM’ and owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
no rows selected
- lob
warning: in 9i you must join with dba_tables to get tablespace_name
SQL> select owner, table_name, column_name from dba_lobs where tablespace_name=’SYSTEM’ and owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
OWNER TABLE_NAME COLUMN_NAME
—– ———- ———–
SCOTT T CSQL> alter table scott.t move lob(c) store as (tablespace users);
Table altered.
SQL> select owner, table_name, column_name from dba_lobs where tablespace_name=’SYSTEM’ and owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
no rows selected
- table partition
SQL> select table_owner, table_name, partition_name from dba_tab_partitions where tablespace_name=’SYSTEM’ and table_owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
TABLE_OWNER TABLE_NAME PARTITION_NAME
———– ———- ————–
SCOTT T P1SQL> alter table scott.t move partition p1 tablespace users;
Table altered.
SQL> select table_owner, table_name, partition_name from dba_tab_partitions where tablespace_name=’SYSTEM’ and table_owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
no rows selected
- index partition
SQL> select index_owner, index_name, partition_name from dba_ind_partitions where tablespace_name=’SYSTEM’ and index_owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
INDEX_OWNER INDEX_NAME PARTITION_NAME
———– ———- ————–
SCOTT I SYS_P32SQL> alter index scott.i rebuild partition SYS_P32 tablespace users;
Index altered.
SQL> select index_owner, index_name, partition_name from dba_ind_partitions where tablespace_name=’SYSTEM’ and index_owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
no rows selected
- table subpartition
SQL> select table_owner, table_name, subpartition_name from dba_tab_subpartitions where tablespace_name=’SYSTEM’ and table_owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
TABLE_OWNER TABLE_NAME SUBPARTITION_NAME
———– ———- ——————————
SCOTT T SYS_SUBP30SQL> alter table scott.t move subpartition SYS_SUBP30 tablespace users;
Table altered.
SQL> select table_owner, table_name, subpartition_name from dba_tab_subpartitions where tablespace_name=’SYSTEM’ and table_owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
no rows selected
- index subpartition
SQL> select index_owner, index_name, subpartition_name from dba_ind_subpartitions where tablespace_name=’SYSTEM’ and index_owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
INDEX_OWNER INDEX_NAME SUBPARTITION_NAME
———– ———- ——————————
SCOTT I SYS_SUBP31SQL> alter index scott.i rebuild subpartition SYS_SUBP31 tablespace users;
Index altered.
SQL> select index_owner, index_name, subpartition_name from dba_ind_subpartitions where tablespace_name=’SYSTEM’ and index_owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
no rows selected
- IOT
SQL> select owner, table_name, index_name, index_type from dba_indexes where tablespace_name=’SYSTEM’ and owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
OWNER TABLE_NAME INDEX_NAME INDEX_TYPE
—– ———- —————– ———-
SCOTT T SYS_IOT_TOP_10406 IOT – TOPSQL> alter table scott.t move tablespace users;
Table altered.
SQL> select owner, table_name, index_name, index_type from dba_indexes where tablespace_name=’SYSTEM’ and owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
no rows selected
- IOT Overflow
SCOTTSQL> select owner, table_name, iot_name, iot_type from dba_tables where tablespace_name=’SYSTEM’ and owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
OWNER TABLE_NAME IOT_NAME IOT_TYPE
—– —————— ——– ————
SCOTT SYS_IOT_OVER_10406 T IOT_OVERFLOWSQL> alter table scott.t move overflow tablespace users;
Table altered.
SQL> select owner, table_name, iot_name, iot_type from dba_tables where tablespace_name=’SYSTEM’ and owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
no rows selected
- cluster
I did not find out yet 🙁 Probably not possible, so use exp+drop+create+imp as for long - nested tables
warning: according to the sql reference manual (not tested), in 9i, the nested table was moved with the parent table automatically
SQL> select owner, table_name from dba_tables where nested=’YES’ and tablespace_name=’SYSTEM’ and owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
OWNER TABLE_NAME
—– ———-
SCOTT CTTSQL> alter table scott.ctt move tablespace users;
Table altered.
SQL> select owner, table_name from dba_tables where nested=’YES’ and tablespace_name=’SYSTEM’ and owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
no rows selected
- Lob partitions and subpartitions
This is getting tricky… I did not achieve to change the default tablespace specification for lob, nor to change a HASH partition. Again, when all failed, use exp/drop/create/imp
SQL> select owner, table_name, column_name from dba_lobs where tablespace_name=’SYSTEM’ and owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
OWNER TABLE_NAME COLUMN_NAME
—– ———- —————–
SCOTT T CSQL> alter table scott.t move lob(c) store as (tablespace users);
alter table scott.t move lob(c) store as (tablespace users)
*
ERROR at line 1:
ORA-14511: cannot perform operation on a partitioned objectSQL> select table_owner,table_name,column_name,partition_name from dba_lob_partitions where tablespace_name=’SYSTEM’ and table_owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
TABLE_OWNER TABLE_NAME COLUMN_NAME PARTITION_NAME
———– ———- ———– ————–
SCOTT T C P1SQL> alter table scott.t move partition p1 lob(c) store as (tablespace users);
Table altered.
SQL> select table_owner,table_name,column_name,partition_name from dba_lob_partitions where tablespace_name=’SYSTEM’ and table_owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
no rows selected
SQL> select owner, table_name, column_name from dba_lobs where tablespace_name=’SYSTEM’ and owner not in (‘SYS’,’SYSTEM’,’OUTLN’);
OWNER TABLE_NAME COLUMN_NAME
—– ———- —————–
SCOTT T C
the table was ranged partitioned. With a hash partition, i would get an ORA-22877
SQL> alter table scott.t move partition sys_p47 lob(c) store as (tablespace users);
alter table scott.t move partition sys_p47 lob(c) store as (tablespace users)
*
ERROR at line 1:
ORA-22877: invalid option specified for a HASH partition or subpartition of a LOB column
The DBA also wanted to separate indexes and tables for tuning IOs. I had to redirect him to the doc :
Performance Tuning Guide
One popular approach to manual I/O distribution suggests separating a frequently used table from its index. This is not correct.
well, he shows me his Oracle 9i Tuning Course, Chapter 3, Slice 6, put table and indexes on different tablespaces… Ok, this is not a new thema, just google to find explanations !
SQL> alter table scott.t move partition sys_p47 lob(c) store as (tablespace users);
alter table scott.t move partition sys_p47 lob(c) store as (tablespace users)
*
ERROR at line 1:
ORA-22877: invalid option specified for a HASH partition or subpartition of a LOB column
It was an interesting issue, i was pretty sure, your syntax is valid ( at least, i couldn’t remember any restriction for hash partitions). After short search i stumbled upon Bug 5338698. Switched undo management to manual (a trap again – rollback tablespace shouldn’t be ASSM) – and move works indeed…
Hopefully, will be fixed …
Regarding your post – nice case study, will sure bookmark it(can never remember all that differences for lobs, nested tables, partitions etc)
Best regards
Maxim
Pingback: Laurent Schneider » How to get rid of corrupted blocks without a backup
Pingback: To shrink or to move – Laurent Schneider