ORA-04021: timeout occurred while waiting to lock object during truncate table or alter table

Hi,

Sometimes you can get ” ORA-04021: timeout occurred while waiting to lock object  ” during truncate table or alter table.

 

Details of error are as follows.

ALTER TABLE MSD.TEST_TABLE TRUNCATE SUBPARTITION SYS_SUBP2946291;

ALTER TABLE MSD.TEST_TABLE TRUNCATE SUBPARTITION SYS_SUBP2946291
*
ERROR at line 1:
ORA-04021: timeout occurred while waiting to lock object MSD.TEST_TABLE

 

To solve this problem, you can use DDL_LOCK_TIMEOUT parameter with related query as follows.

ALTER SESSION SET DDL_LOCK_TIMEOUT=6000;
ALTER TABLE MSD.TEST_TABLE TRUNCATE SUBPARTITION SYS_SUBP2946291;

 

If you get the same error even though you use DDL_LOCK_TIMEOUT parameter, then you should use the following query to find the related session which hold this table.

SELECT a.inst_id,
status,
username,
machine,
event,
blocking_session,
sql_id,
last_call_et,
status,
'alter system kill session ''' || a.sid || ',' || serial# || ''';'
FROM gv$access a, gv$session b
WHERE a.inst_id = b.inst_id AND a.sid = b.sid
AND object = 'TEST_TABLE';

 

query result is as follows.

alter system kill session '489,46242,@5';
alter system kill session '824,41709,@4';
alter system kill session '877,15892,@7';

 

 

then execute this kill session script, and kill these 3 sessions which hold the TEST_TABLE table.

Once you kill the related sessions, you can alter the table as follows.

SQL> ALTER TABLE MSD.TEST_TABLE TRUNCATE SUBPARTITION SYS_SUBP2946291;

Table altered.


 

 

Do you want to learn Oracle Database for Beginners, then read the following articles.

https://ittutorial.org/oracle-database-19c-tutorials-for-beginners/

About Mehmet Salih Deveci

I am Founder of SysDBASoft IT and IT Tutorial and Certified Expert about Oracle & SQL Server database, Goldengate, Exadata Machine, Oracle Database Appliance administrator with 10+years experience.I have OCA, OCP, OCE RAC Expert Certificates I have worked 100+ Banking, Insurance, Finance, Telco and etc. clients as a Consultant, Insource or Outsource.I have done 200+ Operations in this clients such as Exadata Installation & PoC & Migration & Upgrade, Oracle & SQL Server Database Upgrade, Oracle RAC Installation, SQL Server AlwaysOn Installation, Database Migration, Disaster Recovery, Backup Restore, Performance Tuning, Periodic Healthchecks.I have done 2000+ Table replication with Goldengate or SQL Server Replication tool for DWH Databases in many clients.If you need Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS Consultancy and Training you can send my email adress [email protected].-                                                                                                                                                                                                                                                 -Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS ve linux Danışmanlık ve Eğitim için  [email protected] a mail atabilirsiniz.

Leave a Reply

Your email address will not be published. Required fields are marked *