Thanks Chris. I'd not even considered dbms_lock. I tested your idea, but I didn't make it much further, but it's possible that I'm not doing it right. For example,
Session 1:
SQL> exec get_lock;
PL/SQL procedure successfully completed.
Session 2 (slips in a fast one...):
SQL> insert into mylist values (1,2);
1 row created.
Session 1:
SQL> alter table mylist drop partition two;
alter table mylist drop partition two
*
ERROR at line 1:
ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
Need some ddl_lock_timeout...
Now, I do get a little farther (which is probably where you were leading me to) if I call the LOCK TABLE immediately after dbms_lock.x_mode:
Session 1:
SQL> exec get_lock;
PL/SQL procedure successfully completed.
SQL> lock table mylist in exclusive mode;
Table(s) Locked.
After which Session 2 waits until Session 1 is done.
Session 2:
SQL> insert into mylist values (1,2);
insert into mylist values (1,2)
*
ERROR at line 1:
ORA-14400: inserted partition key does not map to any partition
However, after reflecting a little more on our environment the majority of our cursor pins and library cache locks are really on SELECT statements. So all of this is probably for naught...
I'll be sure to tell Support you told them to get back to work. Thanks again for your help. Love TOMs.
June 08, 2017 - 1:36 am UTC
I think Chris's point was that if you adopt a serialisation mechanism, then *all parties* who want to compete for the resource need to embrace it.
In those sites that have a plsql wrapper around their code, this is of course trivial - you just add dbms_lock where appropriate.