This post is a part of Bit Series blog and Its going to be a very quick one.
Have you ever faced a scenario as Vertica DBA to close all sessions on a vertica cluster for a specific user only.
The traditional way to do this is
- Query sessions table and find all open session for a specific user
- Take the session id one by one and then use “select close_session(‘session_id’) command to close each of those sessions
What if there is a smart of way of achieving this tedious task.
Yes, you can do all this with a single command as below.
## First we get all the sessions for the specific users and construct the close_session SQL command for each of the sessions, then we just pass the output of first vsql command as an input to second vsql command. vsql -U dbadmin -w 'xxxxxx' -At -c "select 'select close_session(''' || session_id || ''');' from sessions where user_name = 'dbadmin';" | vsql -U dbadmin -w 'xxxxxx'
Next time, you have this task at hand, do it with a single command using VSQL.
Stay tuned for more such upcoming tips and tricks.