Configure database session persistence
We can use scripting and wsadmin.sh to configure database persistence.
Before starting this task, wsadmin.sh must be running. See the Start the wsadmin scripting client topic for more information.
To configure database persistence. Within these steps, the following variables apply to the Jython and Jacl commands:
- node is the affected node within our configuration.
- server_name is the affected server within our configuration.
- cell_name is the affected cell within our configuration.
- db2_administrator is the ID for the database administrator.
- db2_password is the password for the ID that is associated with the database administrator.
- Retrieve the configuration ID of the server to enable database persistence and store its values in the server variable.
Jacl:
set server [$AdminConfig getid /Node:node/Server:server_name/]
Example output:
server_name(cells/cell_name/nodes/node/servers/server_name |server.xml#Server_1265038035855)
Jython:
server = AdminConfig.getid('/Node:node/Server:server_name/')
Example output: None
- Retrieve the name of the session manager, which is associated with the server values in the previous step, and assign the session manager to the sm variable.
Jacl:
set sm [$AdminConfig list SessionManager $server]
Example output:
(cells/cell_name/nodes/node/servers/server_name |server.xml#SessionManager_1256932276179)
Jython:
sm = AdminConfig.list('SessionManager', server)
Example output: None
- Add the database session persistence mode value to the sm variable, which already contains the session manager value from the previous steps.
Jacl:
$AdminConfig modify $sm {{sessionPersistenceMode "DATABASE"}}
Example output: None
Jython:
AdminConfig.modify(sm,'[[sessionPersistenceMode "DATABASE"]]')
Example output: None
- Retrieve the database session persistence value for the session manager and the database session persistence mode that are set to the sm variable. Set to the sesdb variable.
Jacl:
set sesdb [$AdminConfig list SessionDatabasePersistence $sm]
Example output:
(cells/cell_name/nodes/node/servers/server_name |server.xml#SessionDatabasePersistence_1256932276179)
Jython:
sesdb = AdminConfig.list('SessionDatabasePersistence',sm)
Example output: None
- Modify the sesdb variable to include the user ID and password to access the database and the table space name; and the Java naming and directory interface (JNDI) name.
Jacl:
$AdminConfig modify $sesdb { {userId "db2_administrator"} {password "db2_password"} {tableSpaceName ""} {datasourceJNDIName "jdbc/SessionDataSource"} }Example output: None
Jython:
AdminConfig.modify(sesdb,'[[userId "db2_administrator"] [password "db2_password"] [tableSpaceName ""] [datasourceJNDIName "jdbc/SessionDataSource"]]')
Example output: None
- Save the configuration changes. For more information, see the documentation on saving configuration changes with wsadmin.sh.
Related tasks
Saving configuration changes with wsadmin.sh Use the wsadmin scripting AdminConfig object for scripted administration
Commands for the AdminConfig object Configure for database session persistence