Skip to content

Instantly share code, notes, and snippets.

View phil-hildebrand's full-sized avatar

Phil Hildebrand phil-hildebrand

  • Robinhood.com
  • Seattle
View GitHub Profile
@namrata4
namrata4 / admin.sql
Last active March 16, 2024 17:24
Handy PostgreSQL Monitoring Scripts
-- turn off paging (less/more)
psql> \pset pager off
/*
Pager usage is off.
*/
-- find an object name by id
SELECT OID, relname
@phil-hildebrand
phil-hildebrand / connection_info.sql
Last active April 3, 2022 19:15
Handy MySQL information schema / processlist scripts
-- 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(*) |
@virusdave
virusdave / postgres_queries_and_commands.sql
Last active January 27, 2022 21:33 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- 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'