# Forcing a DB transaction to go through

**URL:** <https://www.ruby-forum.com/t/forcing-a-db-transaction-to-go-through/174292>\
**Category:** Rails\
**Created:** [August 24, 2009, 4:12pm UTC](https://www.ruby-forum.com/t/forcing-a-db-transaction-to-go-through/174292 "2009-08-24T16:12:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [August 24, 2009, 4:12pm UTC](https://www.ruby-forum.com/t/forcing-a-db-transaction-to-go-through/174292/1 "2009-08-24T16:12:21Z")

</div>

This is the ‘sequel’ to this:  
[http://www.ruby-forum.com/topic/193688](http://www.ruby-forum.com/topic/193688)

By ‘sequel’, I mean that this is actually the problem I am having.

Aldric G. wrote:

> Okay, I finally got a clear look at the log, and it is indeed how it  
> seems - all the transactions to the database are queued until I actually  
> look at the database.
> 
> The DB I am using is SQLite3. How do I force ActiveRecord / SQLite /  
> Rails to commit / process the transaction so it happens in a better type  
> of real-time than that?

I’m looking for something like an update/commit/force/process/execute  
statement to tell the DB to do its update now, and not next time someone  
goes “What if I looked at that list of reports ?”  
When I came in this morning, it was processing the background job which  
runs every five minutes - I saw the DB (at 8am) go through the updates  
from midnight to then. I don’t know if someone had clicked to view the  
report or if the buffer was full or what… But this is just  
unacceptable behavior, you know?

And sadly, mysql or oracle or postgresql aren’t choices for me at the  
time.

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [August 24, 2009, 5:43pm UTC](https://www.ruby-forum.com/t/forcing-a-db-transaction-to-go-through/174292/2 "2009-08-24T17:43:42Z")

</div>

On Aug 24, 3:12 pm, Aldric G. \<rails-mailing-l…@andreas-  
[s.net](http://s.net)\> wrote:

> > Rails to commit / process the transaction so it happens in a better type  
> > of real-time than that?

Well database transactions are supposed to be like that - once you’ve  
sent “commit” then it’s on disk (and if you’re not in a transaction  
then every statement is surrounded in an implicit transaction). Are  
you sure that it isn’t just buffering on the log file that is fooling  
you ?

Fred

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [August 24, 2009, 5:54pm UTC](https://www.ruby-forum.com/t/forcing-a-db-transaction-to-go-through/174292/3 "2009-08-24T17:54:38Z")

</div>

Frederick C. wrote:

> On Aug 24, 3:12ï¿½pm, Aldric G. \<rails-mailing-l…@andreas-  
> [s.net](http://s.net)\> wrote:
> 
> > > Rails to commit / process the transaction so it happens in a better type  
> > > of real-time than that?
> 
> Well database transactions are supposed to be like that - once you’ve  
> sent “commit” then it’s on disk (and if you’re not in a transaction  
> then every statement is surrounded in an implicit transaction). Are  
> you sure that it isn’t just buffering on the log file that is fooling  
> you ?
> 
> Fred

Well, when I try to view the report, I get one of two behaviors. Ignore  
the lack of ‘a’, it’s a bug with the console I use (yay Windows).

1. It loads almost instantly. Log file shows:

Processing ReportsController#folder (for 127.0.0.1 t 2009-08-24  
11:28:02) [POST]  
Prmeters: {“folder\_id”=\>“1”,  
“uthenticity\_token”=\>“3WKJGViOKytwH7Xn+g8Q1d4rH5xu9Q1H03tkqo4+pI=”}  
Report Lod (47.0ms) SELECT \* FROM “reports” WHERE  
(“reports”.“report\_pth\_id” = ‘1’)  
Rendered reports/\_lists (124.0ms)  
Rendered reports/\_lists (0.0ms)  
Rendered reports/\_lists (0.0ms)  
Rendered reports/\_folder (124.0ms)  
Completed in 218ms (View: 124, DB: 47) | 200 OK  
[[http://loclhost/reports/folder?folder\_id=1](http://loclhost/reports/folder?folder_id=1)]

1. It takes longer than ‘instantly’. Sometimes considerably longer.  
I get the same output than in 1 but, prior to that, I get a ton of  
‘select’ and ‘update’ statements… The same statements which should be  
happening during the background job I have that runs every 5 minutes.

That background job outputs to the log file “#{Timestamp} - Swept for  
reports.” and the issue happens after I see this a couple of times with  
no other activity.

When I came back from the week-end, as I was saying, I saw it do a whole  
lot of time updates, every 5 minutes, on the same db entries… When I  
expect that these should have been done, you know, when the job ran!

I don’t understand why it would buffer so much select/update statement  
that should go out to the log, and why that’d slow down the app  
anyway… Any idea?

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [August 26, 2009, 9:10pm UTC](https://www.ruby-forum.com/t/forcing-a-db-transaction-to-go-through/174292/4 "2009-08-26T21:10:27Z")

</div>

Same issue in production mode.  
Same issue if I use ‘save!’ instead of ‘save’.  
Same issue if I issue a “Report.find :all” at the end of the job in an  
attempt to force the system to look at the updates.

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [August 27, 2009, 2:13pm UTC](https://www.ruby-forum.com/t/forcing-a-db-transaction-to-go-through/174292/5 "2009-08-27T14:13:31Z")

</div>

E. Litwin wrote:

> > Well, when I try to view the report, I get one of two behaviors. Ignore  
> > the lack of ‘a’, it’s a bug with the console I use (yay Windows).
> 
> To fix that “Windows” issue with “a” not showing, follow the  
> instructions here:  
> [http://codesnippets.joyent.com/posts/show/414](http://codesnippets.joyent.com/posts/show/414)

Thanks!  
On another random note, I came back this morning and lo and behold, I  
did not wait the usual 20 minutes to get updated data after clicking on  
one of the report links.  
Maybe it is fixed after all.

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [August 26, 2009, 11:27pm UTC](https://www.ruby-forum.com/t/forcing-a-db-transaction-to-go-through/174292/6 "2009-08-26T23:27:42Z")

</div>

> Well, when I try to view the report, I get one of two behaviors. Ignore  
> the lack of ‘a’, it’s a bug with the console I use (yay Windows).

To fix that “Windows” issue with “a” not showing, follow the  
instructions here:  
[http://codesnippets.joyent.com/posts/show/414](http://codesnippets.joyent.com/posts/show/414)
