diff --git a/src/AdminViews/README.md b/src/AdminViews/README.md index 573d3c80..f07ce0e9 100644 --- a/src/AdminViews/README.md +++ b/src/AdminViews/README.md @@ -1,4 +1,4 @@ -# Redshift Admin Views +# Redshift Admin Views Views objective is to help with administration of Redshift. All views assume you have a schema called admin. @@ -20,13 +20,14 @@ All views assume you have a schema called admin. | v\_generate\_terminate\_session.sql | View to get pg\_terminate\_backend() statements | | v\_generate\_udf\_ddl.sql | View to get the DDL for a UDF. | v\_generate\_unload\_copy\_cmd.sql | View to get that will generate unload and copy commands for an object. After running | -|v\_generate\_user\_grant\_revoke\_ddl.sql| View to generate grant or revoke ddl for users and groups in the database| +| v\_generate\_user\_grant\_revoke\_ddl.sql| View to generate grant or revoke ddl for users and groups in the database| | v\_generate\_user\_object\_permissions.sql | View to get the DDL for a users permissions to tables and views. | | v\_generate\_view\_ddl.sql | View to get the DDL for a view. | | v\_get\_blocking\_locks.sql | View to identify blocking locks as well as determine what/who is blocking a query | | v\_get\_cluster\_restart\_ts.sql | View to get the datetime of when Redshift cluster was recently restarted | | v\_get\_obj\_priv\_by\_user.sql | View to get the table/views that a user has access to | | v\_get\_schema\_priv\_by\_user.sql | View to get the schema that a user has access to | +| v\_get\_running\_queries.sql | View to get current running queries. | | v\_get\_tbl\_priv\_by\_user.sql | View to get the tables that a user has access to | | v\_get\_tbl\_priv\_by\_group.sql | View to get the tables that a user group has access to | | v\_get\_tbl\_reads\_and\_writes.sql | View to get operations performed per table for transactions ID or query ID | diff --git a/src/AdminViews/v_get_running_queries.sql b/src/AdminViews/v_get_running_queries.sql new file mode 100644 index 00000000..aa86edff --- /dev/null +++ b/src/AdminViews/v_get_running_queries.sql @@ -0,0 +1,22 @@ +/********************************************************************************************** +Purpose: View to get the running queries in the Redshift +History: +2022-08-15 whrocha Created +**********************************************************************************************/ +CREATE OR REPLACE VIEW admin.v_get_running_queries AS +SELECT a.txn_owner, + a.txn_db, + a.xid, + a.pid, + a.txn_start, + a.lock_mode, + a.granted, + b.pid AS blocking_pid, + (DATEDIFF(s, a.txn_start, GETDATE()) / 86400) AS days, + (DATEDIFF(s, a.txn_start, GETDATE()) % 86400 / 3600) AS hrs, + (DATEDIFF(s, a.txn_start, GETDATE()) % 3600 / 60) AS mins, + (DATEDIFF(s, a.txn_start, GETDATE()) % 60) AS secs +FROM svv_transactions a LEFT JOIN (SELECT pid, relation, granted FROM pg_locks GROUP BY 1, 2, 3) b ON a.relation = b.relation AND a.granted = 'f' AND b.granted = 't' +WHERE a.relation IS NOT NULL +ORDER BY txn_start +;