CLOSE ALL USER SESSIONS

You might need to close all user sessions connected to a YugabyteDB database if, for example,  there is severe resource contention or you’re just feeling ornery (just kidding about that reason).

Here’s how…

First you need to be a super user. Let’s find out who is the super user, and log in as that user…

				
					yugabyte=> SELECT usename FROM pg_user WHERE usesuper;
 usename
----------
 odoo_sys
(1 row)

yugabyte=> \! ysqlsh -U odoo_sys
ysqlsh (11.2-YB-2.13.1.0-b0)
Type "help" for help.
				
			

Now let’s check who is connected…

				
					yugabyte=> SELECT usename, application_name, pid FROM pg_stat_activity;
 usename  | application_name |  pid
----------+------------------+-------
 yugabyte | ysqlsh           | 16813
 jim      | ysqlsh           | 16874
 jim      | ysqlsh           | 16886
 odoo_sys | ysqlsh           | 16957
          |                  |  1906
(5 rows)
				
			

Now let’s close all of the sessions, except the one we are on…

				
					yugabyte=> SELECT pg_terminate_backend(pid)
yugabyte->   FROM pg_stat_activity
yugabyte->  WHERE pid <> pg_backend_pid();
WARNING:  PID 1906 is not a PostgreSQL server process
 pg_terminate_backend
----------------------
 t
 t
 t
 f
(4 rows)

yugabyte=> SELECT usename, application_name, pid FROM pg_stat_activity;
 usename  | application_name |  pid
----------+------------------+-------
 odoo_sys | ysqlsh           | 16957
          |                  |  1906
(2 rows)
				
			

Have Fun!