UNPKG

917 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 pg_size_pretty(sum(c.relpages::bigint*8192)::bigint) AS size
9FROM pg_class c
10LEFT JOIN pg_namespace n ON (n.oid = c.relnamespace)
11WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
12AND n.nspname !~ '^pg_toast'
13AND c.relkind='i';
14`
15
16function * run (context, heroku) {
17 let db = yield pg.fetcher(heroku).database(context.app, context.args.database)
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 total size of all indexes in MB',
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: 'total-index-size'}, cmd),
33 Object.assign({command: 'total_index_size', hidden: true}, cmd)
34]