A
A deploy pipeline imports your APEX app while the rest of the team keeps working in the Builder. Until APEX 26.2 there was no supported way to lock the application from code, so most of us flipped the build status to Run Only and hoped for the best.
APEX 26.2 ships a real lock API. I upgraded a clone of a local APEX 26.1 database and tested what it actually does, next to everything else APEX calls a lock.
It is #JoelKallmanDay today, the day the Oracle community publishes in memory of Joel Kallman, who led the APEX team for many years and it is missed by many. Here is my contribution.
Four things that look like a lock
- Application lock – the Builder lock on the whole app. Only the developer who locked it can edit or unlock it (docs). Visible in apex_applications.
- Page locks – one developer per page, Builder only, no public API. Visible in apex_application_locked_pages.
- Build status – Run Only keeps developers out of the Builder. Not a lock, but the only thing a script could flip.
- Working copies – isolation, not a lock, but an application lock can protect Main while copies exist.
The old workaround
The usual trick is to set Run Only with APEX_APPLICATION_ADMIN.SET_BUILD_STATUS, import, and put the original status back. It works, sort of:
- Run Only blocks Builder entry only. A Page Designer session that is already open still saves on top of the import.
- An APEXlang import resets the build status to "Run and Develop" every time, so the pipeline has to set it again after the import.
- Flipping the status moves the export checksum. If you compare checksums to detect drift, the workaround itself looks like a change.
And the application lock in APEX 26.1 was no help. It had no API, and an import simply removed it.
The APEX 26.2 API
Two new procedures, LOCK_APPLICATION and UNLOCK_APPLICATION, meant for "trusted CI/CD and development integrations":
APEX_APPLICATION_ADMIN.LOCK_APPLICATION (
p_application_id => 100,
p_lock_as_user => 'JAN',
p_lock_comment => 'Deploy 2026-10-07'
);
--
APEX_APPLICATION_ADMIN.UNLOCK_APPLICATION (
p_application_id => 100,
p_unlock_as_user => 'JAN' -- defaults to NULL
);
The parsing schema can call both with no extra grant, after APEX_UTIL.SET_WORKSPACE. The user has to be a real developer in that workspace (case does not matter), a made-up pipeline name is rejected. Locking again as the same user just replaces the comment.
Two behaviours deserve a warning. Unlock with a NULL user removes anybody's lock, so never use it in a pipeline, or a failed deploy will happily remove a colleague's lock. And "already locked by another user" comes back as the generic ORA-20001, the same code as a missing workspace, so your CI code has to match on the message text. Shame, a dedicated error code would cost Oracle nothing.
And the import keeps it now
This is what makes the API useful. In APEX 26.2 the application lock survives the import, APEXlang and f100.sql alike, and the lock does not block the import either. So a pipeline can lock, import and unlock. The build status still resets after an APEXlang import, nothing changed there.
Page locks are the catch and a huge dissapointment. An APEXlang import removes them, silently. Somebody locked page 10 because they are in the middle of something, you deploy, and the lock is gone. With no API you cannot put it back, so the best you can do is look before you deploy.
A pipeline that locks, imports, unlocks
Lock with a comment naming the pipeline run, so whoever opens the Builder sees who holds the app and why:
DECLARE
c_workspace CONSTANT VARCHAR2(128) := 'MY_WORKSPACE';
c_app_id CONSTANT NUMBER := 100;
c_deployer CONSTANT VARCHAR2(128) := 'CI_DEPLOY';
c_run_id CONSTANT VARCHAR2(64) := '4711';
--
v_locked BOOLEAN := FALSE;
v_locked_by apex_applications.locked_by%TYPE;
BEGIN
APEX_UTIL.SET_WORKSPACE (
p_workspace => c_workspace
);
-- take the lock, the comment says which run holds it
APEX_APPLICATION_ADMIN.LOCK_APPLICATION (
p_application_id => c_app_id,
p_lock_as_user => c_deployer,
p_lock_comment => 'Pipeline run ' || c_run_id
);
v_locked := TRUE;
COMMIT;
-- run the import here (apex import in SQLcl)
NULL;
-- release only our own lock, never with a NULL user
APEX_APPLICATION_ADMIN.UNLOCK_APPLICATION (
p_application_id => c_app_id,
p_unlock_as_user => c_deployer
);
COMMIT;
--
EXCEPTION
WHEN OTHERS THEN
IF v_locked THEN
APEX_APPLICATION_ADMIN.UNLOCK_APPLICATION (
p_application_id => c_app_id,
p_unlock_as_user => c_deployer
);
COMMIT;
RAISE;
END IF;
--
IF SQLERRM LIKE '%already locked by another user%' THEN
SELECT a.locked_by
INTO v_locked_by
FROM apex_applications a
WHERE a.application_id = c_app_id;
--
RAISE_APPLICATION_ERROR(-20000, 'Deploy refused, application ' || TO_CHAR(c_app_id) || ' is locked by ' || v_locked_by);
END IF;
RAISE;
END;
/
The v_locked flag is the important bit. If the lock itself failed, the handler must not unlock anything; if it succeeded, every failure after it has to release it. The commits make the lock visible to other sessions while the import runs.
In real life "apex import" is a SQLcl command, so you will split this into three steps: lock, import, unlock. Put the unlock into the step your CI runs always, even after a failed job, or one broken import keeps your team out of the Builder until somebody notices.
And before any of that, check what is locked right now:
SELECT
'APPLICATION' AS lock_type,
NULL AS page_id,
a.locked_by,
a.lock_comment
FROM apex_applications a
WHERE 1 = 1
AND a.application_id = :app_id
AND a.locked_by IS NOT NULL
UNION ALL
SELECT
'PAGE' AS lock_type,
p.page_id,
p.locked_by,
p.lock_comment
FROM apex_application_locked_pages p
WHERE 1 = 1
AND p.application_id = :app_id
ORDER BY
1, 2;
How ADT.ai uses it
ADT.ai does exactly this on APEX 26.2 and newer. It locks the application as the deploying developer, imports, restores the build status and unlocks. If somebody else holds the lock, the deploy refuses and tells you who; locked pages get a warning. Below APEX 26.2 it holds the pages with the back door below, where a DBA granted it, and falls back to the build status otherwise.
Try it
Upgrade a dev instance to APEX 26.2 and run the lock, import, unlock cycle against your own app. Lock a page in Page Designer first, so you see it disappear with your own eyes. And if you need to protect database objects too, lightweight object locking covers that side.
If this saves your team one overwritten page, pass it on to whoever owns your deploy pipeline.

Comments
Post a Comment