Skip to content

sys.session

This view returns a list of current 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.) The application name for replication operations is replication service.
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_timetimestamptzWhen the session started.
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.

Examples

Join the sys.session, sys.user, and sys.database views to return the details about current ybsql sessions:

premdb=# select ss.session_id, su.user_id, su.name username, su.superuser, sd.database_id, sd.name dbname 
from sys.session ss, sys.user su, sys.database sd where ss.user_id=su.user_id and ss.database_id=sd.database_id 
and application_name='ybsql';
 session_id | user_id | username | superuser | database_id |      dbname      
------------+---------+----------+-----------+-------------+------------------
     23281 |   16590 | ybd_test | f         |       16588 | yellowbrick_test
     23449 |   26261 | bobr     | t         |       26259 | premdb
(2 rows)

Return all active ybsql sessions:

yellowbrick_test=# select * from sys.session where state='active' and application_name='ybsql';
-[ RECORD 1 ]-----+---------------------------------------------
session_id        | 40424
application_name  | ybsql
client_hostname   | [NULL]
client_ip_address | 10.30.22.203/32
database_id       | 16388
user_id           | 16007
start_time        | 2020-01-28 15:04:19.48118-08
process_id        | 22371
secure_connection | t
last_statement    | 2020-01-28 15:07:12.48244-08
state             | active
secure_details    | TLSv1.2/ECDHE-RSA-AES256-GCM-SHA384/256 bits

Parent topic:System Views