1 | 'use strict'
|
2 |
|
3 | const co = require('co')
|
4 | const cli = require('heroku-cli-util')
|
5 | const pg = require('heroku-pg')
|
6 |
|
7 | const query = `
|
8 | SELECT
|
9 | 'index hit rate' AS name,
|
10 | (sum(idx_blks_hit)) / nullif(sum(idx_blks_hit + idx_blks_read),0) AS ratio
|
11 | FROM pg_statio_user_indexes
|
12 | UNION ALL
|
13 | SELECT
|
14 | 'table hit rate' AS name,
|
15 | sum(heap_blks_hit) / nullif(sum(heap_blks_hit) + sum(heap_blks_read),0) AS ratio
|
16 | FROM pg_statio_user_tables;
|
17 | `
|
18 |
|
19 | function * 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 |
|
25 | const 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 |
|
34 | module.exports = [
|
35 | Object.assign({command: 'cache-hit'}, cmd),
|
36 | Object.assign({command: 'cache_hit', hidden: true}, cmd)
|
37 | ]
|