UNPKG

953 BJavaScriptView Raw
1'use strict'
2
3const co = require('co')
4const cli = require('heroku-cli-util')
5const pg = require('heroku-pg')
6
7const query = `
8SELECT
9 'index hit rate' AS name,
10 (sum(idx_blks_hit)) / nullif(sum(idx_blks_hit + idx_blks_read),0) AS ratio
11FROM pg_statio_user_indexes
12UNION ALL
13SELECT
14 'table hit rate' AS name,
15 sum(heap_blks_hit) / nullif(sum(heap_blks_hit) + sum(heap_blks_read),0) AS ratio
16FROM pg_statio_user_tables;
17`
18
19function * run (context, heroku) {
20 let db = yield pg.fetcher(heroku).database(context.app, context.args.database)
21 let output = yield pg.psql.exec(db, query)
22 process.stdout.write(output)
23}
24
25const cmd = {
26 topic: 'pg',
27 description: 'show the total size of all indexes in MB',
28 needsApp: true,
29 needsAuth: true,
30 args: [{name: 'database', optional: true}],
31 run: cli.command(co.wrap(run))
32}
33
34module.exports = [
35 Object.assign({command: 'cache-hit'}, cmd),
36 Object.assign({command: 'cache_hit', hidden: true}, cmd)
37]