cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

SHOW SESSIONS does not show all active sessions

Open tim-o opened this issue 8 years ago • 9 comments

Describe the problem

I'd expect that SHOW SESSIONS; would show all active sessions, including those initiated over jdbc or any other postgres:// string. However, this appears not to be the case. Locally, while running tests with dbeaver and running queries with Python, I'm only able to see my dbeaver connections.

A client reports that they're unable to see their jdbc connections with the attached script.

To Reproduce

Use the script here (CRDB only): https://cockroachlabs.slack.com/archives/C4UHCCUB0/p1543254119419400

Environment: v2.1.1

tim-o avatar Nov 26 '18 17:11 tim-o

Picked sql-pgwire somewhat arbitrarily since I'm not sure which area this fits under; feel free to adjust.

tim-o avatar Nov 26 '18 17:11 tim-o

This may not be it, but just in case it's worth noting that SHOW SESSIONS only shows sessions from the current user. If the different connection URLs are using different users, it's expected that they wouldn't show up.

a-robinson avatar Nov 26 '18 17:11 a-robinson

As per doco "No privileges are required to execute this statement. However, note that non-root users see only their own currently active sessions, wherease the root user sees all users' currently active sessions." I was running as ROOT.

https://www.cockroachlabs.com/docs/v2.1/show-sessions.html#main-content

slateraus avatar Nov 26 '18 17:11 slateraus

I'm not sure whether it's the docs or the implementation that's incorrect, but that's not how things work in my experience. cc @knz

a-robinson avatar Nov 26 '18 18:11 a-robinson

This works as I expect in version 2.1 but does not work in 2.1.1. For example in 2.1 I can see my sessions as follows.

root@crdb:26257/lee> select node_id, user_name, session_id, last_active_query from [show sessions] where user_name = 'lee'; node_id | user_name | session_id | last_active_query +---------+-----------+----------------------------------+-------------------------------------------------+ 4 | lee | 156ae9909f5c7aeb0000000000000004 | SELECT sum(balance) AS a FROM accounts 4 | lee | 156ae990f26f27e00000000000000004 | SET application_name = 'PostgreSQL JDBC Driver' 4 | lee | 156ae990a8a65c270000000000000004 | SET application_name = 'PostgreSQL JDBC Driver' 1 | lee | 156ae990e937a7540000000000000001 | SET application_name = 'PostgreSQL JDBC Driver' 1 | lee | 156ae990b1eb28730000000000000001 | SET application_name = 'PostgreSQL JDBC Driver' 3 | lee | 156ae990cd6428fa0000000000000003 | SET application_name = 'PostgreSQL JDBC Driver' 3 | lee | 156ae990d6d624330000000000000003 | SET application_name = 'PostgreSQL JDBC Driver' 5 | lee | 156ae990e014c85f0000000000000005 | SET application_name = 'PostgreSQL JDBC Driver' 5 | lee | 156ae990bb2ee2ea0000000000000005 | SET application_name = 'PostgreSQL JDBC Driver' 2 | lee | 156ae990c42fb3820000000000000002 | SET application_name = 'PostgreSQL JDBC Driver' (10 rows)

slateraus avatar Nov 27 '18 07:11 slateraus

cockroach version Build Tag: v2.1.0 Build Time: 2018/10/30 12:32:34 Distribution: CCL Platform: linux amd64 (x86_64-unknown-linux-gnu) Go Version: go1.10.3 C Compiler: gcc 6.3.0 Build SHA-1: f0dd1dc2d2500155c8b36330ae3d6932c13c1027 Build Type: release

slateraus avatar Nov 27 '18 07:11 slateraus

This behavior has probably been changed in #32253. Needs to be investigated.

knz avatar Nov 27 '18 12:11 knz

I have verified that indeed the root user has become unable to observe non-root sessions. This is a regression.

knz avatar Nov 27 '18 12:11 knz

@slateraus will hopefully be fixed in the next minor release

knz avatar Nov 29 '18 12:11 knz