Check out example codes for "postgresql print sessions using the database". It will help you in understanding the concepts better.

Code Example 1

select pid as process_id, 
       usename as username, 
       datname as database_name, 
       client_addr as client_address, 
       application_name,
       backend_start,
       state,
       state_change
from pg_stat_activity;

Learn ReactJs, React Native from akashmittal.com