In this blog post we are discussing on how to remove expired tokens in WSO2 Identity Server.
Please Create procedure in PostgreSQL
https://raw.githubusercontent.com/wso2/carbon-identity-framework/master/features/identity-core/org.wso2.carbon.identity.core.server.feature/resources/dbscripts/stored-procedures/postgresql/postgre-9x/token-cleanup/postgresql-token-cleanup.sql
Please update PostgreSQL connection details in in below script and execute to remove token as batches.
https://raw.githubusercontent.com/wso2/carbon-identity-framework/master/features/identity-core/org.wso2.carbon.identity.core.server.feature/resources/dbscripts/stored-procedures/postgresql/postgre-9x/token-cleanup/token-cleanup-runner.sh
Reindex DB
REINDEX DATABASE WSO2;
Run Vaccum cleaning
VACUUM VERBOSE ANALYZE idn_oauth2_access_token;
VACUUM VERBOSE ANALYZE idn_oauth2_access_token_scope;
VACUUM VERBOSE ANALYZE idn_oauth2_authorization_code;