Slight improvement:

1. Rotate usernames/passwords and call sql.Open(...) to get a new 
connection pool for future queries. (Save old pool in oldDB.)
2. Call oldDB.SetMaxIdleConns(-1), which will immediately close any unused 
connections in the old pool and cause those in use to be closed as soon as 
they are returned to the pool.
3. Start a goroutine that will poll oldDB.Stats().OpenConnections at an 
appropriate frequency, when it returns zero (or too much time has passed) 
call oldDB.Close() and exit the goroutine.

Chris

On Tuesday, November 1, 2016 at 6:59:38 PM UTC-4, Francis Chuang wrote:
>
> Just some further questions. I think the easiest way would be to combine 
> ksug and Chris' suggestions. I would prefer not having to maintain a 
> wrapper for each database as we talk to quite a few different types of 
> databases using database/sql.
>
> Does this some bullet proof?
> 1. Rotate usernames/passwords and open a new connection and get a new db 
> object. Keep the old db object around.
> 2. Wait for 1 hour or some other predetermined amount of time.
> 3. Call SetMaxConnections(-1) on the old db object. Does this flush and 
> close cached connections immediately?
> 4. Call Close() on the old db object.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to