Search code examples
pythoncx-oracle

Application name in cx_Oracle


I am connecting to an Oracle Database Server using a SessionPool from cx_Oracle. When I look at the description of the opened session in the Oracle developer, I see that its name is "python.exe". How can I set the application/module name in cx_oracle?


Solution

  • You may be able to physically rename python.exe but there is no programmatic way to change what is shown in Oracle Database as the executable.

    You can set the driver name by calling cx_Oracle.init_oracle_client. This changes the CLIENT_DRIVER column of V$SESSION_CONNECT_INFO.

    Other settable attributes including 'module' (which in Oracle terminology is not the program name) are shown in the documentation Oracle Database End-to-End Tracing.

    # Set the tracing metadata
    connection.client_identifier = "pythonuser"
    connection.action = "Query Session tracing parameters"
    connection.module = "End-to-end Demo"
    
    for row in cursor.execute("""
            SELECT username, client_identifier, module, action
            FROM V$SESSION
            WHERE username = 'SYSTEM'"""):
        print(row)