Skip to content

Instantly share code, notes, and snippets.

View arsham's full-sized avatar

Arsham Shirvani arsham

View GitHub Profile
@arsham
arsham / list_ssh_tunnels
Created April 1, 2015 13:23
Lists ssh tunnles
sudo lsof -i -n | egrep '\<ssh\>'
@arsham
arsham / purge_queue.sh
Created April 20, 2015 09:42
Purges a rabbimq queue with celery
manage.py celery amqp queue.purge <QUEUE_NAME>
@arsham
arsham / IP.sh
Last active December 3, 2016 14:10
Shows only IP address
/sbin/ifconfig NET_NAME | grep 'inet ' | tr -s " " | cut -d " " -f3
@arsham
arsham / s3_mv
Created September 3, 2015 15:12
To move folders in amazon's S3 buckets
s3cmd mv s3://SOURCE_BUCKET/foo s3://DESTINATION_BUCKET/bar --recursive
@arsham
arsham / purge-celery-queue.sh
Last active June 5, 2016 09:49
Purge a celery queue
./manage.py celery amqp queue.purge <queue_name>
@arsham
arsham / Build a large index on postgres
Created March 4, 2016 17:19
If you are going to build a large index or do some other large query that can benefit from access to more RAM, set work_mem larger for your session
set work_mem = '56GB';
commit;
-- Do your work here.
-- Then be a good neighbour.
set work_mem = default;
commit;
@arsham
arsham / redirect output.sql
Last active June 5, 2016 09:44
Redirect the output of postgreSQL query to a file
-- To enable
\o output_file
SELECT * FROM .....;
-- TO disable
\o
@arsham
arsham / table io stats.sql
Last active June 5, 2016 09:44
Get IO stats for a particular table
select relname as "table",
heap_blks_read as "heap from disc",
heap_blks_hit as "heap from cache",
idx_blks_read as "index from disc",
idx_blks_hit as "index from cache",
toast_blks_read as "toast from disc",
toast_blks_hit as "toast from cache",
tidx_blks_read as "toast index disc",
tidx_blks_hit as "toast index cache"
from pg_statio_user_tables
@arsham
arsham / activity stats.sql
Last active June 5, 2016 09:44
Read activity stats for a particular table
select relname as "table",
seq_scan as "table scans",
idx_scan as "index lookups"
from pg_stat_user_tables
where relname = 'TABLE_NAME';
@arsham
arsham / table-activities.sql
Last active June 5, 2016 09:52
Read enhanced activity stats for a particular table
select relname as "table",
seq_scan as "table scans",
seq_tup_read as "tuples scanned",
idx_scan as "index lookups",
idx_tup_fetch as "tuples fetched via index"
from pg_stat_user_tables
where relname = 'TABLE_NAME';