in reply to timing response from database

You might also want to look at SIGALRM, so you can limit how long it takes and check whether it timed out or returned a different error, if any.