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 pg_size_pretty(sum(c.relpages::bigint*8192)::bigint) AS size
|
9 | FROM pg_class c
|
10 | LEFT JOIN pg_namespace n ON (n.oid = c.relnamespace)
|
11 | WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
|
12 | AND n.nspname !~ '^pg_toast'
|
13 | AND c.relkind='i';
|
14 | `
|
15 |
|
16 | function * 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 |
|
22 | const 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 |
|
31 | module.exports = [
|
32 | Object.assign({command: 'total-index-size'}, cmd),
|
33 | Object.assign({command: 'total_index_size', hidden: true}, cmd)
|
34 | ]
|