Created
February 7, 2013 21:24
-
-
Save lambdamusic/4734297 to your computer and use it in GitHub Desktop.
Django: Clean up expired django.contrib.session\'s in a huge MySQL InnoDB table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment