Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle 11g how to estimate needed TEMP tablespace?

We do an initial bulk load of some tables (both, source and target are Oracle 11g). The process is as follows: 1. truncate, 2. drop indexes (the PK and a unique index), 3. bulk insert, 4. create indexes (again the PK and the unique index). Now I got the following error:

alter table TARGET_SCHEMA.MYBIGTABLE
add constraint PK_MYBIGTABLE primary key (MYBIGTABLE_PK)
ORA-01652: unable to extend temp segment by 128 in tablespace TEMP

So obviously TEMP tablespace is to small for PK creation (FYI the table has 6 columns and about 2.2 billion records). So I did this:

explain plan for
select line_1,line_2,line_3,line_4,line_5,line_6,count(*) as cnt
from SOURCE_SCHEMA.MYBIGTABLE
group by line_1,line_2,line_3,line_4,line_5,line_6;

select * from table( dbms_xplan.display );
/*
-----------------------------------------------------------------------------------------------
| Id  | Operation          | Name             | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
-----------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |                  |  2274M|    63G|       |    16M  (2)| 00:05:06 |
|   1 |  HASH GROUP BY     |                  |  2274M|    63G|   102G|    16M  (2)| 00:05:06 |
|   2 |   TABLE ACCESS FULL| MYBIGTABLE       |  2274M|    63G|       |   744K  (7)| 00:00:14 |
-----------------------------------------------------------------------------------------------
*/

Is this how to tell how much TEMP tablespace will be needed for PK creation (102 GB in my case)? Or would you make the estimate differently?

Additional: The PK only exists on the target system. But fair point, so I run your query on target PK:

explain plan for
select MYBIGTABLE_PK 
from TARGET_SCHEMA.MYBIGTABLE
group by MYBIGTABLE_PK ;

-------------------------------------------------------------------------------------------
| Id  | Operation          | Name                 | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |                      |     1 |    13 |     3  (34)| 00:00:01 |
|   1 |  HASH GROUP BY     |                      |     1 |    13 |     3  (34)| 00:00:01 |
|   2 |   TABLE ACCESS FULL| MYBIGTABLE           |     1 |    13 |     2   (0)| 00:00:01 |
-------------------------------------------------------------------------------------------

So how would I have to read this now?

like image 620
BaseBallBatBoy Avatar asked Nov 13 '22 01:11

BaseBallBatBoy


1 Answers

This is a good question.

First, If you create the following primary key

alter table TARGET_SCHEMA.MYBIGTABLE 
     add constraint PK_MYBIGTABLE primary key (MYBIGTABLE_PK)

then you should query

explain plan for 
     select PK_MYBIGTABLE 
     from SOURCE_SCHEMA.MYBIGTABLE 
     group by PK_MYBIGTABLE 

To get an estimate (make sure you gather stats exec dbms_stats.gather_table_stats('SOURCE_SCHEMA','MYBIGTABLE').

Second , you can query V$TEMPSEG_USAGE to see how much temp blocks were consumed before you got thrown and v$session_longops to see how much of the total process you finished.

Oracle docs suggests creating a dedicated temp tablespace for the process to not disturb any other operations.

Please post an edit if you find a more accurate solution.

like image 121
haki Avatar answered Nov 15 '22 06:11

haki