How to Run Code Every Time SQL Developer Starts - Connection Startup Script

In SQLDeveloper, I wanted to set dbms_application_info.set_module every time I load up a connection. This way, my queries will be delineated as belonging to me in v$active_session_history and other views.

Create a file and name in connection_startup_script.sql with whatever code you want to execute, such as:

BEGIN
    DBMS_APPLICATION_INFO.SET_MODULE(
        module_name => 'SQL Developer', 
        action_name => 'MMOISEN'
    );
END;
/

In SQLDeveloper, navigate to Tools>Preferences>Database, and under Filename for connection startup script click Browse and select your file.

matthew_moisen_sql_developer_connection_startup_script.jpg

Alternatively, under the search bar type in "startup" and then click database:

matthew_moisen_sql_developer_connection_start_up_script_alternate.jpg

To verify it is working, open up a new connection, and run the following:

SELECT username, osuser, module, action 
FROM v$session 
WHERE 1=1
    AND sid = SYS_CONTEXT('USERENV', 'SID')
;

And you should see the following output:

matthew_moisen_sql_developer_start_up_connection_verification.jpg


Comments

Add Comment

Name

Email

Comment

Are you human? + one = 2