GithubHelp home page GithubHelp logo

heroku / heroku-pg-extras Goto Github PK

View Code? Open in Web Editor NEW
1.3K 130.0 102.0 407 KB

A heroku plugin for awesome pg:* commands that are also great and fun and super.

License: MIT License

JavaScript 100.00%
heroku heroku-cli-plugin heroku-data

heroku-pg-extras's Introduction

pg-extras CLI Plugin

A Heroku CLI plugin providing shortcuts to common Postgres introspection queries.

This plugin is used to obtain information about a Heroku Postgres instance, that may be useful when analyzing performance issues. This includes information about locks, index usage, buffer cache hit ratios and vacuum statistics.

Installation

$ heroku plugins:install heroku-pg-extras

Usage

Each command can display more detailed usage information, including accepted flags, with heroku help pg:<command>.

pg:cache-hit

$ heroku pg:cache-hit
      name      |         ratio
----------------+------------------------
 index hit rate | 0.99957765013541945832
 table hit rate |                   1.00
(2 rows)

This command provides information on the efficiency of the buffer cache, for both index reads (index hit rate) as well as table reads (table hit rate). A low buffer cache hit ratio can be a sign that the Heroku Postgres plan is too small for the workload.

pg:index-usage

$ heroku pg:index-usage
       relname       | percent_of_times_index_used | rows_in_table
---------------------+-----------------------------+---------------
 events              |                          65 |       1217347
 app_infos           |                          74 |        314057
 app_infos_user_info |                           0 |        198848
 user_info           |                           5 |         94545
 delayed_jobs        |                          27 |             0
(5 rows)

This command provides information on the efficiency of indexes, represented as what percentage of total scans were index scans. A low percentage can indicate under indexing, or wrong data being indexed.

pg:locks

$ heroku pg:locks
 procpid | relname | transactionid | granted |     query_snippet     |       age
---------+---------+---------------+---------+-----------------------+-----------------
   31776 |         |               | t       | <IDLE> in transaction | 00:19:29.837898
   31776 |         |          1294 | t       | <IDLE> in transaction | 00:19:29.837898
   31912 |         |               | t       | select * from hello;  | 00:19:17.94259
    3443 |         |               | t       |                      +| 00:00:00
         |         |               |         |    select            +|
         |         |               |         |      pg_stat_activi   |
(4 rows)

This command displays queries that have taken out an exclusive lock on a relation. Exclusive locks typically prevent other operations on that relation from taking place, and can be a cause of "hung" queries that are waiting for a lock to be granted.

pg:outliers

$ heroku pg:outliers
                   qry                   |    exec_time     | prop_exec_time |   ncalls    | sync_io_time
-----------------------------------------+------------------+----------------+-------------+--------------
 SELECT * FROM archivable_usage_events.. | 154:39:26.431466 | 72.2%          | 34,211,877  | 00:00:00
 COPY public.archivable_usage_events (.. | 50:38:33.198418  | 23.6%          | 13          | 13:34:21.00108
 COPY public.usage_events (id, reporte.. | 02:32:16.335233  | 1.2%           | 13          | 00:34:19.784318
 INSERT INTO usage_events (id, retaine.. | 01:42:59.436532  | 0.8%           | 12,328,187  | 00:00:00
 SELECT * FROM usage_events WHERE (alp.. | 01:18:10.754354  | 0.6%           | 102,114,301 | 00:00:00
 UPDATE usage_events SET reporter_id =.. | 00:52:35.683254  | 0.4%           | 23,786,348  | 00:00:00
 INSERT INTO usage_events (id, retaine.. | 00:49:24.952561  | 0.4%           | 21,988,201  | 00:00:00
 COPY public.app_ownership_events (id,.. | 00:37:14.31082   | 0.3%           | 13          | 00:12:32.584754
 INSERT INTO app_ownership_events (id,.. | 00:26:59.808212  | 0.2%           | 383,109     | 00:00:00
 SELECT * FROM app_ownership_events   .. | 00:19:06.021846  | 0.1%           | 744,879     | 00:00:00
(10 rows)

This command displays statements, obtained from pg_stat_statements, ordered by the amount of time to execute in aggregate. This includes the statement itself, the total execution time for that statement, the proportion of total execution time for all statements that statement has taken up, the number of times that statement has been called, and the amount of time that statement spent on synchronous I/O (reading/writing from the filesystem).

Typically, an efficient query will have an appropriate ratio of calls to total execution time, with as little time spent on I/O as possible. Queries that have a high total execution time but low call count should be investigated to improve their performance. Queries that have a high proportion of execution time being spent on synchronous I/O should also be investigated.

pg:calls

$ heroku pg:calls
                   qry                   |    exec_time     | prop_exec_time |   ncalls    | sync_io_time
-----------------------------------------+------------------+----------------+-------------+--------------
 SELECT * FROM usage_events WHERE (alp.. | 01:18:11.073333  | 0.6%           | 102,120,780 | 00:00:00
 BEGIN                                   | 00:00:51.285988  | 0.0%           | 47,288,662  | 00:00:00
 COMMIT                                  | 00:00:52.31724   | 0.0%           | 47,288,615  | 00:00:00
 SELECT * FROM  archivable_usage_event.. | 154:39:26.431466 | 72.2%          | 34,211,877  | 00:00:00
 UPDATE usage_events SET reporter_id =.. | 00:52:35.986167  | 0.4%           | 23,788,388  | 00:00:00
 INSERT INTO usage_events (id, retaine.. | 00:49:25.260245  | 0.4%           | 21,990,326  | 00:00:00
 INSERT INTO usage_events (id, retaine.. | 01:42:59.436532  | 0.8%           | 12,328,187  | 00:00:00
 SELECT * FROM app_ownership_events   .. | 00:19:06.289521  | 0.1%           | 744,976     | 00:00:00
 INSERT INTO app_ownership_events(id, .. | 00:26:59.885631  | 0.2%           | 383,153     | 00:00:00
 UPDATE app_ownership_events SET app_i.. | 00:01:22.282337  | 0.0%           | 359,741     | 00:00:00
(10 rows)

This command is much like pg:outliers, but ordered by the number of times a statement has been called.

pg:blocking

$ heroku pg:blocking
 blocked_pid |    blocking_statement    | blocking_duration | blocking_pid |                                        blocked_statement                           | blocked_duration
-------------+--------------------------+-------------------+--------------+------------------------------------------------------------------------------------+------------------
         461 | select count(*) from app | 00:00:03.838314   |        15682 | UPDATE "app" SET "updated_at" = '2013-03-04 15:07:04.746688' WHERE "id" = 12823149 | 00:00:03.821826
(1 row)

This command displays statements that are currently holding locks that other statements are waiting to be released. This can be used in conjunction with pg:locks to determine which statements need to be terminated in order to resolve lock contention.

pg:total-index-size

$ heroku pg:total-index-size
  size
-------
 28194 MB
(1 row)

This command displays the total size of all indexes on the database, in MB. It is calculated by taking the number of pages (reported in relpages) and multiplying it by the page size (8192 bytes).

pg:index-size

$ heroku pg:index-size
                             name                              |  size
---------------------------------------------------------------+---------
 idx_activity_attemptable_and_type_lesson_enrollment           | 5196 MB
 index_enrollment_attemptables_by_attempt_and_last_in_group    | 4045 MB
 index_attempts_on_student_id                                  | 2611 MB
 enrollment_activity_attemptables_pkey                         | 2513 MB
 index_attempts_on_student_id_final_attemptable_type           | 2466 MB
 attempts_pkey                                                 | 2466 MB
 index_attempts_on_response_id                                 | 2404 MB
 index_attempts_on_enrollment_id                               | 1957 MB
 index_enrollment_attemptables_by_enrollment_activity_id       | 1789 MB
 enrollment_activities_pkey                                    |  458 MB
 index_enrollment_activities_by_lesson_enrollment_and_activity |  402 MB
 index_placement_attempts_on_response_id                       |  109 MB
 index_placement_attempts_on_placement_test_id                 |  108 MB
 index_placement_attempts_on_grade_level_id                    |   97 MB
 index_lesson_enrollments_on_lesson_id                         |   93 MB
(truncated results for brevity)

This command displays the size of each each index in the database, in MB. It is calculated by taking the number of pages (reported in relpages) and multiplying it by the page size (8192 bytes).

pg:table-size

$ heroku pg:table-size
                             name                              |  size
---------------------------------------------------------------+---------
 learning_coaches                                              |  196 MB
 states                                                        |  145 MB
 grade_levels                                                  |  111 MB
 charities_customers                                           |   73 MB
 charities                                                     |   66 MB
(truncated results for brevity)

This command displays the size of each table in the database, in MB. It is calculated by using the system administration function pg_table_size(), which includes the size of the main data fork, free space map, visibility map and TOAST data.

pg:table-indexes-size

$ heroku pg:table-indexes-size
                             table                             | indexes_size
---------------------------------------------------------------+--------------
 learning_coaches                                              |    153 MB
 states                                                        |    125 MB
 charities_customers                                           |     93 MB
 charities                                                     |     16 MB
 grade_levels                                                  |     11 MB
(truncated results for brevity)

This command displays the total size of indexes for each table, in MB. It is calculates by using the system administration function pg_indexes_size().

pg:total-table-size

$ heroku pg:total-table-size
                             name                              |  size
---------------------------------------------------------------+---------
 learning_coaches                                              |  349 MB
 states                                                        |  270 MB
 charities_customers                                           |  166 MB
 grade_levels                                                  |  122 MB
 charities                                                     |   82 MB
(truncated results for brevity)

This command displays the total size of each table in the database, in MB. It is calculated by using the system administration function pg_total_relation_size(), which includes table size, total index size and TOAST data.

pg:unused-indexes

$ heroku pg:unused-indexes
          table      |                       index                | index_size | index_scans
---------------------+--------------------------------------------+------------+-------------
 public.grade_levels | index_placement_attempts_on_grade_level_id | 97 MB      |           0
 public.observations | observations_attrs_grade_resources         | 33 MB      |           0
 public.messages     | user_resource_id_idx                       | 12 MB      |           0
(3 rows)

This command displays indexes that have < 50 scans recorded against them, and are greater than 5 pages in size, ordered by size relative to the number of index scans. This command is generally useful for eliminating indexes that are unused, which can impact write performance, as well as read performance should they occupy space in memory.

pg:seq-scans

$ heroku pg:seq-scans

               name                |  count
-----------------------------------+----------
 learning_coaches                  | 44820063
 states                            | 36794975
 grade_levels                      | 13972293
 charities_customers               |  8615277
 charities                         |  4316276
 messages                          |  3922247
 contests_customers                |  2915972
 classroom_goals                   |  2142014
 contests                          |  1370267
 goals                             |  1112659
 districts                         |   158995
 rollup_reports                    |   115942
 customers                         |    93847
 schools                           |    92984
 classrooms                        |    92982
 customer_settings                 |    91226
(truncated results for brevity)

This command displays the number of sequential scans recorded against all tables, descending by count of sequential scans. Tables that have very high numbers of sequential scans may be underindexed, and it may be worth investigating queries that read from these tables.

pg:long-running-queries

$ heroku pg:long-running-queries

  pid  |    duration     |                                      query
-------+-----------------+---------------------------------------------------------------------------------------
 19578 | 02:29:11.200129 | EXPLAIN SELECT  "students".* FROM "students"  WHERE "students"."id" = 1450645 LIMIT 1
 19465 | 02:26:05.542653 | EXPLAIN SELECT  "students".* FROM "students"  WHERE "students"."id" = 1889881 LIMIT 1
 19632 | 02:24:46.962818 | EXPLAIN SELECT  "students".* FROM "students"  WHERE "students"."id" = 1581884 LIMIT 1
(truncated results for brevity)

This command displays currently running queries, that have been running for longer than 5 minutes, descending by duration. Very long running queries can be a source of multiple issues, such as preventing DDL statements completing or vacuum being unable to update relfrozenxid.

pg:records-rank

$ heroku pg:records_rank
               name                | estimated_count
-----------------------------------+-----------------
 tastypie_apiaccess                |          568891
 notifications_event               |          381227
 core_todo                         |          178614
 core_comment                      |          123969
 notifications_notification        |          102101
 django_session                    |           68078
 (truncated results for brevity)

This command displays an estimated count of rows per table, descending by estimated count. The estimated count is derived from n_live_tup, which is updated by vacuum operations. Due to the way n_live_tup is populated, sparse vs. dense pages can result in estimations that are significantly out from the real count of rows.

pg:bloat

$ heroku pg:bloat

 type  | schemaname |           object_name         | bloat |   waste
-------+------------+-------------------------------+-------+----------
 table | public     | bloated_table                 |   1.1 | 98 MB
 table | public     | other_bloated_table           |   1.1 | 58 MB
 index | public     | bloated_table::bloated_index  |   3.7 | 34 MB
 table | public     | clean_table                   |   0.2 | 3808 kB
 table | public     | other_clean_table             |   0.3 | 1576 kB

This command displays an estimation of table "bloat" – space allocated to a relation that is full of dead tuples, that has yet to be reclaimed. Tables that have a high bloat ratio, typically 10 or greater, should be investigated to see if vacuuming is aggressive enough, and can be a sign of high table churn.

pg:vacuum-stats

$ heroku pg:vacuum-stats
 schema |         table         | last_vacuum | last_autovacuum  |    rowcount    | dead_rowcount  | autovacuum_threshold | expect_autovacuum
--------+-----------------------+-------------+------------------+----------------+----------------+----------------------+-------------------
 public | log_table             |             | 2013-04-26 17:37 |         18,030 |              0 |          3,656       |
 public | data_table            |             | 2013-04-26 13:09 |             79 |             28 |             66       |
 public | other_table           |             | 2013-04-26 11:41 |             41 |             47 |             58       |
 public | queue_table           |             | 2013-04-26 17:39 |             12 |          8,228 |             52       | yes
 public | picnic_table          |             |                  |             13 |              0 |             53       |

This command displays statistics related to vacuum operations for each table, including an estimation of dead rows, last autovacuum and the current autovacuum threshold. This command can be useful when determining if current vacuum thresholds require adjustments, and to determine when the table was last vacuumed.

pg:user-connections

$ heroku pg:user-connections
Credential      Connections
──────────────  ───────────
ua7almfsv0d8tq  24

This command displays the number of open connections for each role. This is primarily useful for determining if a specific role is consuming many more connections than expected.

pg:mandelbrot

$ heroku pg:mandelbrot

This command outputs the Mandelbrot set, calculated through SQL.

Publishing

To publish new versions, see the data plugin documentation.

THIS IS BETA SOFTWARE

Thanks for trying it out. If you find any issues, please open an issue.

heroku-pg-extras's People

Contributors

andscoop avatar beanieboi avatar binarycleric avatar camillebaldock avatar catalectic avatar catsby avatar coreypurcell avatar craigkerstiens avatar cyberdelia avatar damonmorgan avatar hgmnz avatar jdowning avatar jdx avatar jheikes515 avatar jpadilla avatar keiko713 avatar mandagill avatar mble avatar mikelikesbikes avatar mimen avatar mmcgrana avatar msakrejda avatar nekopanic avatar neovintage avatar petergeoghegan avatar scottshea avatar svc-scm avatar tcrayford avatar will avatar wuputah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

heroku-pg-extras's Issues

Running pg:promote yields: `Can not find add-on with "HEROKU_POSTGRESQL_TEAL_URL"`

This started happening in the last 24 hours.

List our DBs:

$ heroku pg --app y-fix-small-ansible-related-bu
=== HEROKU_POSTGRESQL_IVORY_URL (DATABASE_URL)
Plan:               Standard 0
Status:             Available
Data Size:          37.8 MB
Tables:             35
PG Version:         9.4.1
Connections:        5/120
Fork/Follow:        Available
Rollback:           earliest from 2015-05-05 17:05 UTC
Created:            2015-05-05 17:03 UTC
Maintenance:        not required
Maintenance window: Thursdays 19:00 to 23:00 UTC

=== HEROKU_POSTGRESQL_TEAL_URL
Plan:        Hobby-basic
Status:      Available
Connections: 1/20
PG Version:  9.4.1
Created:     2015-05-05 17:08 UTC
Data Size:   37.0 MB
Tables:      35
Rows:        81705/10000000 (In compliance)
Fork/Follow: Unsupported
Rollback:    Unsupported

Promote the Teal DB:

$ heroku pg:promote HEROKU_POSTGRESQL_TEAL_URL --app y-fix-small-ansible-related-bu
 !    Can not find add-on with "HEROKU_POSTGRESQL_TEAL_URL"

This error looks suspect to me: Can not find add-on with "HEROKU_POSTGRESQL_TEAL_URL"

Outliers doesn't always report a query?

 total_exec_time | prop_exec_time |   ncalls   |  sync_io_time   |                                                                                                                                                                                                                                                     query                                                                                                                                                                                                                                                     
-----------------+----------------+------------+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 183:15:01.46537 | 33.9%          | 1,098      | 00:00:00        | 
 39:35:47.241997 | 7.3%           | 3,409      | 00:00:47.694985 | 
 34:56:59.867606 | 6.5%           | 112,718    | 00:01:30.863298 | 
 25:38:39.198269 | 4.7%           | 13,119,228 | 01:42:07.078046 | 
 17:51:37.385149 | 3.3%           | 1,201      | 00:00:00        |< A QUERY>
 11:58:47.164366 | 2.2%           | 5,189,969  | 03:30:00.709405 | 
 11:01:31.743686 | 2.0%           | 3,734      | 00:00:00        | 
 07:57:54.580272 | 1.5%           | 160,098    | 05:05:18.541591 | 
 07:16:58.959337 | 1.3%           | 486        | 00:00:00.90561  | 
 06:36:02.431033 | 1.2%           | 148,375    | 00:00:33.633563 | 

feature: display number of active connections

Considering recent changes in the number of connections policy, and advising people to use connection poolers, it would be very useful to have task which displays the number of active connections. Something like: heroku pg:connections.

Warn on no local psql

pg-extras requires the psql binary be available. We should warn the user if they have pg-extras installed, but no psql found

pgbench command

Feature request for a pgbench command that behaves like psql

index_usage is a bit muddled

pg:index_usage doesn't indicate index hit rate (in terms of blocks hit and missed). It indicates the number of index scans as against the number of sequential scans (in terms of the number of physical scans of each type of relation performed in order to satisfy queries). This is clearly incorrect, because the comment (which appears in help too) says:

calculates your index hit rate (effective databases are at 99% and up)

Hit rate comes from pg_statio___tables, not pg_stat___tables.

So decide if the comment is wrong or the code, and fix one or the other.

Naming conventions

Cleaning up the README for the vacuum PR, I noticed some inconsistencies in naming fields in the various queries we run, most notably referring to tables ('name', 'relname', 'table_name', 'table' are all used). Also, some queries include the schema; most omit it. It would be good to have some consistency here. How about the following:

  • use 'table' to refer to table names
  • omit schema if 'public', otherwise prepend it to the table name with a delimiter ('::' ?)

pgbackups:transfer

Got a weird error trying to use this today. Here's the situation:

We have a 9.1 zilla db that we are trying to convert to 9.2. Since we can't setup a follower between versions it seemed like the transfer method was the right solution rather than backing up the existing 9.1 db and then restoring that into a 9.2 db (what we have done in the past).

So I ran this:

heroku pgbackups:transfer HEROKU_POSTGRESQL_ORANGE_URL HEROKU_POSTGRESQL_CHARCOAL_URL -a someapp

and got

"! a transfer is currently in progress"

Doesn't seem like there is a transfer in progress and don't even see that error in the code committed for this feature so I assume something else is going on? I can send this to Heroku support if you think this is something to do with our specific account but figured I would ask here first.

Unable to install on Mac

$ heroku version
heroku-toolbelt/3.15.0 (x86_64-darwin10.8.0) ruby/1.9.3

issue:

$ heroku plugins:install git://github.com/heroku/heroku-pg-extras.git
Installing heroku-pg-extras... failed
 !    Unable to load plugin heroku-pg-extras.
 !    Search for help at: https://help.heroku.com
 !    Or report a bug at: https://github.com/heroku/heroku/issues/new

    Error:       no such command: pg:cache-hit (RuntimeError)

Error with heroku pg:push

Hi there,

Firstly thanks for the extensions great idea and direction.

The bad news is: I am getting an error when trying to make use of the pg:push functionality.

undefined local variable or method `generate_resolver' for #<Heroku::Command::Pg:0x007f86a449a750> (NameError)

When following the pattern:

heroku pg:push postgres://[email protected]:5432/__db_name__ postgres://__user__:__pass__@__host__/__db__ --app data-services-__numbers__

any thoughts?

Add command for which shows what pg:cache-hit show for each table?

I modified this code:

SELECT
    relname,
    heap_blks_hit,
    heap_blks_read,
    heap_blks_hit + heap_blks_read AS total_read,
    heap_blks_hit / (heap_blks_hit + heap_blks_read + 1)::float AS ratio 
FROM pg_statio_user_tables
ORDER BY ratio DESC;

I was checking the cache rate in staging and production.
The ratios seem so different so I decide to get the ratio for every table to find out what's not cached.
It's easier to understand after reading the actual read & hit numbers separated by tables.

Not Working on Ubuntu 12.04

Hey all,

I'm trying to get pg-extras working, but am having issues. Here's what I get after installing the plugin successfully, and attempting to run cache_hit:

$ heroku pg:cache_hit                                                

 !    Heroku client internal error.
 !    Search for help at: https://help.heroku.com
 !    Or report a bug at: https://github.com/heroku/heroku/issues/new

    Error:       undefined local variable or method `find_uri' for #<Heroku::Command::Pg:0x000000029818c0> (NameError)
    Backtrace:   /home/rdegges/.heroku/plugins/heroku-pg-extras/init.rb:464:in `exec_sql'
                 /home/rdegges/.heroku/plugins/heroku-pg-extras/init.rb:25:in `cache_hit'
                 /home/rdegges/.rvm/gems/ruby-1.9.3-p374/gems/heroku-2.39.3/lib/heroku/command.rb:206:in `run'
                 /home/rdegges/.rvm/gems/ruby-1.9.3-p374/gems/heroku-2.39.3/lib/heroku/cli.rb:28:in `start'
                 /home/rdegges/.rvm/gems/ruby-1.9.3-p374/gems/heroku-2.39.3/bin/heroku:17:in `<top (required)>'
                 /home/rdegges/.rvm/gems/ruby-1.9.3-p374/bin/heroku:19:in `load'
                 /home/rdegges/.rvm/gems/ruby-1.9.3-p374/bin/heroku:19:in `<main>'
                 /home/rdegges/.rvm/gems/ruby-1.9.3-p374/bin/ruby_noexec_wrapper:14:in `eval'
                 /home/rdegges/.rvm/gems/ruby-1.9.3-p374/bin/ruby_noexec_wrapper:14:in `<main>'

    Command:     heroku pg:cache_hit
    Plugins:     heroku-accounts
                 heroku-config
                 heroku-pg-extras
                 heroku-production-check
                 heroku.json

    Version:     heroku-gem/2.39.3 (x86_64-linux) ruby/1.9.3

9.2 support

this should support the new columns in 9.2

requested by @TheCorp on original "will" repo

Open pg:push/pull feedback

This issue is for collecting feedback on pg:push and pg:pull. These two commands will soon be promted from pg-extras into the Heroku Toolbelt proper. When this happens the existing db:push and db:pull commands will become deprecated, and later removed to a plugin. The documentation here is also serves as a draft for the eventual devcenter article.

background

For extraordinarily simple and tiny databases, the old db:* commands are alright, but they are unsuitable for any database that uses real postgres features—or for any database bigger than "tiny". With more and more people having trouble with those commands, we needed a modern replacement.

Unlike the db:* commands which read all your data into ruby and tries to massage data between sqlite and postgres if needed, the new pg:push/pull commands the same binary pg_dump and pg_restore commands that are standard for moving postgres data around. The downside is that this replacement does not work with sqlite. The upsides however are that it actually works, and is often very fast due to the native compression pg_dump does.

installing

If you are new to the pg-extras plugin, please see the installation instructionsin the readme. Please note that currently, pg-extras requires a Heroku Toolbelt version ≥2.40.0.

You must also have a working local postgres installation.

usage

pg:pull

pg:pull can be used to pull remote data from a Heroku Postgres database to a database on your local machine. The command looks like this:

$ heroku pg:pull DATABASE mylocaldb --app sushi

This command will create a new local database named "mylocaldb" and then pull data from database at DATABASE_URL from the app "sushi". In order to prevent accidental data overwrites and loss, the local database must not exist. You will be prompted to drop an already existing local database before proceeding.

Note: like all pg:* comamnds you can use the shorthand identifiers here, so to pull data from HEROKU_POSTGRESQL_RED on the app "sushi" you could do heroku pg:pull sushi::RED mylocaldb.

pg:push

Like pull but in reverse, pg:push will push data from a local database into a remote Heroku Postgres database. The command looks like this:

$ heroku pg:push mylocaldb DATABASE --app sushi

This command will take the local database "mylocaldb" and push it to the database at DATABASE_URL on the app "sushi". In order to prevent accidental data overwrites and loss, the remote database must be empty. You will be prompted to pg:reset an already a remote database that is not empty.

feedback

Please use this issue for any feedback on this upcoming feature or documentation.

Wrong warning telling hpg_resolve is deprecated

$ h pgbackups:transfer HEROKU_POSTGRESQL_GREEN_URL HEROKU_POSTGRESQL_PURPLE_URL
 !    #hpg_resolve is deprecated. Please run `heroku plugins:update` to update your plugins.
 !    from: /Users/raulb/.heroku/plugins/heroku-pg-extras/lib/heroku/command/pgbackups.rb:59:in `resolve_transfer'
 !    #hpg_resolve is deprecated. Please run `heroku plugins:update` to update your plugins.
 !    from: /Users/raulb/.heroku/plugins/heroku-pg-extras/lib/heroku/command/pgbackups.rb:59:in `resolve_transfer'

$ h plugins:update heroku-pg-extras
Updating heroku-pg-extras... done

$ h pgbackups:transfer HEROKU_POSTGRESQL_GREEN_URL HEROKU_POSTGRESQL_PURPLE_URL
 !    #hpg_resolve is deprecated. Please run `heroku plugins:update` to update your plugins.
 !    from: /Users/raulb/.heroku/plugins/heroku-pg-extras/lib/heroku/command/pgbackups.rb:59:in `resolve_transfer'
 !    #hpg_resolve is deprecated. Please run `heroku plugins:update` to update your plugins.
 !    from: /Users/raulb/.heroku/plugins/heroku-pg-extras/lib/heroku/command/pgbackups.rb:59:in `resolve_transfer'

In case it conflicts with other plugins...

$ h plugins
=== Installed Plugins
heroku-bundles
heroku-lunch
heroku-oauth
heroku-pg-extras
heroku-pipeline
heroku-repos
heroku-snitch
heroku-sudo
heroku-two-factor

pg:backups info output

OK, here are a few update to pgbackups:info that should make everything more understandable to users. @deafbybeheading Some of these may need to be to be done transferatu .

  1. Status should be "Completed Successfully", instead of Complete
  2. Show Original DB Size.
  3. Show Backup size and compression amount.
  4. Give the logs section a proper header and call it "Backup Logs" instead of "Logs".
=== Backup info: b003
Database: COLORLESS
Started:  2014-11-13 21:55:19 +0000
Finished: 2014-11-13 21:56:54 +0000
Status:   Completed Successfully
Type:     Manual
Original DB Size: 500 MB
Backup Size:     143 MB (71% compression)

=== Backup Logs
2014-11-13 21:55:20 +0000: Running /app/bin/pg/9.3/bin/pg_dump --no-owner --no-privileges --verbose --format custom postgres://...
2014-11-13 21:55:20 +0000: Running gof3r put -b xfrtu -k ed3312e2-33a8-479c-abcc-d40fbb04d181/2014-11-13T21:55:18Z/db390682-5aa7-46c0-a4e3-6de8c8bcbe99 -m x-amz-server-side-encryption:AES256
2014-11-13 21:55:20 +0000: pg_dump: reading schemas
2014-11-13 21:55:20 +0000: pg_dump: reading user-defined tables
2014-11-13 21:55:21 +0000: pg_dump: reading extensions
2014-11-13 21:55:21 +0000: pg_dump: reading user-defined functions
2014-11-13 21:55:21 +0000: pg_dump: reading user-defined types
2014-11-13 21:55:21 +0000: pg_dump: reading procedural languages
2014-11-13 21:55:21 +0000: pg_dump: reading user-defined aggregate functions
2014-11-13 21:55:21 +0000: pg_dump: reading user-defined operators
2014-11-13 21:55:21 +0000: pg_dump: reading user-defined operator classes
2014-11-13 21:55:21 +0000: pg_dump: reading user-defined operator families
2014-11-13 21:55:21 +0000: pg_dump: reading user-defined text search parsers
2014-11-13 21:55:21 +0000: pg_dump: reading user-defined text search templates
2014-11-13 21:55:21 +0000: pg_dump: reading user-defined text search dictionaries
2014-11-13 21:55:21 +0000: pg_dump: reading user-defined text search configurations
2014-11-13 21:55:21 +0000: pg_dump: reading user-defined foreign-data wrappers
2014-11-13 21:55:21 +0000: pg_dump: reading user-defined foreign servers
2014-11-13 21:55:21 +0000: pg_dump: reading default privileges
2014-11-13 21:55:21 +0000: pg_dump: reading user-defined collations
2014-11-13 21:55:21 +0000: pg_dump: reading user-defined conversions
2014-11-13 21:55:21 +0000: pg_dump: reading type casts
2014-11-13 21:55:21 +0000: pg_dump: reading table inheritance information
2014-11-13 21:55:21 +0000: pg_dump: reading event triggers
2014-11-13 21:55:21 +0000: pg_dump: finding extension members
2014-11-13 21:55:21 +0000: pg_dump: finding inheritance relationships
2014-11-13 21:55:21 +0000: pg_dump: reading column info for interesting tables
2014-11-13 21:55:21 +0000: pg_dump: finding the columns and types of table "pg_stat_statements"
2014-11-13 21:55:21 +0000: pg_dump: finding the columns and types of table "schema_migrations"
2014-11-13 21:55:21 +0000: pg_dump: finding the columns and types of table "stocks"
2014-11-13 21:55:21 +0000: pg_dump: finding default expressions of table "stocks"
2014-11-13 21:55:22 +0000: pg_dump: finding the columns and types of table "options"
2014-11-13 21:55:22 +0000: pg_dump: finding default expressions of table "options"
2014-11-13 21:55:22 +0000: pg_dump: finding the columns and types of table "runs"
2014-11-13 21:55:22 +0000: pg_dump: finding default expressions of table "runs"
2014-11-13 21:55:22 +0000: pg_dump: flagging inherited columns in subtables
2014-11-13 21:55:22 +0000: pg_dump: reading indexes
2014-11-13 21:55:22 +0000: pg_dump: reading indexes for table "schema_migrations"
2014-11-13 21:55:22 +0000: pg_dump: reading indexes for table "stocks"
2014-11-13 21:55:22 +0000: pg_dump: reading indexes for table "options"
2014-11-13 21:55:22 +0000: pg_dump: reading indexes for table "runs"
2014-11-13 21:55:22 +0000: pg_dump: reading constraints
2014-11-13 21:55:22 +0000: pg_dump: reading triggers
2014-11-13 21:55:22 +0000: pg_dump: reading rewrite rules
2014-11-13 21:55:22 +0000: pg_dump: reading large objects
2014-11-13 21:55:22 +0000: pg_dump: reading dependency data
2014-11-13 21:55:22 +0000: pg_dump: saving encoding = UTF8
2014-11-13 21:55:22 +0000: pg_dump: saving standard_conforming_strings = on
2014-11-13 21:55:22 +0000: pg_dump: saving database definition
2014-11-13 21:55:22 +0000: pg_dump: dumping contents of table options
2014-11-13 21:56:52 +0000: pg_dump: dumping contents of table runs
2014-11-13 21:56:52 +0000: pg_dump: dumping contents of table schema_migrations
2014-11-13 21:56:52 +0000: waiting for pg_dump to complete
2014-11-13 21:56:52 +0000: pg_dump: dumping contents of table stocks
2014-11-13 21:56:52 +0000: pg_dump done
2014-11-13 21:56:52 +0000: waiting for upload to complete
2014-11-13 21:56:54 +0000: upload done

pg:pull not working as expected

Hi the pg extras!!
Hope you are doing well.
I am running a Wordpress application on heroku.
The only addon i am using is the postgreSQL one.
No PGBackups (as it is requiring verification, which i am not able to do, personal issue.)

I am trying to get a DB dump on wordpress using the pg:pull command.
but whenever I use it:
PGUSER=postgres PGPASSWORD=123 heroku pg:pull HEROKU_POSTGRESQL_COLOUR mysitedb --app sushi

it starts until almost near completion and then
I get this error (last 2 lines of log):

pg_dump: reading constraints
pg_dump: reading triggers
pg_dump: reading rewrite rules
pg_dump: reading large objects
pg_dump: reading dependency data
pg_dump: saving encoding = UTF8
pg_dump: saving standard_conforming_strings = on
pg_dump: saving database definition
""pg_restore: [archiver] did not find magic string in file header
pg_dump: [custom archiver] could not write to output file: Invalid argument""

Then I installed this plugin from pgextras, but there hasnt been any change in the error output.
I just want to get the backup of my DB, I wish if any of the common wordpress plugin may work like updraft, BackWordpressUp or Xcloner, etc.
I have tried some what like 2 dozen plugins of wordpress backing up, but none of them are working in here.
All of them work on Openshift.
Any thoughts?
Will appreciate much.

"already initialized constant" warnings

When I execute any commands on heroku I get a couple of "already initialized constant" warnings from this plugin:

/home/fletch/.heroku/plugins/heroku-pg-extras/lib/heroku/client/heroku_postgresql_backups.rb:6: warning: already initialized constant Heroku::Client::HerokuPostgresqlApp::Version
/usr/local/heroku/lib/heroku/client/heroku_postgresql_backups.rb:3: warning: previous definition of Version was here
/home/fletch/.heroku/plugins/heroku-pg-extras/lib/heroku/command/pg_backups.rb:62: warning: already initialized constant Heroku::Command::Pg::MaybeAttachment
/usr/local/heroku/lib/heroku/command/pg_backups.rb:69: warning: previous definition of MaybeAttachment was here

Allow configurable output for pg:outliers

d873c3a changed the behavior of pg:outliers to truncate query length at 38 characters. This makes it a lot less useful in some cases, would it be possible allow the previous behavior by passing a flag?

SELECT "long_table_name"."id", "long_table_name.. | 00:00:40.743934 | 12.9%          | 8,617  | 00:00:00
SELECT "long_table_name"."id", "long_table_name.. | 00:00:40.269905 | 12.8%          | 8,096  | 00:00:00

Unable to run some commands

    Error:       uninitialized constant Heroku::Command::Pg::Gem (NameError)
    Backtrace:   /Users/mikehale/.heroku/plugins/heroku-pg-extras/init.rb:189:in `nine_two?'
                 /Users/mikehale/.heroku/plugins/heroku-pg-extras/init.rb:193:in `pid_column'
                 /Users/mikehale/.heroku/plugins/heroku-pg-extras/init.rb:78:in `locks'
                 /Users/mikehale/.heroku/client/lib/heroku/command.rb:206:in `send'
                 /Users/mikehale/.heroku/client/lib/heroku/command.rb:206:in `run'
                 /Users/mikehale/.heroku/client/lib/heroku/cli.rb:28:in `start'
                 /usr/local/heroku/bin/heroku:25

    Command:     heroku pg:locks -a sputnik-staging
    Plugins:     heroku-anvil
                 heroku-buildpacks
                 heroku-config
                 heroku-multikernel
                 heroku-orgs
                 heroku-pg-extras
                 heroku-production-check
                 heroku-routing
                 heroku-sudo
                 heroku-values
                 manager-cli

    Version:     heroku-toolbelt/2.35.0 (universal-darwin12.0) ruby/1.8.7

pg:push failing with must be owner of extension plpgsql

When trying to do:
heroku pg:push local HEROKU_DB

It's failing with the following dump:

pg_restore: creating COMMENT EXTENSION plpgsql
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 2605; 0 0 COMMENT EXTENSION plpgsql 
pg_restore: [archiver (db)] could not execute query: ERROR:  must be owner of extension plpgsql
    Command was: COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';

Tried using:
PGUSER=owner_of_db heroku pg:push local HEROKU_DB
but still nothing.

Any idea?

pg_stats on interesting columns

I'm thinking of adding something like this:

select s.*, atts.indexrelid::regclass::text as index from pg_stats s join pg_attribute a on s.attname = a.attname and s.tablename = a.attrelid::regclass::text join (select unnest(indkey) attnum, indexrelid, indrelid from pg_index i) atts on (atts.attnum = a.attnum and atts.indrelid = a.attrelid) where schemaname != 'pg_catalog' and (n_distinct != -1 or correlation < 0.95) order by schemaname, tablename, attname;

The idea here is that we see statistics on interesting columns - columns that are indexed and have a non-uniform distribution (n_distinct = -1 means that there are a number of distinct elements equal to the total number of elements....values between -1 and 0 represent a multiplier of the total number of elements, whereas positive values are absolute numbers). These values are in general more likely to matter on indexed columns. So it's a reasonable way to find interesting statistics as they may relate to problematic queries. I can think of one customer in particular that I always look at this stuff for, because their listings are particularly skewed. I think if nothing else it's useful to encourage the idea that whether or not constants appearing in your query predicate are in the most common values list matters a lot.

@deafbybeheading @fdr Would you use it if you had it? I do look at this sometimes. It is frustrating to have to work to get it, and that it isn't as accessible as I'd like. Although perhaps this isn't much more accessible.

'notrunc' seems bizarre as a positional argument

To signal the "no query trunction" behavior, one passes "notrunc" positionally.

heroku pg:outliers notrunc

That seems bizarre by both UNIX and Heroku CLI standards, being an option and a boolean field.

@bgentry I know that you are working on The Next Big Thing, but can you share any thoughts you have on dealing with a boolean flag that is a negation of a behavior, e.g. --no-truncate or --truncate=false, except ideally less wordy if possible?

heroku-pg-extras install is failing

I previously had this plugin installed successfully. today, it started giving me errors when running any command. So i removed the plugin and tried to re-install it. now it won't install either.

heroku plugins:install git://github.com/heroku/heroku-pg-extras.git
Installing git://github.com/heroku/heroku-pg-extras.git... failed

 !    Unable to load plugin heroku-pg-extras.
 !    Search for help at: https://help.heroku.com
 !    Or report a bug at: https://github.com/heroku/heroku/issues/new

    Error:       undefined method `configure_addon' for class `Heroku::Command::Addons' (NameError)
    Command:     heroku plugins:install git://github.com/heroku/heroku-pg-extras.git
    Plugins:     heroku-pg-extras
                 heroku-repo

    Version:     heroku-toolbelt/3.34.0 (x86_64-darwin10.8.0) ruby/1.9.3
    Error ID:    26abe1b665644eb18623e3d6a6b24a9b


    More information in /Users/spollack/.heroku/error.log

here are the lines from the error.log file:

Unable to load plugin heroku-pg-extras.
undefined method `configure_addon' for class `Heroku::Command::Addons'
/Users/spollack/.heroku/plugins/heroku-pg-extras/lib/heroku/command/pg.rb:790:in `alias_method'
/Users/spollack/.heroku/plugins/heroku-pg-extras/lib/heroku/command/pg.rb:790:in `<class:Addons>'
/Users/spollack/.heroku/plugins/heroku-pg-extras/lib/heroku/command/pg.rb:789:in `<module:Command>'
/Users/spollack/.heroku/plugins/heroku-pg-extras/lib/heroku/command/pg.rb:788:in `<top (required)>'
/usr/local/heroku/ruby/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/usr/local/heroku/ruby/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/spollack/.heroku/plugins/heroku-pg-extras/init.rb:6:in `<top (required)>'
/Users/spollack/.heroku/client/lib/heroku/plugin.rb:62:in `load'
/Users/spollack/.heroku/client/lib/heroku/plugin.rb:62:in `load_plugin'
/Users/spollack/.heroku/client/lib/heroku/command/plugins.rb:120:in `block in ruby_plugin_install'
/Users/spollack/.heroku/client/lib/heroku/helpers.rb:258:in `action'
/Users/spollack/.heroku/client/lib/heroku/command/plugins.rb:117:in `ruby_plugin_install'
/Users/spollack/.heroku/client/lib/heroku/command/plugins.rb:47:in `install'
/Users/spollack/.heroku/client/lib/heroku/command.rb:223:in `run'
/Users/spollack/.heroku/client/lib/heroku/cli.rb:45:in `start'
/usr/bin/heroku:24:in `<main>'

you'll note that it thinks the plugin is installed from the above output, but it won't run, the extra commands are not available.

help?

command heroku pg:unused_indexes (and more) failes due to wanting to write usage-tracking data somewhere on disk. (Windows)

Running the command heroku pg:unused_indexes, and others also, fails if it's not allowed to write usage statistics on my H:.heroku folder. I do not have a H:.heroku folder, it is installed in: C:\Program Files (x86)\Heroku

C:\metagamerscore>heroku pg:unused_indexes
 !    Attention!
Hello! We at Heroku would like to track your usage of pg-extras.
This data helps us direct our efforts in supporting and adopting the
features used here. All data is anonymous; we only collect the command name,
nothing else.

Please answer (y/n) if this is OK. A file is written to H:\.heroku/pg-extras.conf recording
your reply. Default is "no".
(n/y): n
!    Heroku client internal error.
!    Search for help at: https://help.heroku.com
!    Or report a bug at: https://github.com/heroku/heroku/issues/new

Error:       No such file or directory - H:\.heroku/pg-extras.conf (Errno::ENOENT)
Backtrace:   C:/Users/osho/.heroku/plugins/heroku-pg-extras/lib/heroku/command/pg.rb:736:in `initialize'
             C:/Users/osho/.heroku/plugins/heroku-pg-extras/lib/heroku/command/pg.rb:736:in `open'
             C:/Users/osho/.heroku/plugins/heroku-pg-extras/lib/heroku/command/pg.rb:736:in `can_track?'
             C:/Users/osho/.heroku/plugins/heroku-pg-extras/lib/heroku/command/pg.rb:455:in `unused_indexes'
             C:/Users/osho/.heroku/client/lib/heroku/command.rb:218:in `run'
             C:/Users/osho/.heroku/client/lib/heroku/cli.rb:28:in `start'
             C:/Program Files (x86)/Heroku/bin/heroku:29:in `<main>'

Command:     heroku pg:unused_indexes
Plugins:     heroku-pg-extras
Version:     heroku/toolbelt/3.6.0 (i386-mingw32) ruby/1.9.3


C:\metagamerscore>

Answering Yes gives the same result.

pg:ps fails with internal server error

Running 2.39.4 . Also just did heroku plugins:update. Running against a 9.2 database.

heroku pg:ps -a devcenter-metrics                                                                                                              git:master

 !    Heroku client internal error.
 !    Search for help at: https://help.heroku.com
 !    Or report a bug at: https://github.com/heroku/heroku/issues/new

    Error:       uninitialized constant Heroku::Command::Pg::Gem (NameError)
    Backtrace:   /Users/jonmountjoy/.heroku/plugins/heroku-pg-extras/init.rb:437:in `nine_two?'
                 /Users/jonmountjoy/.heroku/plugins/heroku-pg-extras/init.rb:441:in `pid_column'
                 /Users/jonmountjoy/.heroku/plugins/heroku-pg-extras/init.rb:112:in `ps'
                 /Users/jonmountjoy/.heroku/client/lib/heroku/command.rb:206:in `send'
                 /Users/jonmountjoy/.heroku/client/lib/heroku/command.rb:206:in `run'
                 /Users/jonmountjoy/.heroku/client/lib/heroku/cli.rb:28:in `start'
                 /usr/bin/heroku:25

    Command:     heroku pg:ps -a devcenter-metrics
    Plugins:     heroku-docs
                 heroku-lunch
                 heroku-man
                 heroku-oauth
                 heroku-orgs
                 heroku-pg-extras
                 heroku-production-check
                 heroku-values
                 manager-cli

    Version:     heroku-toolbelt/2.39.4 (universal-darwin12.0) ruby/1.8.7

env: psql: No such file or directory

Hi.
Tried to install and run this today.
Each command gives me the following error

env: psql: No such file or directory

Currently using heroku-toolbelt/3.0.1 (x86_64-darwin10.8.0) ruby/1.9.3
Any ideas?

either something's broken, or maybe setup instructions need an extra block..

Trying to run the very first example; did not expect it to work, of course, because whatever -adashboard is, I probably don't have it; but the error is not what I would expect. I've tried blindly stabbing around, providing my own --app and/or database URL, still the same error (don't think --app or URL even matters, because the error is on the client anyway).

Tried reinstalling Heroku Toolbelt - no dice.

akarpov at macairak in ~/workspace/r101-dashboard on develop*
$ heroku pg:cache_hit -adashboard
! Heroku client internal error.
! Search for help at: https://help.heroku.com
! Or report a bug at: https://github.com/heroku/heroku/issues/new

Error:       undefined method `exec_sql' for #<Heroku::Command::Pg:0x007fe712c601f0> (NoMethodError)
Backtrace:   /Users/akarpov/.heroku/plugins/heroku-pg-extras/init.rb:23:in `cache_hit'
             /Users/akarpov/.rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/heroku-2.35.0/lib/heroku/command.rb:206:in `run'
             /Users/akarpov/.rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/heroku-2.35.0/lib/heroku/cli.rb:28:in `start'
             /Users/akarpov/.rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/heroku-2.35.0/bin/heroku:17:in `<top (required)>'
             /Users/akarpov/.rbenv/versions/1.9.3-p448/bin/heroku:23:in `load'
             /Users/akarpov/.rbenv/versions/1.9.3-p448/bin/heroku:23:in `<main>'

Command:     heroku pg:cache_hit -adashboard
Plugins:     heroku-pg-extras
Version:     heroku-gem/2.35.0 (x86_64-darwin12.4.1) ruby/1.9.3

blocking command issue.

when I try the heroku pg:blocking I get the following error. I am running the latest.

!    Heroku client internal error.
!    Search for help at: https://help.heroku.com
!    Or report a bug at: https://github.com/heroku/heroku/issues/new

    Error:       uninitialized constant Heroku::Command::Pg::Gem (NameError)
    Backtrace:   /Users/myusuf3/.heroku/plugins/heroku-pg-extras/init.rb:389:in `nine_two?'
                 /Users/myusuf3/.heroku/plugins/heroku-pg-extras/init.rb:401:in `query_column'
                 /Users/myusuf3/.heroku/plugins/heroku-pg-extras/init.rb:63:in `blocking'
                 /usr/local/heroku/lib/heroku/command.rb:191:in `send'
                 /usr/local/heroku/lib/heroku/command.rb:191:in `run'
                 /usr/local/heroku/lib/heroku/cli.rb:28:in `start'
                 /usr/bin/heroku:25

    Command:     heroku pg:blocking
    Plugins:     heroku-accounts
                 heroku-pg-extras

    Version:     heroku-toolbelt/2.31.2 (universal-darwin12.0) ruby/1.8.7 autoupdate

Is there a way of resetting the stats?

When using any of the stat summary commands, it seems like I'm seeing old data, like unused indexes, very low cache hit rates, etc. I believe this data is coming from historical queries that were once used and now are still responsible for low cache/index hit rates. They also report about many unused indexes that have since been removed. Is there a way of dropping the historical stats and start aggregating them with a clean slate? E.g. call any of the pg_stat_* reset functions? We cannot do this manually since we don't have superuser permission on Heroku.

Add command to reset stats

Create a wrapper for SELECT pg_stat_statements_reset(); e.g. heroku pg:stats-reset.

As for the command name, try to avoid people running heroku pg:reset to do this and accidentally deleting all their data.

Missing find_uri

I think one of the recent commits removed the find_uri method that was used elsewhere.

Error:       undefined local variable or method `find_uri' for #<Heroku::Command::Pg:0x00000101061ad8> (NameError)
Backtrace:   /Users/ussrliveson/.heroku/plugins/heroku-pg-extras/init.rb:447:in `exec_sql'
             /Users/ussrliveson/.heroku/plugins/heroku-pg-extras/init.rb:49:in `index_usage'
             /usr/local/heroku/lib/heroku/command.rb:206:in `run'
             /usr/local/heroku/lib/heroku/cli.rb:28:in `start'
             /usr/local/heroku/bin/heroku:24:in `<main>'

Command:     heroku pg:index_usage
Plugins:     heroku-pg-extras
Version:     heroku-toolbelt/2.39.5 (x86_64-darwin10.8.0) ruby/1.9.3

find_uri is referenced in a few other method as well, not just with index_usage.

pgbackups:transfer stops after transferring half of the database.

I had the old 32bit Ronin db and I tried to downgrade it to Crane.
I executed the command

heroku pgbackups:transfer HEROKU_POSTGRESQL_PINK_URL

And here was the last couple line of logs:

2013-03-26T04:22:37+00:00 app[pgbackups]: psql-9.2.1-64bit:/dev/fd/63:1: WARNING:  skipping "pg_tablespace" --- only superuser can analyze it
2013-03-26T04:22:37+00:00 app[pgbackups]: psql-9.2.1-64bit:/dev/fd/63:1: WARNING:  skipping "pg_db_role_setting" --- only superuser can analyze it
2013-03-26T04:22:38+00:00 app[pgbackups]: ANALYZE
2013-03-26T04:22:48+00:00 app[pgbackups]: ANALYZE
2013-03-26T04:22:49+00:00 app[pgbackups]: Files /dev/fd/63 and /dev/fd/62 are identical
2013-03-26T04:22:49+00:00 app[pgbackups]: Finished: Tue Mar 26 04:22:48 UTC 2013

It said finished and my new crane db is only half the size of my original 32 bit db. Data seems to be there thou. Are 64 bit database half the size of 32 bit database?

% heroku pg:info
=== HEROKU_POSTGRESQL_PINK_URL
Plan:        Crane
Status:      available
Data Size:   728.6 MB
Tables:      19
PG Version:  9.1.8
Connections: 3
Fork/Follow: Available
Created:     2013-03-26 04:10 UTC
Maintenance: not required

=== HEROKU_POSTGRESQL_VIOLET_URL (DATABASE_URL)
Plan:        Ronin
Status:      available
Data Size:   1.40 GB
Tables:      19
PG Version:  9.1.8
Connections: 3
Fork/Follow: Available (to same plan only)
Created:     2013-03-25 07:26 UTC
Forked From: HEROKU_POSTGRESQL_WHITE
Maintenance: not required

Ruby 1.8.7 support?

For those of us who still have a legacy project to maintain.

    Error:       ~/.heroku/plugins/heroku-pg-extras/init.rb:496: odd number list for Hash
...le| YAML::dump({collect_stats: agreement},file) }
                              ^
~/.heroku/plugins/heroku-pg-extras/init.rb:496: syntax error, unexpected ':', expecting '}'

Even if I don't need pg-extras on an old project, the act of installing it in a Ruby 2.0 project will break every heroku command under 1.8.7.

heroku-toolbelt/2.41.0 (x86_64-darwin12.4.0) ruby/2.0.0

Unable to load plugin heroku-pg-extras (undefined method error)

$ heroku plugins:install git://github.com/heroku/heroku-pg-extras.git
Installing git://github.com/heroku/heroku-pg-extras.git... failed

 !    Unable to load plugin heroku-pg-extras.
 !    Search for help at: https://help.heroku.com
 !    Or report a bug at: https://github.com/heroku/heroku/issues/new

    Error:       undefined method `configure_addon' for class `Heroku::Command::Addons' (NameError)
    Command:     heroku plugins:install git://github.com/heroku/heroku-pg-extras.git
    Plugins:     heroku-accounts
                 heroku-pg-extras
                 heroku-repo

    Version:     heroku-toolbelt/3.34.0 (x86_64-darwin10.8.0) ruby/1.9.3
    Error ID:    96700afa3903495493a8aed63574e46f
$ cat ~/.heroku/error.log
Unable to load plugin heroku-pg-extras.
undefined method `configure_addon' for class `Heroku::Command::Addons'
/Users/aaron/.heroku/plugins/heroku-pg-extras/lib/heroku/command/pg.rb:790:in `alias_method'
/Users/aaron/.heroku/plugins/heroku-pg-extras/lib/heroku/command/pg.rb:790:in `<class:Addons>'
/Users/aaron/.heroku/plugins/heroku-pg-extras/lib/heroku/command/pg.rb:789:in `<module:Command>'
/Users/aaron/.heroku/plugins/heroku-pg-extras/lib/heroku/command/pg.rb:788:in `<top (required)>'
/usr/local/heroku/ruby/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/usr/local/heroku/ruby/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/aaron/.heroku/plugins/heroku-pg-extras/init.rb:6:in `<top (required)>'
/Users/aaron/.heroku/client/lib/heroku/plugin.rb:62:in `load'
/Users/aaron/.heroku/client/lib/heroku/plugin.rb:62:in `load_plugin'
/Users/aaron/.heroku/client/lib/heroku/command/plugins.rb:120:in `block in ruby_plugin_install'
/Users/aaron/.heroku/client/lib/heroku/helpers.rb:258:in `action'
/Users/aaron/.heroku/client/lib/heroku/command/plugins.rb:117:in `ruby_plugin_install'
/Users/aaron/.heroku/client/lib/heroku/command/plugins.rb:47:in `install'
/Users/aaron/.heroku/client/lib/heroku/command.rb:223:in `run'
/Users/aaron/.heroku/client/lib/heroku/cli.rb:45:in `start'
/usr/local/heroku/bin/heroku:24:in `<main>'
$ heroku version
heroku-toolbelt/3.34.0 (x86_64-darwin10.8.0) ruby/1.9.3
=== Installed Plugins
heroku-accounts
heroku-repo

Cache hit calculation

I see e38e0cc updated the calculation of cache hit. The calculation isn't clicking for me probably because I have a misunderstanding of the idx_blks_hit and idx_blks_read columns.

The monitoring stats documentation says:

Note: pg_stat_get_blocks_fetched minus pg_stat_get_blocks_hit gives the number of kernel read() calls issued for the table, index, or database; the number of actual physical reads is usually lower due to kernel-level buffering. *The _blks_read statistics columns use this subtraction, i.e., fetched minus hit.

The calculation made is:

(sum(idx_blks_hit) - sum(idx_blks_read)) / sum(idx_blks_hit + idx_blks_read) as ratio

Why is idx_blks_read being subtracted idx_blks_read in the numerator? Shouldn't it be hits divided by total fetched (hits plus reads)?

sum(idx_blks_hit) / sum(idx_blks_hit + idx_blks_read) as ratio

Every command fails with "ENOENT: spawn command ENOENT"

Hi,

every command run results in following output:

ENOENT: spawn command ENOENT

For example:

> heroku pg:calls -r production       
▸    ENOENT: spawn command ENOENT

Some debugging information:

> heroku plugins
=== Installed Plugins
[email protected]
> ruby --version
ruby 2.1.5p273 (2014-11-13) [x86_64-linux-gnu]

Many thanks

pg:backups CLI copy changes

@hgmnz @deafbybeheading @pvh

I finished a review of the CLI copy changes for the new pg:backups. I've already submitted a few in this commit.

CLI Changes

$ heroku pg:backups

Currently:

$ heroku pg:backups

ID    Backup Time                Status                                      Size   Database
----  -------------------------  ------------------------------------------  -----  ---------
b001  2014-11-12 19:19:59 +0000  Finished 2014-11-12 19:22:32 +0000 (143MB)  143MB  COLORLESS

Change

  1. remove size from status (it is redundant)
  2. Sort backups and restores DESC by backup time
  3. Change to:
## Backups:
ID    Backup Time                Status                                      Size   Database
----  -------------------------  ------------------------------------------  -----  ---------
b002  2014-11-12 19:19:59 +0000  In Progress (60 MB)                                 COLORLESS
b001  2014-11-12 19:19:59 +0000  Finished 2014-11-12 19:22:32 +0000 (143 MB)  143MB  COLORLESS

## Restores:
ID    Backup Time                Status                                      Size   Database
----  -------------------------  ------------------------------------------  -----  ---------
r001  2014-11-12 19:19:59 +0000  Finished 2014-11-12 19:22:32 +0000 (143MB)  143MB  COLORLESS

heroku pg:backups capture

Submitted changes:

$ heroku pg:backups capture
Use Ctrl-C at any time to stop monitoring progress; the backup
will continue running. Use heroku pg:backups info to check progress. 
Stop a running backup with heroku pg:backups cancel.

HEROKU_POSTGRESQL_PINK ---backup---> b003

pg:backups info

Propose that we remove pg:backups info altogether. Except for manual vs automatic, everything else is available in the pg:backups view. The manual vs backup is inferrable from the capture time.


$ pg:backups schedule

Current: Scheduled nightly backups for #{attachment.name}

  1. Change to Scheduled automatic daily backups for #{attachment.name} if there is not time argument
  2. Change to Scheduled automatic daily backups at #{time} for #{attachment.name} if there is a time argument

$ pg:backups unschedule

If not scheduled:

Current: No nightly backups for #{attachment.name} found
Change to (submitted): No automatic daily backups for #{attachment.name} found

If Scheduled:

Current: Stopped nightly backups for #{attachment.name}
Change to (submitted): Stopped automatic daily backups for #{attachment.name}


pg:copy

Change this command to show a list of copies that have been performed or are in progress

ID    Backup Time                Status                                      Size   Database
----  -------------------------  ------------------------------------------  -----  ---------
c001  2014-11-12 19:19:59 +0000  Finished 2014-11-12 19:22:32 +0000 (143MB)  143MB  COLORLESS

New Command: pg:query_time

Gents, love these commands so much, thanks for the effort. Before I wrote the code and created a pull request, I wanted to check if there was interest in adding a command to show information from pg_stat_statements tracking since it is supported on the Heroku stack.

If y'all like it, I'm happy to generate a PR.

Usage and query info:

https://gist.github.com/eprothro/ca56e21b7db6842f8b2d

Thanks!

fdwsql needs additional option?

I'm using the undocumented (but awesome) fdwsql option.

When I query the resulting foreign table, I get an error:

select * from dwh_foo limit 1;
ERROR:  relation "public.foo" does not exist

I got it to work with a little help from @craigkerstiens

Right now, it generates something like:

CREATE FOREIGN TABLE dwh_foo .... OPTIONS (table_name 'foo');

Instead, it looks like it needs to be this:

CREATE FOREIGN TABLE dwh_foo .... OPTIONS (schema_name 'heroku', table_name 'foo');

(where, I guess, schema_name can vary).

Cache and Index Hit Rate

from @atreanor on the original "will" repo

Hi there,

I'm not postgres expert but it seems to me that you cache hit rate and index hit rate are pulling the same numbers. They both pull

(sum(idx_blks_hit) - sum(idx_blks_read)) / sum(idx_blks_hit)

from

pg_statio_user_indexes

Should one be pulling from pg_statio_user_tables?

Thanks

Breaks toolbelt pg:psql features

Because this plugin redefines the pg:psql command, features like -c and the app::COLOR prompt don't work if the plugin is installed:

maciek@gamera:~$ heroku pg:psql maroon --app db-corral
---> Connecting to HEROKU_POSTGRESQL_MAROON_URL
Pager usage is off.
psql (9.3.3, server 9.3.2)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.

db-corral::MAROON=> \q
maciek@gamera:~$ heroku pg:psql -c "select 1" maroon --app db-corral
---> Connecting to HEROKU_POSTGRESQL_MAROON_URL
 ?column? 
----------
        1
(1 row)
maciek@gamera:~$ heroku plugins:install https://github.com/heroku/heroku-pg-extras
Installing heroku-pg-extras... done
maciek@gamera:~$ heroku pg:psql maroon --app db-corral
Pager usage is off.
psql (9.3.3, server 9.3.2)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.

d7sae5lh1fgjii=>

maciek@gamera:~$ heroku pg:psql -c "select 1" maroon --app db-corral
Pager usage is off.
psql (9.3.3, server 9.3.2)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.

d7sae5lh1fgjii=> 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.