##MONGODB & PYTHON
###Ubuntu Install
sudo apt-get install mongodb
pip install pymongo
Table - Collection
Column - Property
Row - Document
| #!/usr/bin/env python | |
| """strip outputs from an IPython Notebook | |
| Opens a notebook, strips its output, and writes the outputless version to the original file. | |
| Useful mainly as a git filter or pre-commit hook for users who don't want to track output in VCS. | |
| This does mostly the same thing as the `Clear All Output` command in the notebook UI. | |
| LICENSE: Public Domain |
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| import urllib2 | |
| gh_url = 'https://api.github.com' | |
| req = urllib2.Request(gh_url) | |
| password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() |
##MONGODB & PYTHON
###Ubuntu Install
sudo apt-get install mongodb
pip install pymongo
Table - Collection
Column - Property
Row - Document
| with table_stats as ( | |
| select psut.relname, | |
| psut.n_live_tup, | |
| 1.0 * psut.idx_scan / greatest(1, psut.seq_scan + psut.idx_scan) as index_use_ratio | |
| from pg_stat_user_tables psut | |
| order by psut.n_live_tup desc | |
| ), | |
| table_io as ( | |
| select psiut.relname, | |
| sum(psiut.heap_blks_read) as table_page_read, |
| ** Find commmonly accessed tables and their use of indexes: | |
| SELECT relname,seq_tup_read,idx_tup_fetch,cast(idx_tup_fetch AS numeric) / (idx_tup_fetch + seq_tup_read) AS idx_tup_pct FROM pg_stat_user_tables WHERE (idx_tup_fetch + seq_tup_read)>0 ORDER BY idx_tup_pct; | |
| Returns output like: | |
| relname | seq_tup_read | idx_tup_fetch | idx_tup_pct | |
| ----------------------+--------------+---------------+------------------------ | |
| schema_migrations | 817 | 0 | 0.00000000000000000000 | |
| user_device_photos | 349 | 0 | 0.00000000000000000000 |
| -- 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' |