Search code examples
databasedb2db2-luw

Db2: Get current connection details


Is there a way in DB2 to fetch current connection details? I'm working on a requirement where I need to keep history of all inserts/updates on a table along with the details about the user who made the change. I'm looking for a way to retrieve current connection user's name, hostname and/or IP address from where the connection is made. We are using LUW DB2 v10.5.0.8


Solution

  • You can use special registers as pseudo-columns within SQL statements such as triggers:

    SELECT 
     CURRENT TIMESTAMP,    
     SESSION_USER,
     CURRENT CLIENT_WRKSTNNAME
    FROM
     SYSIBM.SYSDUMMY1
    

    Source: https://www.ibm.com/docs/en/db2-for-zos/11?topic=elements-special-registers