- Author:
- patsplat
- Posted:
- December 31, 2008
- Language:
- SQL
- Version:
- Not specified
- Tags:
- mysql django.contrib.session expire innodb
- Score:
- 3 (after 3 ratings)
While django provides the django_admin.py cleanup script, if sessions get out of control sometimes you have to go lower level to get everything cleaned up. If the problem gets out of hand and you hit the resource limits of the machine, it is very difficult to get anything done in the database.
Attached is SQL code which was used to cleanup 27GB of expired session data in 3h. Run it like this to make sure it runs to completion:
nohup mysql --user=username --password=password --host=hostname database < delete_expired_sessions.sql
nohup causes the script to run detached from a terminal, so if your session gets disconnected it will keep running.
1 2 3 4 5 6 7 8 9 10 11 12 13 | DROP TABLE IF EXISTS `django_session_cleaned`;
CREATE TABLE `django_session_cleaned` (
`session_key` varchar(40) NOT NULL,
`session_data` longtext NOT NULL,
`expire_date` datetime NOT NULL,
PRIMARY KEY (`session_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `django_session_cleaned` SELECT * FROM `django_session` WHERE `expire_date` > CURRENT_TIMESTAMP;
RENAME TABLE `django_session` TO `django_session_old_master`, `django_session_cleaned` TO `django_session`;
DROP TABLE `django_session_old_master`;
|
More like this
- MySQL django password function by mcosta 6 years, 7 months ago
- Creating MySQL Alter table commands for Foreign Keys by vidyanand 7 years, 6 months ago
- Database cleanup by skyjur 5 years, 5 months ago
- Test Django against many Pythons and databases by jacobian 8 years, 10 months ago
- Load customized SQL by roppert 6 years, 10 months ago
Comments
Please login first before commenting.