# Session id length in sessions table

**URL:** <https://www.ruby-forum.com/t/session-id-length-in-sessions-table/167190>\
**Category:** Rails\
**Created:** [May 5, 2009, 9:43am UTC](https://www.ruby-forum.com/t/session-id-length-in-sessions-table/167190 "2009-05-05T09:43:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![builtbysimple](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/aca169/32.png) [@builtbysimple](https://www.ruby-forum.com/u/builtbysimple)\
**Post date:** [May 5, 2009, 9:43am UTC](https://www.ruby-forum.com/t/session-id-length-in-sessions-table/167190/1 "2009-05-05T09:43:43Z")

</div>

Dear all,

I just created session with rake db:sessions:create and run the  
migration  
also. When I run my apps, my db barfed out saying that the length of  
session\_id is too long. When I checked into my db, the length of  
session\_id  
column in the sessions table, it was 255 of character varying. I then  
changed it to 500 character varying and it works. But that would be too  
long. Does anybody know the exact length of this field?

Thank you in advance.

–  
If you can’t believe in God the chances are your God is too small.

Read my blog: [http://joshuajava.wordpress.com/](http://joshuajava.wordpress.com/)  
Follow us on twitter: [http://twitter.com/scrum8](http://twitter.com/scrum8)

---

<div class="post-metadata">

**Author:** ![builtbysimple](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/aca169/32.png) [@builtbysimple](https://www.ruby-forum.com/u/builtbysimple)\
**Post date:** [May 5, 2009, 6:55pm UTC](https://www.ruby-forum.com/t/session-id-length-in-sessions-table/167190/2 "2009-05-05T18:55:33Z")

</div>

Hi there,

Not a DB expert but as far as I understand when you have a “varying”  
field you are telling the DB how long the data in the field/column  
**could be**. If you put a value that is shorter than the maximum  
possible length the DB should arrange the storage for as much data as  
you put in the field and no more, so ‘extra empty space’ is not  
wasted. In other words, I think you should be fine, especially if you  
clean up session information as sessions expire.

Pepe

---

<div class="post-metadata">

**Author:** ![builtbysimple](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/aca169/32.png) [@builtbysimple](https://www.ruby-forum.com/u/builtbysimple)\
**Post date:** [May 5, 2009, 7:06pm UTC](https://www.ruby-forum.com/t/session-id-length-in-sessions-table/167190/3 "2009-05-05T19:06:08Z")

</div>

On May 5, 8:42 am, Joshua P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Dear all,
> 
> I just created session with rake db:sessions:create and run the migration  
> also. When I run my apps, my db barfed out saying that the length of  
> session\_id is too long. When I checked into my db, the length of session\_id  
> column in the sessions table, it was 255 of character varying. I then  
> changed it to 500 character varying and it works. But that would be too  
> long. Does anybody know the exact length of this field?

It’s not normally anywhere near that long. if you are moving from an  
app that was using the cookiestore session storage then you’ll need to  
clear out the sessions (because with the cookie store the session id  
is the session data)

Fred
