Skip to content

Instantly share code, notes, and snippets.

@nbenns
Last active October 24, 2019 01:30
Show Gist options
  • Save nbenns/f5636bc8e281aa3ea06ddf27c3fd30ff to your computer and use it in GitHub Desktop.
Save nbenns/f5636bc8e281aa3ea06ddf27c3fd30ff to your computer and use it in GitHub Desktop.
DB Queries
-- MySQL count same queries
SELECT substring_index(info, '/', 1), count(*) AS cnt
FROM INFORMATION_SCHEMA.PROCESSLIST
WHERE INFO IS NOT NULL
GROUP BY 1
HAVING cnt>1
ORDER BY cnt DESC;
-- MySQL show queries on DB
SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST WHERE DB='DB_NAME'
-- Show locks
SHOW OPEN TABLES WHERE In_use > 1;
-- POSTGRES --
-- Set search path
set search_path to public,other;
-- Storage Size of DB
SELECT pg_size_pretty( pg_database_size('db_name') );
-- Storage Size of Table
SELECT pg_size_pretty( pg_total_relation_size('table_name') );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment