-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding in active queries and table sizes
- Loading branch information
1 parent
bd4e709
commit fe49d63
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/*==================================================================================================== | ||
Active Queries - Cortland Goffena | ||
Shows information about current running queries in all databases. | ||
====================================================================================================*/ | ||
|
||
SELECT | ||
datname AS "DatabaseName", | ||
pid AS "PID", | ||
usename AS "Username", | ||
application_name AS "ApplicationName", | ||
--client_addr AS "ClientIPAddress", | ||
--client_hostname AS "ClientHostName", | ||
client_port AS "ClientPort", | ||
state AS "ProcessState", | ||
backend_start AS "ProcessStart", | ||
xact_start AS "TransactionStart", | ||
query_start AS "QueryStart", | ||
--query_id AS "QueryID", | ||
query AS "QueryText", | ||
wait_event_type AS "WaitEventType", | ||
wait_event AS "WaitEvent" | ||
FROM pg_stat_activity | ||
WHERE pid != pg_backend_pid() | ||
AND wait_event_type != 'Activity' | ||
AND state = 'active' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/*==================================================================================================== | ||
Table Stats - Cortland Goffena | ||
Shows space size and record size. | ||
Gives index percent of the total space. | ||
====================================================================================================*/ | ||
|
||
SELECT | ||
t.schemaname || '.' || t.relname AS "TableName", | ||
t.n_live_tup AS "RecordCount", | ||
pg_size_pretty(pg_total_relation_size(t.schemaname || '.' || t.relname)) AS "TableTotalSize", | ||
pg_size_pretty(pg_relation_size(t.schemaname || '.' || t.relname)) AS "TableDataSize", | ||
CASE WHEN pg_total_relation_size(t.schemaname || '.' || t.relname) > 0 | ||
AND pg_relation_size(t.schemaname || '.' || t.relname) > 0 | ||
THEN CAST( | ||
CAST(pg_relation_size(t.schemaname || '.' || t.relname) AS NUMERIC(19,4)) / | ||
CAST(pg_total_relation_size(t.schemaname || '.' || t.relname) AS NUMERIC(19,4)) | ||
AS NUMERIC(19,4)) | ||
ELSE 0 END AS "DataSizePercent", | ||
pg_size_pretty(pg_indexes_size(t.schemaname || '.' || t.relname)) AS "TableIndexSize", | ||
CASE WHEN pg_total_relation_size(t.schemaname || '.' || t.relname) > 0 | ||
AND pg_indexes_size(t.schemaname || '.' || t.relname) > 0 | ||
THEN CAST( | ||
CAST(pg_indexes_size(t.schemaname || '.' || t.relname) AS NUMERIC(19,4)) / | ||
CAST(pg_total_relation_size(t.schemaname || '.' || t.relname) AS NUMERIC(19,4)) | ||
AS NUMERIC(19,4)) | ||
ELSE 0 END AS "IndexSizePercent" | ||
FROM pg_stat_user_tables AS t | ||
ORDER BY t.n_live_tup DESC; |