We have some initialization code that makes sure that all the needed resources are in place,
i.e.: creates those resources (files, directories, databases, tables, etc.) if missing, and does nothing otherwise.
But, when a database is in use (i.e. exists and already has live connections), a new app
that goes through the initialization code waits forever.
The reason is that ‘CREATE DATABASE IF NOT EXISTS’ is kinda stupid: it tries to own the database, even though it exists and nothing should be done.
Is there a way to check whether a database already exists, that does not involve such a lock?
Returns 1 if database exists (and the user executing the query has the appropriate privileges to be able to see it, blah blah blah); 0 otherwise