Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
eablack committed Apr 24, 2024
1 parent 58e3608 commit 8541d2e
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions packages/cli/src/commands/pg/vacuum-stats.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// import color from '@heroku-cli/color'
import {Command, flags} from '@heroku-cli/command'
import {Args} from '@oclif/core'
import {Args, ux} from '@oclif/core'
import {database} from '../../lib/pg/fetcher'
// import * as Heroku from '@heroku-cli/schema'
import {exec} from '../../lib/pg/psql'
import heredoc from 'tsheredoc'

// const cli = require('heroku-cli-util')
export default class VacuumStats extends Command {
static topic = 'pg';
static description = 'show dead rows and whether an automatic vacuum is expected to be triggered';
Expand All @@ -21,10 +18,7 @@ export default class VacuumStats extends Command {

public async run(): Promise<void> {
const {flags, args} = await this.parse(VacuumStats)
// const fetcher = require('../lib/fetcher')(heroku)
// const psql = require('../lib/psql')
const db = await database(this.heroku, flags.app, args.database)
// const query = '\nWITH table_opts AS (\n SELECT\n pg_class.oid, relname, nspname, array_to_string(reloptions, \'\') AS relopts\n FROM\n pg_class INNER JOIN pg_namespace ns ON relnamespace = ns.oid\n), vacuum_settings AS (\n SELECT\n oid, relname, nspname,\n CASE\n WHEN relopts LIKE \'%autovacuum_vacuum_threshold%\'\n THEN substring(relopts, \'.*autovacuum_vacuum_threshold=([0-9.]+).*\')::integer\n ELSE current_setting(\'autovacuum_vacuum_threshold\')::integer\n END AS autovacuum_vacuum_threshold,\n CASE\n WHEN relopts LIKE \'%autovacuum_vacuum_scale_factor%\'\n THEN substring(relopts, \'.*autovacuum_vacuum_scale_factor=([0-9.]+).*\')::real\n ELSE current_setting(\'autovacuum_vacuum_scale_factor\')::real\n END AS autovacuum_vacuum_scale_factor\n FROM\n table_opts\n)\nSELECT\n vacuum_settings.nspname AS schema,\n vacuum_settings.relname AS table,\n to_char(psut.last_vacuum, \'YYYY-MM-DD HH24:MI\') AS last_vacuum,\n to_char(psut.last_autovacuum, \'YYYY-MM-DD HH24:MI\') AS last_autovacuum,\n to_char(pg_class.reltuples, \'9G999G999G999\') AS rowcount,\n to_char(psut.n_dead_tup, \'9G999G999G999\') AS dead_rowcount,\n to_char(autovacuum_vacuum_threshold\n + (autovacuum_vacuum_scale_factor::numeric * pg_class.reltuples), \'9G999G999G999\') AS autovacuum_threshold,\n CASE\n WHEN autovacuum_vacuum_threshold + (autovacuum_vacuum_scale_factor::numeric * pg_class.reltuples) < psut.n_dead_tup\n THEN \'yes\'\n END AS expect_autovacuum\nFROM\n pg_stat_user_tables psut INNER JOIN pg_class ON psut.relid = pg_class.oid\n INNER JOIN vacuum_settings ON pg_class.oid = vacuum_settings.oid\nORDER BY 1\n'
const query = heredoc(`
WITH table_opts AS (
SELECT
Expand Down Expand Up @@ -66,6 +60,6 @@ export default class VacuumStats extends Command {
ORDER BY 1
`)
const output = await exec(db, query)
process.stdout.write(output)
ux.log(output)
}
}

0 comments on commit 8541d2e

Please sign in to comment.