I recently asked a question about exporting query plans (here Export Query Plans) and got some great answers.

However, I did run into one issue, during the process of interrogating SQL Server to obtain the plans, the process fails if there are any offline databases. Simple question, to which I suspect the answer is complex. How do I have the interrogation ignore the offline databases?

Thank you in advance for your assistance!

  • 1
    Why would you care about db status when interrogating the query cache? Sep 15, 2015 at 13:38
  • One query can touch multiple databases. In order to know if any of the objects are offline, you would need to parse the plan/query/etc to check all of the databases in the plan.
    – Brent Ozar
    Sep 15, 2015 at 13:56
  • Remus, because the interrogation fails if a DB is offline.
    – pshore73
    Sep 15, 2015 at 13:58
  • Brent, I keep forgetting that is a truism in SQL, since so much of what I am dealing with are databases that are not "cross queried". Creating the process to exam the plan seems like a large task to take on sometime after now. :)
    – pshore73
    Sep 15, 2015 at 13:59
  • @pshore73 that does not answer my question. The interrogation fails because is incorrect. Sep 15, 2015 at 14:09

1 Answer 1


Did you try:

get-sqldatabase -ServerInstance yourserver | Where-Object status -eq 'Normal'
  • Thank you, I did not know that option existed in PowerShell. However, as Brent noted, with the potential of queries hitting multiple DBs, the status check needs be accompanied by some parsing of the query plan itself.
    – pshore73
    Sep 15, 2015 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.