When a user logs in, Django adds a row to the django_session database table. Django updates this row each time the session data changes. If the user logs out manually, Django deletes the row. But if the user does not log out, the row never gets deleted.

asked 24 Feb '14, 16:54

cgrzemba's gravatar image

cgrzemba ♦♦
6091318
accept rate: 9%


To understand this problem, consider what happens with the database backend. When a user logs in, Django adds a row to the django_session database table. Django updates this row each time the session data changes. If the user logs out manually, Django deletes the row. But if the user does not log out, the row never gets deleted. A similar process happens with the file backend.

Django does not provide automatic purging of expired sessions. Therefore, it’s your job to purge expired sessions on a regular basis. Django provides a clean-up management command for this purpose: clearsessions. It’s recommended to call this command on a regular basis, for example as a daily cron job.

Note that the cache backend isn’t vulnerable to this problem, because caches automatically delete stale data. Neither is the cookie backend, because the session data is stored by the users’ browsers.

so run:

$ ./manage.py clearsessions
permanent link

answered 24 Feb '14, 16:55

cgrzemba's gravatar image

cgrzemba ♦♦
6091318
accept rate: 9%

this can placed in crontab, see $OSQA_SITE/cron directory for examples

(27 Feb '14, 10:42) cgrzemba ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×2

question asked: 24 Feb '14, 16:54

question was seen: 52,835 times

last updated: 27 Feb '14, 10:42

Related questions

powered by OSQA