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
-- turn off paging (less/more) | |
psql> \pset pager off | |
/* | |
Pager usage is off. | |
*/ | |
-- find an object name by id | |
SELECT OID, relname |
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
-- Get Current sessions by state: | |
SELECT @@hostname as server, user,state,command,count(*) | |
FROM information_schema.processlist | |
GROUP BY user,state,command ; | |
/* | |
+-------------+-------------+---------------------------------------------------------------+-------------+----------+ | |
| server | user | state | command | count(*) | |
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
-- CHECK TIMINGS ON ACTIVE AND EXPENSIVE QUERIES | |
SELECT activity.* | |
FROM ( | |
SELECT | |
pid, | |
CASE WHEN state = 'active' THEN AGE(clock_timestamp(), query_start) | |
ELSE AGE(state_change, query_start) | |
END as query_duration, -- This is how long the most recent query was running (or is running so far, if still active) | |
AGE(clock_timestamp(), xact_start) as xact_duration, -- Same, but for the currently active transaction | |
CASE WHEN state = 'active' THEN INTERVAL '0' |