Solved

Inserting records into table makes UNDOTBS1 very big !

Posted on 2008-10-27
10
624 Views
Last Modified: 2012-08-14
Hello Experts !

I've got two tables in Oracle 10.1g

TableA
16,594,824 records

TableB
0 records, same structure as TableA

I don't have too much free space in my disk, so I need to get tablespace UNDOTBS1 as small as possible.

When I try to insert the 16 millions rows of TableA into TableB like:

INSERT INTO TableB (select * from TableA);

then UNDOTBS1.DBF gets huge, like 7GB.

I set up UNDO_RETENTION in this way:

ALTER SYSTEM SET UNDO_RETENTION = 5;

I thought that doing that, UNDOTBS1.DBF won't get big.

My questions are:

1. Is the size of UNDOTBS1.DBF affected because setting up "ALTER SYSTEM SET UNDO_RETENTION = 5" or setting up "ALTER SYSTEM SET UNDO_RETENTION = 900";

2. Is there any way that UNDOTBS1.DBF and UNDOTBS1 don't grow so much? I know how to shrink UNDOTBS1.DBF after all transactions are commit, but don't know how to prevent it!
0
Comment
Question by:miyahira
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
10 Comments
 
LVL 48

Accepted Solution

by:
schwertner earned 200 total points
ID: 22813894
Setting
ALTER SYSTEM SET UNDO_RETENTION = 5;
you will keep the undo data only 5 minutes,
so you have to expect that in 5 minutes
the UNDO tablespace will shrink.
0
 
LVL 1

Author Comment

by:miyahira
ID: 22813951
> so you have to expect that in 5 minutes the UNDO tablespace will shrink.

It didn't. On the contrary, it got bigger up to 7GB until "INSERT INTO TableB (select * from TableA);" finished
0
 
LVL 48

Expert Comment

by:schwertner
ID: 22814018
Yes, because this happens in that 5 minutes frame.
Only after 5 minutes it will shrink.
It waits for COMMIT or ROLLBACK statement
to decide what to do.
Write ROLLBACK; and it will shrink.
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 48

Expert Comment

by:schwertner
ID: 22814051
So I think it will count the time after COMMIT statement.
Before COMMIT it is possible to get ROLLBACK and so
no entries could be emptied.
0
 
LVL 1

Author Comment

by:miyahira
ID: 22814075
Ok, I got it!

Would you mind suggesting me how to make COMMIT when running this command:

INSERT INTO TableB (select * from TableA);

Should it be using CURSOR in a stored procedure? I wouldn't like to load in memory 16 millions records.

Many thanks.
0
 
LVL 1

Author Comment

by:miyahira
ID: 22814084
I mean: how to make COMMIT every 5 minutes when running this command:
INSERT INTO TableB (select * from TableA);
0
 
LVL 10

Assisted Solution

by:dbmullen
dbmullen earned 200 total points
ID: 22815731
few options:
  1)  use oracle copy command and
            change the copycommit and arraysize until you don't have UNDO issues
             see snippet

  2)  why are you inserting data twice?
            drop table tableb;
            create or replace view tableb as select * from tablea;


set arraysize 100
set copycommit 50
truncate table  TableB ;
COPY FROM username/password@source_db TO username/password@target_db insert  TableB  USING SELECT * FROM  TableA;

Open in new window

0
 
LVL 48

Expert Comment

by:schwertner
ID: 22819560
SELECT statement will load in memory all record, but not all of them
will be there. Do not worry about this.
The suggestion of Dbmullen is OK!
You can also try to use stored procedure and cursor inside.
This has some advantages like possibilities to edit the records
on the fly. Also very good control on the flow.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  â€¦
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Suggested Courses

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question