Skip to content

sys.log_session

This view records the history of individual database sessions.

Column NameData TypeDescription
session_idbigintUnique ID of the session.
application_namevarchar(256)Name of the application that is running the session, such as ybsql, ybload, ybunload, or yb-smc. You will also see internal application names such as yb-lime. (Note that an unload session reports ybunload as the application name while it is running. When the unload is complete, the view reports yb-lime as the application name.)
client_hostnamevarchar(256)Client host name, if available.
client_ip_addressvarchar(256)Client IP address.
database_idbigintUnique ID for the database.
user_idbigintUnique ID for the database user.
start_timetimestamptzTimestamp for when the session started.
end_timetimestamptzTimestamp for when the session ended, if it is not still running.
process_idbigintUnique process ID for the session. Used internally for debugging purposes.
secure_connectionbooleanWhether the database connection is secure (SSL).
last_statementtimestamptzWhen the last SQL statement was started. This column is NULL if the session did not execute any statements.
statevarchar(256)If the session was shut down because of idle_in_transaction_timeout, the state is 25P03. If the session was shut down because of idle_session_timeout, the state is 25P04. Other states are idle and active. See also Managing Idle Sessions.
secure_detailsvarchar(256)For secure connections, the SSL version, cipher, and key size.

Example

Join sys.log_session to sys.database to return information about ybsql sessions that lasted longer than 1 second:

premdb=# select sd.name dbname, sd.database_id, user_id, session_id, application_name, end_time-start_time duration 
from sys.database sd, sys.log_session sls where sd.database_id=sls.database_id 
and application_name ='ybsql' and duration>'1 sec' 
order by sd.database_id, session_id;
     dbname      | database_id | user_id | session_id | application_name |    duration     
------------------+-------------+---------+------------+------------------+-----------------
 yellowbrick_test |       16588 |   16590 |      17232 | ybsql            | 00:00:11.774066
 yellowbrick_test |       16588 |   16590 |      18279 | ybsql            | 00:00:19.486412
 yellowbrick_test |       16588 |   16590 |      19941 | ybsql            | 00:00:30.966864
 yellowbrick_test |       16588 |   16590 |      23253 | ybsql            | 00:18:08.167864
 premdb           |       26259 |   26261 |      23285 | ybsql            | 00:00:35.007097
 premdb           |       26259 |   26261 |      23445 | ybsql            | 00:00:54.950788
(6 rows)

Parent topic:System Views