sys.session

This view returns a list of current database sessions.

Column Name Data Type Description
session_id bigint Unique ID of the session.
application_name varchar(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_hostname varchar(256) Client host name, if available.
client_ip_address varchar(256) Client IP address.
database_id bigint Unique ID for the database.
user_id bigint Unique ID for the database user.
start_time timestamptz When the session started.
process_id bigint Unique process ID for the session. Used internally for debugging purposes.
secure_connection boolean Whether the database connection is secure (SSL).
last_statement timestamptz When the last SQL statement was started. This column is NULL if the session did not execute any statements.
state varchar(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_details varchar(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