I’m not an oracle expert, but you can also create a table with the records you want keep up.
Something like:
create table pessoa_new as select * from pessoa where idade <= 40;
After that, run a truncate in the table original:
truncate table pessoa
Note that truncate does not create log in oracle, that is, you will not
can do rollback or commit. Once done, it cannot be
undone.
After that, copy the data back to the original table:
alter session set rollback_segment = 'HUGE_RBS';
insert into pessoa as select * from pessoa_new
Or if you prefer, change the name of the new and old table:
alter table pessoa rename to pessoa_old;
alter table pessoa_new rename to pessoa;
In either case, remember rebuild If you choose to rename tables, consider recreating constraints, triggers, etc.
You can limit the query
DELETE FROM pessoa WHERE pessoa.idade > 40 LIMIT 5000
and make a script to run this query in x seconds until no lines exist– lazyFox
Following more or less the same line of reasoning that lazyFox said, this topic here also says, to create batch files and run little by little: http://stackoverflow.com/questions/24785439/deleting-1-millions-rows-in-sql-server
– Gabriel Augusto
The table has fk s that depend on it ? How many records would be in the table ? There are solutions like exporting what will be in an Insert script , truncate in the table and import , open the exclusive bd , turn off the Audit , delete , turn on the Audit and reopen the bd
– Motta
Copy Data that matters to Novatable and delete or rename the Old Table and rename the New Table to Old Table :)
– user60252
@Motta, I mistook me for the chart, she’s 4 fk, and six Eagles, you’d be left with 82 million.
– David
maybe it is better something like : saves the records that should be in scripts of Insert , disables the constraints , gives truncate in the tables , performs the script of (re)Insert , habitita as constrainsts , in any case search in sites like asktom because it has enough material about it.
– Motta
The problem of entering this data again, with the scripts of Insert, is that there are many Inserts to be made, it will take a lot of time. !
– Marcos Henzel
I am far from being a deep connoisseur of Oracle and SQL. However, I think there are two relevant questions: 1) is this removal something that occurs frequently during the operation? 2) Does this removal need to be immediate? I ask this because maybe you can simply mark these records as irrelevant (pending for deletion) and run a trial overnight (or at a low system usage time) to do the removal itself.
– Luiz Vieira
The operation does not occur frequently, but occurs occasionally. Yes the operation needs to be done immediately. Thanks Luiz.
– David
@lazyFox, the hard one I need to remove all at once, and do x and x seconds, splitting 2kk/5k would be 6 minutes, wouldn’t be so bad, but wanted something in the second house.. thank you
– David
How the operation occurs occasionally: first eliminates those that already exist. And from there every time you enter new records also deletes those on the condition you wish, in this case
> 40
.– lazyFox
There are some techniques described in Delete row set in huge tables -> https://portosql.wordpress.com/2019/10/16/delete-vlt/
– José Diz