Appearance
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, ym, ybload, or ybunload. 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) | SSL version, cipher, and key size. |
| cluster_name | varchar(256) | Name of the compute cluster where the session is running. |
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, 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 | database_id | dbname
------------+---------+-----------------------------+-------------+--------
1499660 | 16399 | trebor@yellowbrickcloud.com | 16400 | premdb
(1 row)Return all active ybsql sessions:
premdb=> select * from sys.session where state='active' and application_name='ybsql';
-[ RECORD 1 ]-----+---------------------------------------------
session_id | 1499490
application_name | ybsql
client_hostname |
client_ip_address | 10.0.123.231/32
database_id | 16400
user_id | 16395
start_time | 2022-10-03 18:07:07.383345-07
process_id | 42120
secure_connection | t
last_statement | 2022-10-03 18:08:44.929571-07
state | active
secure_details | TLSv1.2/ECDHE-RSA-AES256-GCM-SHA384/256 bits
cluster_name | large-default-clusterParent topic:System Views