From 85ccbb6fdccbfe492aefa5928e82deaf671db50a Mon Sep 17 00:00:00 2001 From: Eric Black Date: Fri, 19 Apr 2024 14:22:36 -0700 Subject: [PATCH] Cleanup --- packages/cli/src/commands/pg/vacuum-stats.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/commands/pg/vacuum-stats.ts b/packages/cli/src/commands/pg/vacuum-stats.ts index 81dbe5efc9..677dac0d7e 100644 --- a/packages/cli/src/commands/pg/vacuum-stats.ts +++ b/packages/cli/src/commands/pg/vacuum-stats.ts @@ -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'; @@ -21,10 +18,7 @@ export default class VacuumStats extends Command { public async run(): Promise { 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 @@ -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) } }