db_release_unused_handles (public)

 db_release_unused_handles [ -dbn dbn ]

Defined in packages/acs-tcl/tcl/01-database-procs.tcl

Releases any database handles that are presently unused.

Switches:
-dbn (optional)
The database name to use. If empty_string, uses the default database.

Testcases:
db__db_foreach, db__caching, db__transaction_bug_3440
Source code:
        # we need the state array still for transaction handling
        upvar "#0" [db_state_array_name_is -dbn $dbn] db_state

        set pools [db_available_pools $dbn]
        set currentHandles [ns_db currenthandles]

        foreach pool $pools {
            if {[dict exists $currentHandles $pool]} {
                foreach {handle active} [dict get $currentHandles $pool] {
                    #ns_log notice "### FOUND pool $pool handle $handle active $active"
                    if {$active eq 0} {
                        # Don't release handles which are part of a transaction.
                        if { [info exists db_state(transaction_level,$handle)]
                             && $db_state(transaction_level,$handle) > 0
                         } {
                            continue
                        }
                        set start_time [expr {[clock clicks -microseconds]/1000.0}]
                        ns_db releasehandle $handle
                        #ns_log notice "### AFTER releasehandle [ns_db currenthandles $pool]"
                        ds_collect_db_call $handle releasehandle "" "" $start_time 0 ""
                    }
                }
            }
        }
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: