As you use WSO2 API Manager, the number of revoked, inactive and expired tokens accumulates in the IDN_OAUTH2_ACCESS_TOKEN table. These tokens are kept in the database for logging and audit purposes, but they can have a negative impact on the server's performance over time. Therefore, it is recommended to clean them periodically as given in the instructions below:
Tip : It is safe to run these steps in read-only mode or during a time when traffic on the server is low, but that is not mandatory.
- Take a backup of the running database.
Set up the database dump in a test environment and test it for any issues.
Tip: We recommend you to test the database dump before the cleanup task as the cleanup can take some time.
Run the following script (select one according to your database) on the database dump. It takes a backup of the necessary tables, turns off SQL updates and cleans the database of unused tokens.
The following script has been tested on MySQL 5.7.
Uncomment the following in the above script and replace
apimdbwith name of your API Manager database.
Please note that the stored procedure is not included in the script given below.
The following script has been tested on Oracle 11g.
Once the cleanup is over, start the API Manager pointing to the cleaned-up database dump and test thoroughly for any issues.
You can also schedule a cleanup task that will automatically run after a given period of time. Here's an example:
WSO2AM_DBwith the name of your API Manager database in the above script.