Solved

Inserting records into table makes UNDOTBS1 very big !

Posted on 2008-10-27
10
612 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
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 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
 
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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Difference in number of minutes between 2 timestamps 16 49
Fastest way to replace data in Oracle 5 62
Oracle Pivot Question 8 58
Creation date for a PDB 5 18
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

813 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

15 Experts available now in Live!

Get 1:1 Help Now