I hereby claim:
- I am dougcole on github.
- I am dougcole (https://keybase.io/dougcole) on keybase.
- I have a public key ASDTtsuupEhbdaE_b8iZcPro2VddC8iHN3MiGAiS0jqxUgo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
| module NilifyBlanks | |
| def nilify_blanks(*columns) | |
| columns.each do |column| | |
| value = read_attribute(column) | |
| write_attribute(column, nil) if value.blank? | |
| end | |
| end | |
| end |
| class ConcurrentQuery < BasicObject | |
| def initialize(&block) | |
| @query = ::Thread.new do | |
| result = begin | |
| block.call | |
| ensure | |
| ::ActiveRecord::Base.connection_pool.release_connection | |
| end | |
| result |
| class AccessDatabase | |
| def initialize | |
| @query_count = 0 | |
| @query_sql = [] | |
| end | |
| def matches?(target) | |
| subscription = ActiveSupport::Notifications.subscribe(/^sql\./) do |*args| | |
| @query_count += 1 | |
| @query_sql << args.last[:sql] |
| ***find the biggest tables | |
| select relname, pg_size_pretty(pg_relation_size(relname::text)) from pg_stat_user_tables where schemaname= 'public' order by pg_relation_size(relname::text) desc; | |
| ***find the biggest indexes | |
| select tablename, indexname, pg_size_pretty(pg_relation_size(indexname::text)) from pg_indexes where schemaname= 'public' order by pg_relation_size(indexname::text) desc; | |
| ***find indexes that are almost never used sorted by size. | |
| -if the application has changed significantly since the database was built, run pg_stat_reset() and wait for a few days to view only up-to-date statistics. | |
| SELECT idstat.relname AS table_name, | |
| indexrelname AS index_name, |
| select pg_class.relname,pg_locks.mode,pg_stat_activity.current_query from pg_class,pg_locks,pg_stat_activity where pg_class.relfilenode=pg_locks.relation and pg_stat_activity.procpid=pg_locks.pid; |