Search code examples
db2metadatadb2-luw

Get DB2 database name using SQL


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.


Solution

  • 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.