title: Binary data getting borked when saving to PostgreSQL
body: <p>I'll let this irb session do the talking (junk omitted with <code>....</code>).</p>
  
  <h3>Create a model with some Marshalled data. <code>user_info</code> is a binary column</h3>
  
  <pre><code>irb(main):011:0&gt; p2 = Provider.create(user_info: Marshal.dump(ActiveSupport::HashWithIndifferentAccess.new({foo: 1, bar: 2}))
     (0.7ms)  BEGIN
    SQL (11.6ms)  INSERT INTO "providers" (...."user_info") VALUES (....$9) RETURNING "id"  [.....["user_info", "\x04\bC:-ActiveSupport::HashWithIndifferentAccess{\aI\"\bfoo\x06:\x06EFi\x06I\"\bbar\x06;\x06Fi\a"]]
     (3.6ms)  COMMIT
  =&gt; #&lt;Provider id: 98, ..... user_info: "\x04\bC:-ActiveSupport::HashWithIndifferentAccess{\aI\"\bf...", provider_id: nil&gt;
  </code></pre>
  
  <h3>Check the value. Looks right:</h3>
  
  <pre><code>irb(main):013:0&gt; p2.user_info
  =&gt; "\x04\bC:-ActiveSupport::HashWithIndifferentAccess{\aI\"\bfoo\x06:\x06EFi\x06I\"\bbar\x06;\x06Fi\a"
  </code></pre>
  
  <h3>Bad things happen: here I reload it and the value completely changes into a format Marshal can't load</h3>
  
  <pre><code>irb(main):014:0&gt; p2.reload
    Provider Load (5.3ms)  SELECT "providers".* FROM "providers" WHERE "providers"."id" = $1 LIMIT 1  [["id", 98]]
  =&gt; #&lt;Provider id: 98, ...., user_info: "x0408433a2d416374697665537570706f72743a3a4861736857...", provider_id: nil&gt;
  
  irb(main):015:0&gt; p2.user_info
  =&gt; "x0408433a2d416374697665537570706f72743a3a4861736857697468496e646966666572656e744163636573737b07492208666f6f063a0645466906492208626172063b06466907"
  </code></pre>
  
  <p>This session is running on Heroku after I recently moved my database from shared to their new free <a href="https://addons.heroku.com/heroku-postgresql" rel="nofollow noreferrer">Dev Postgres</a>.</p>
  
  <p>I'm not sure if this is a heroku problem, a postgres problem or a rails problem. The strange thing is: I also migrated another instance (production) of the same app to the new Dev Posgress and it's not having this problem. I found <a href="http://blog.aradine.com/2009/09/rubys-marshal-and-activerecord-and.html" rel="nofollow noreferrer">this</a> but it appears to have been fixed years ago. Anyone have experience with this?</p>
  
  <h2>Update</h2>
  
  <p>Looks like I found an answer after all from this excellent answer on SO: <a href="https://stackoverflow.com/a/8541304/65311">https://stackoverflow.com/a/8541304/65311</a></p>