Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add view v_get_running_queries to AdminViews #710

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/AdminViews/README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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 |
Expand Down
22 changes: 22 additions & 0 deletions src/AdminViews/v_get_running_queries.sql
Original file line number Diff line number Diff line change
@@ -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
;