Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session database table cleanup

Does this table need to be purged or is it taken care of automatically by Django?

like image 775
nemesisdesign Avatar asked Sep 03 '11 22:09

nemesisdesign


3 Answers

Django does NOT provide automatic purging. There is however a handy command available to help you do it manually: Django docs: Clearing the session store

python manage.py clearsessions
like image 125
Abid A Avatar answered Nov 04 '22 13:11

Abid A


  1. Django 1.6 or Above
    python manage.py clearsessions
    
  2. Django 1.5 or lower
    python manage.py cleanup
    
  3. From Django Shell
    from django.contrib.sessions.models import Session
    Session.objects.all().delete()
    
  4. django-session-cleanup cornJob
like image 22
Roshan Bagdiya Avatar answered Nov 04 '22 12:11

Roshan Bagdiya


On my development server, I prefer a database command over python manage.py clearsessions because you delete all sessions, not just the expired ones (here: MySQL). To login into your database and do:

truncate table django_session;

BTW, session is not a database, but a table (django_session) and an app (django.contrib.sessions).

like image 2
Timo Avatar answered Nov 04 '22 12:11

Timo