1

Is it possible to find the database name of a DB2 database by querying the catalog metadata? For instance, we can find the columns of tables using SELECT tbname, column_name FROM SYSIBM.SYSCOLUMNS. Is there an analogous query that can get the database name?

I need this because I am running a query to get the remaining free space in the DB, across several instances. I would prefer to have the query itself tell me the name of the database.

Let's say my JDBC URL is jdbc:db2://hostname.company.com:portNumber/InstanceName. I need the InstanceName.

Running DB2 10.5 on Linux.

2
  • so, you need instance name before you're connected to db, so who will execute such sql query? Commented Jul 26, 2017 at 16:19
  • I know what the instance name is. I connect to the DB and run a certain query, which returns available space. I do this for several DB2 instances. I would prefer to run a query that returns "For database DB_NAME, the available space is NNN Gb". Right now, I only get the "NNN Gb" returned from the query. If I need to put all this data together, I need to add the DB name myself. To automate as much as possible/reduce confusion, would prefer to get this directly from the query. Commented Jul 26, 2017 at 16:23

1 Answer 1

4

Try: values current server (for DB2 on Linux Unix Windows) , it returns the database name to which you are currently connected. Or select current server from sysibm.sysdummy1 if you insist on using the catalog.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.