UNPKG

782 BJavaScriptView Raw
1'use strict'
2
3const co = require('co')
4const cli = require('heroku-cli-util')
5const pg = require('heroku-pg')
6
7function * run (context, heroku) {
8 let db = yield pg.fetcher(heroku).database(context.app, context.args.database)
9
10 let query = `
11SELECT relname AS name,
12 seq_scan as count
13FROM
14 pg_stat_user_tables
15ORDER BY seq_scan DESC;
16`
17
18 let output = yield pg.psql.exec(db, query)
19 process.stdout.write(output)
20}
21
22const cmd = {
23 topic: 'pg',
24 description: 'show the count of sequential scans by table descending by order',
25 needsApp: true,
26 needsAuth: true,
27 args: [{name: 'database', optional: true}],
28 run: cli.command(co.wrap(run))
29}
30
31module.exports = [
32 Object.assign({command: 'seq-scans'}, cmd),
33 Object.assign({command: 'seq_scans', hidden: true}, cmd)
34]