Clean up expired django.contrib.session's in a huge MySQL InnoDB table

 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

  1. Test Django against many Pythons and databases by jacobian 4 years, 11 months ago
  2. MySQL django password function by mcosta 2 years, 8 months ago
  3. Debug middleware for displaying sql queries and template loading info when ?debug=true by SEJeff 10 months, 1 week ago
  4. Creating MySQL Alter table commands for Foreign Keys by vidyanand 3 years, 7 months ago
  5. EncryptField by volksman 3 years, 4 months ago

Comments

(Forgotten your password?)