Thursday, August 24, 2023

Oracle Database 23c - Lock-Free Reservations to Prevent Blocking Sessions

Oracle Database 23c - Lock-Free Reservations to Prevent Blocking Sessions

When multiple concurrent sessions/users are modifying or updating the same rows for example shopping cart multiple sessions and users are keeping the same product into the cart. This will reserve the quantity for their session until the payment is not completed.  If you allow concurrent transactions to access data, you must control the transactions to preserve application correctness. Multiple save points need to be created in application logic.

Let's take an example of a product inventory table.



As you can see here, we have a product_inv table. It has 6 rows out of which the first record is going to be updated by session 1 and Also session 2 has initiated the transaction on the same row.

Session 2 is in waiting mode as session 1 has not completed the transaction. Neither commit nor rollback done.

For developers, such a situation needs to be handled at application level by making save points or making some global variables or in session cache.
 
In Oracle Database 23c, new feature "Lock free reservation" helps you to update the same row without blocking your session. Lock-Free Reservation provides an in-database capability for transactions and operates on so-called reservable columns. It enables concurrent transactions to proceed without being blocked on updates made to reservable columns.

Let's make prod_qty column reservable by using below command,

alter table product_inv modify (prod_qty reservable);

Once you done, now concurrent session can update the same row as shown in below example.



To make this example more realistic, let's add the check constraint so that no one can reserve more than available quantity.

For example, We do have a total 10 quantities, out of that session 1 has reserved the 8 quantities. What if session 2 is reserving 3 quantities which are out of the availability. Hence check constraint is required.
Let's look below snapshot where it is giving an error in session 2 while reserving the 3 quantities.


Some facts about Lock Free Reservations as below,
  • Only numeric (number) columns can be marked as reservable columns.
  • You can only do + or - (increase or decrease) operation on a reservable column. Cannot modify column like prod_qty=5 with literal value to update the column.
  • You can either update the reservable columns or non-reservable columns. Both cannot be updated in the same statement.
  • Your updated transaction is reservable until you commit or rollback. In the above example of updating the product quantity is reserved for that particular session. Other sessions can reserve quantity based on the availability of product quantity.

Benefit of Lock Free Reservations is, it reduces the headache of the developers to write code and maintain each session's value in application.



Thanks & Regards,
Chandan Tanwani

Wednesday, March 29, 2023

503 - The username or password for the connection pool named |default|lo|, are invalid, expired, or the account is locked

503 - The username or password for the connection pool named |default|lo|, are invalid, expired, or the account is locked

This article will help you in two ways, 
1) Update the ords_public_user password
2) Resolve 503 error - The username or password for the connection pool named |default|lo|, are invalid, expired, or the account is locked. Changing weblogic port after deploying ORDS on Oracle WebLogic Server

Initially, we installed and configured weblogic with default port i.e. 7001. ORDS was deployed on weblogic. After that we wanted to change the weblogic port from 7001 to 8080 to run the APEX. After changing port ORDS stop working and throwing below error, 

<Mar 17, 2023, 12:27:27,801 PM India Standard Time> <Error> <oracle.dbtools.rest> <BEA-000000> <<54319e0f-61e7-44fc-8213-a6a5965fdc41-00000070> GET 10.132.141.180 /ords/ 503 The username or password for the connection pool named |default|lo|, are invalid, expired, or the account is locked
ServiceUnavailableException [statusCode=503, logLevel=SEVERE, reasons=[The username or password for the connection pool named |default|lo|, are invalid, expired, or the account is locked]]
        at oracle.dbtools.http.errors.ServletResponseExceptionMapper.mapError(ServletResponseExceptionMapper.java:45)
        at oracle.dbtools.http.errors.ErrorLogger.log(ErrorLogger.java:27)
        at oracle.dbtools.http.errors.ErrorPageFilter.doFilter(ErrorPageFilter.java:106)
        at oracle.dbtools.http.filters.HttpFilter.doFilter(HttpFilter.java:47)
        at oracle.dbtools.http.filters.FilterChainImpl.doFilter(FilterChainImpl.java:64)
        Truncated. see log file for complete stacktrace
Caused By: oracle.dbtools.common.jdbc.ConnectionPoolConfigurationException: The username or password for the connection pool named |default|lo|, are invalid, expired, or the account is locked


I have cross check if my APEX and ORDS users are unlocked or not,

It seems, everything is fine, so why am I getting this error?
I thought if I could reset the password for all the users again that would help, but it didn't help me.

Next thought, when I was reading the error again it saying "The username or password for the connection pool named |default|lo|, are invalid, expired, or the account is locked". It means somewhere it is going wrong.

You know, ORDS config directory also stores the username and password. Here, my ORDS version is 22.4. And in this version you can find the cwallet.sso file under /u01/ords/conf/database/orcl directory. You might have some different directory structure based on your ORDS installation.

Here, I reset the password in ORDS as well with the following command.

Step 1 - Run this command from ords directory 
            > ords --config /u01/ords/conf config secret db.password
Step 2 - Restart the weblogic and hit the URL http://<ip address>:8080/ords again.

It works for me and I am able to get the APEX log-in screen.

You can refer to Jeff Smith's blog for additional resources about the above error for ORDS 22.4 and earlier versions.



Thanks & Regards,
Chandan Tanwani

503 Service Unavailable The connection pool named: |default|lo|, encountered and error: mismatch with the server cert DN:IO Error

503 Service Unavailable
The connection pool named: |default|lo|, encountered and error: mismatch with the server cert DN:IO Error


Hope you have gone through my previous post of ORDS : 404 not found.

Once I resolved above ORDS issue, I was getting error - 503 Service Unavailable
The connection pool named: |default|l0|, encountered and error: mismatch with the server cert DN:IO Error: The Network Adapter could not establish the connection (CONNECTION_ID=N6Ys81zJRmyqf8zuk6YrOg==)

This is really frustrating when you solve one error and immediately get another error and are stuck with no clue why it happened.

Below is the screenshot for the reference.


Also If you see the weblogic log file, you will see the below error.

<Mar 16, 2023, 11:53:01,891 AM India Standard Time> <Error> <oracle.dbtools.rest> <BEA-000000> <<5077f343-f438-4659-a682-f867ee715c88-0000001c> GET 10.132.141.180 /ords/ 503 The connection pool named: |default|lo|, encountered an error: mismatch with the server cert DN: IO Error: The Network Adapter could not establish the connection (CONNECTION_ID=N6Ys81zJRmyqf8zuk6YrOg==)
ServiceUnavailableException [statusCode=503, logLevel=SEVERE, reasons=[The connection pool named: |default|lo|, encountered an error: mismatch with the server cert DN: IO Error: The Network Adapter could not establish the connection (CONNECTION_ID=N6Ys81zJRmyqf8zuk6YrOg==)]]
        at oracle.dbtools.http.errors.ServletResponseExceptionMapper.mapError(ServletResponseExceptionMapper.java:45)
        at oracle.dbtools.http.errors.ErrorLogger.log(ErrorLogger.java:27)
        at oracle.dbtools.http.errors.ErrorPageFilter.doFilter(ErrorPageFilter.java:106)
        at oracle.dbtools.http.filters.HttpFilter.doFilter(H




To resolve the the issue, I have followed below steps,
Step 1 - Check the TNS Entries on DB Server
Step 2 - Check listener is up and running. It serves your PDB database.
Step 3 - Check if TNS Ping working for your PDB

In my case all the above steps were working fine. There was no issue. If you have any issue in the above steps, first rectify the same.

Now, after cross checking all my installation documents and other things, I then found that user APEX_220200 was locked.
You can run the below command in your PDB/CDB and check if any of %APEX% users are locked or what. In my case APEX_220200 was locked.
select username, account_status from dba_users where username like '%APEX%';
Refer below screenshot


Unlock user and reset password with following command
sql> alter user apex_220200 identified by Manager#123 account unlock;


Also check any ORDS user is locked or what by running below query in database. 
select username, account_status from dba_users where username like '%ORDS%';


If the ORDSYS user is locked then no issue. No need to unlock it.


Finally, I was able to get the APEX login page after unlocking apex_220200 user.



Lesson learned, must check all the prerequisites and follow the Oracle documentation steps.



Thanks & Regards,
Chandan Tanwani

Tuesday, March 28, 2023

ORDS - 404 Not Found. The request could not be mapped to any database.

ORDS - 404 Not Found

"The request could not be mapped to any database. Check the request URL is correct, and that URL to database mappings have been correctly configured."

When I hit the url http://<IP Address>:7001/ords/, I was getting the above error after installing ORDS and deploying it in Weblogic 14.1, and trying to access the APEX login page.

Here my ORDS version was 22.4.
Below is the screenshot for the reference.



The reason behind this error is ORDS war is deployed on Weblogic and it doesn't know where the system property of configured directory location.
to set the system property of configuration URL, we need to specify the same in the JAVA_OPTIONS parameter. Follow the following steps,

Prerequisites - Stop Weblogic server (Managed server if any and Admin Server). Just to share that in my case I was not having managed server.

Step 1 : export JAVA_OPTIONS="-Dconfig.url=/u01/ORDS/conf"
Above path is my ORDS conf file, this given while installing the ORDS.
Step 2 : Start weblogic, Admin Server and Managed Server if any.

Refresh or run again the url http://<IP Address>:7001/ords/

And you will get the login page of APEX. This is it.


Thanks & Regards,
Chandan Tanwani