SHOW SESSIONS does not show all active sessions
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
Picked sql-pgwire somewhat arbitrarily since I'm not sure which area this fits under; feel free to adjust.
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.
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
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
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)
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
This behavior has probably been changed in #32253. Needs to be investigated.
I have verified that indeed the root user has become unable to observe non-root sessions. This is a regression.
@slateraus will hopefully be fixed in the next minor release