You could easily make a wrapper for this with uplevel so all you had to do was call db_with_3x_wrapper { code }. After adding this,
proc_doc db_with_3x_wrapper { code } {
executes $code in uplevel, after allocating a db handle named $db
} {
uplevel "
db_release_unused_handles
set db [ns_db gethandle]
$code
ns_db releasehandle $db
"
}
Then my example becomes simply
db_with_3x_wrapper { set admin_p [ad_permission_p $db site_wide] }