Solved

Inserting records into table makes UNDOTBS1 very big !

Posted on 2008-10-27
10
610 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
  • 4
  • 3
10 Comments
 
LVL 47

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 47

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
 
LVL 47

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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 47

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now