How to use the @heroku-cli/plugin-pg-v5.fetcher function in @heroku-cli/plugin-pg-v5

To help you get started, we’ve selected a few @heroku-cli/plugin-pg-v5 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github heroku / heroku-pg-extras / commands / records_rank.js View on Github external
function * run (context, heroku) {
  let db = yield pg.fetcher(heroku).database(context.app, context.args.database)

  let query = `
SELECT
  relname AS name,
  n_live_tup AS estimated_count
FROM
  pg_stat_user_tables
ORDER BY
  n_live_tup DESC;
`

  let output = yield pg.psql.exec(db, query)
  process.stdout.write(output)
}
github heroku / heroku-pg-extras / commands / index_usage.js View on Github external
function * run (context, heroku) {
  let db = yield pg.fetcher(heroku).database(context.app, context.args.database)
  let output = yield pg.psql.exec(db, query)
  process.stdout.write(output)
}
github heroku / heroku-pg-extras / commands / table_indexes_size.js View on Github external
function * run (context, heroku) {
  let db = yield pg.fetcher(heroku).database(context.app, context.args.database)

  let query = `
SELECT c.relname AS table,
  pg_size_pretty(pg_indexes_size(c.oid)) AS index_size
FROM pg_class c
LEFT JOIN pg_namespace n ON (n.oid = c.relnamespace)
WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
AND n.nspname !~ '^pg_toast'
AND c.relkind='r'
ORDER BY pg_indexes_size(c.oid) DESC;
`

  let output = yield pg.psql.exec(db, query)
  process.stdout.write(output)
}
github heroku / heroku-pg-extras / commands / user_connections.js View on Github external
function * run (context, heroku) {
  const app = context.app
  const {database} = context.args

  let db = yield pg.fetcher(heroku).addon(app, database)
  yield util.ensureNonStarterPlan(db)
  let host = pg.host(db)

  let credentials = yield heroku.get(`/postgres/v0/databases/${db.name}/credentials`, { host: host })
  let defaultCredentials = _.filter(credentials, c => c.name === 'default')
  let defaultUsers = _.flatMap(defaultCredentials, c => _.map(c.credentials, u => u.user))

  let isDefaultUser = (user) => _.includes(defaultUsers, user)
  let styledName = (user) => {
    if (isDefaultUser(user)) {
      return 'default'
    } else {
      return user
    }
  }
github heroku / heroku-pg-extras / commands / unused_indexes.js View on Github external
function * run (context, heroku) {
  let db = yield pg.fetcher(heroku).database(context.app, context.args.database)

  let query = `
SELECT
  schemaname || '.' || relname AS table,
  indexrelname AS index,
  pg_size_pretty(pg_relation_size(i.indexrelid)) AS index_size,
  idx_scan as index_scans
FROM pg_stat_user_indexes ui
JOIN pg_index i ON ui.indexrelid = i.indexrelid
WHERE NOT indisunique AND idx_scan < 50 AND pg_relation_size(relid) > 5 * 8192
ORDER BY pg_relation_size(i.indexrelid) / nullif(idx_scan, 0) DESC NULLS FIRST,
pg_relation_size(i.indexrelid) DESC;
`

  let output = yield pg.psql.exec(db, query)
  process.stdout.write(output)
github heroku / heroku-pg-extras / commands / mandelbrot.js View on Github external
function * run (context, heroku) {
  let db = yield pg.fetcher(heroku).database(context.app, context.args.database)

  let query = `
  WITH RECURSIVE Z(IX, IY, CX, CY, X, Y, I) AS (
            SELECT IX, IY, X::float, Y::float, X::float, Y::float, 0
            FROM (select -2.2 + 0.031 * i, i from generate_series(0,101) as i) as xgen(x,ix),
                 (select -1.5 + 0.031 * i, i from generate_series(0,101) as i) as ygen(y,iy)
            UNION ALL
            SELECT IX, IY, CX, CY, X * X - Y * Y + CX AS X, Y * X * 2 + CY, I + 1
            FROM Z
            WHERE X * X + Y * Y < 16::float
            AND I < 100
      )
SELECT array_to_string(array_agg(SUBSTRING(' .,,,-----++++%%%%@@@@#### ', LEAST(GREATEST(I,1),27), 1)),'')
FROM (
      SELECT IX, IY, MAX(I) AS I
      FROM Z
github heroku / heroku-pg-extras / commands / stats_reset.js View on Github external
function * run (context, heroku) {
  const app = context.app
  const {database} = context.args

  let db = yield pg.fetcher(heroku).addon(app, database)
  yield util.ensureNonStarterPlan(db)
  let host = pg.host(db)
  let rsp = yield heroku.put(`/client/v11/databases/${db.name}/stats_reset`, {host})
  cli.log(rsp.message)
}
github heroku / heroku-pg-extras / commands / bloat.js View on Github external
function * run (context, heroku) {
  let db = yield pg.fetcher(heroku).database(context.app, context.args.database)

  let query = `
WITH constants AS (
  SELECT current_setting('block_size')::numeric AS bs, 23 AS hdr, 4 AS ma
), bloat_info AS (
  SELECT
    ma,bs,schemaname,tablename,
    (datawidth+(hdr+ma-(case when hdr%ma=0 THEN ma ELSE hdr%ma END)))::numeric AS datahdr,
    (maxfracsum*(nullhdr+ma-(case when nullhdr%ma=0 THEN ma ELSE nullhdr%ma END))) AS nullhdr2
  FROM (
    SELECT
      schemaname, tablename, hdr, ma, bs,
      SUM((1-null_frac)*avg_width) AS datawidth,
      MAX(null_frac) AS maxfracsum,
      hdr+(
        SELECT 1+count(*)/8
github heroku / heroku-pg-extras / commands / total_index_size.js View on Github external
function * run (context, heroku) {
  let db = yield pg.fetcher(heroku).database(context.app, context.args.database)
  let output = yield pg.psql.exec(db, query)
  process.stdout.write(output)
}
github heroku / heroku-pg-extras / commands / long_running_queries.js View on Github external
function * run (context, heroku) {
  let db = yield pg.fetcher(heroku).database(context.app, context.args.database)

  let query = `
SELECT
  pid,
  now() - pg_stat_activity.query_start AS duration,
  query AS query
FROM
  pg_stat_activity
WHERE
  pg_stat_activity.query <> ''::text
  AND state <> 'idle'
  AND now() - pg_stat_activity.query_start > interval '5 minutes'
ORDER BY
  now() - pg_stat_activity.query_start DESC;
`

@heroku-cli/plugin-pg-v5

Heroku CLI plugin to manage Postgres.

ISC
Latest version published 8 months ago

Package Health Score

74 / 100
Full package analysis