Code Monkey home page Code Monkey logo

ruby-pg-extras's Introduction

Rails and PostgreSQL Performance Consultant

Full Stack web development consultant with over 9 years of experience. Founder of Abot for Slack. Specializing in Ruby on Rails, PostgreSQL and website performance. Experienced in building scalable APIs for startups and refactoring legacy codebases. I'm blogging about web development related topics. After hours I train rock climbing to rest my wrists from the keyboard.

ruby-pg-extras's People

Contributors

darkhelmet avatar defkode avatar djgoku avatar holmesie avatar krsyoung avatar pawurb avatar petergoldstein avatar rainerborene 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

ruby-pg-extras's Issues

Exception: undefined method `fetch' for nil:NilClass (when no sslinfo installed)

Hi, I'm not sure if this is the right place to file this (I'm actually using rails-pg-extras, however I think the exception I'm seeing is coming from this gem.

When loading the landing page for rails-pg-extras (diagnostics) it throws the following error:

An ActionView::Template::Error occurred in queries#index:

  undefined method `fetch' for nil:NilClass

        end.fetch("installed_version", false)
           ^^^^^^

I can confirm that the server does not have sslinfo installed and thus my theory is that this is tied to this:

ssl_info_enabled = extensions_data.find do |el|

If I navigate directly to the following url /pg_extras/queries?query_name=ssl_used I receive this error message:

PG::UndefinedFunction: ERROR: function ssl_is_used() does not exist LINE 3: SELECT ssl_is_used(); ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts.

I'm having a hard time replicating it locally. Not sure if it makes sense that sslinfo really isn't installed?

support tables as strings instead of putsing

Thanks for this awesome gem - I made a quick monkey patch to puts to return strings so that the output can be caputered/displayed differently. I think this is valid usecase to implement properly in the gem.

RubyPGExtras.puts_returns_string = true
# now all table prints return uncolorized strings
module RubyPGExtras
  @@puts_returns_string = false

  def self.puts_returns_string
    @@puts_returns_string
  end

  def self.puts_returns_string=(value)
    @@puts_returns_string = value
  end
end

class String
  REGEXP_PATTERN = /\033\[([0-9]+);([0-9]+);([0-9]+)m(.+?)\033\[0m|([^\033]+)/m

  def uncolorize
    self.scan(REGEXP_PATTERN).inject("") do |str, match|
      str << (match[3] || match[4])
    end
  end
end

module RubyPGExtras
  def self.puts(args)
    if @@puts_returns_string
      args.to_s.uncolorize
    else
      Kernel.puts args
    end
  end
end

module RubyPGExtras
  class DiagnosePrint
    def puts(args)
      RubyPGExtras.puts args
    end
  end
end

module RubyPGExtras
  class TableInfoPrint
    def puts(args)
      RubyPGExtras.puts args
    end
  end
end

module RubyPGExtras
  class IndexInfoPrint
    def puts(args)
      RubyPGExtras.puts args
    end
  end
end

pg_buffercache inspection

pg_buffercache is one of those built-in extensions that provides lots of good feedback. It provides a means for examining what's happening in the shared buffer cache in real time. I'm working on a few Rails tasks and I thought it would be a great idea to provide them here instead. Would you merge it if I come up with a pull request?

Feature request: Partial indexes for columns with high % of the same value

This is kind of evolving an idea used in null_indexes. Additionally to suggesting partial indexes when we have a lot of NULLs in the column, we can suggest partial indexes for columns where we have a high % of the same value.

For example, for the table with millions of users an index on role was added (to quickly find admins, for example). But 99% of the users are regular users, several are admins, moderators, etc. So the partial index where role != 'regular' would be beneficial.

All Locks "age" accuracy and including `pg_stat_activity.application_name`

This is a really helpful gem! I'm the author of GoodJob, which uses a lot of Advisory Locks. This gem (and rails-pg-extras) came up in an issue (bensheldon/good_job#480).

For Advisory Locks in all_locks, the age isn't accurate because the query is fetching the time of the connection's last query, not necessarily the age of the Advisory Lock itself:

age(now(),pg_stat_activity.query_start) AS "age"

I wanted to suggest renaming it, maybe last_activity_age (naming is hard).

And, I also wanted to suggest including pg_stat_activity.application_name in the output. I think that application_name can provide high-context information that would be really useful for understanding what's happening with the locks.

Dependency on unsupported filesize gem

The gem has a dependency on the now unsupported filesize gem - https://github.com/dominikh/filesize

The dependency is extremely minor. It consists of two references

  1. Conversion of 1 MB to a constant int value, which can just be replaced by the constant int value
  2. Checking whether an index size is above a minimum, and hence should be analyzed in the unused_indexes case

Given that the dependency is now unsupported, it should probably be removed. I'm happy to put together a PR if there is interest in resolving the issue.

Customizing queries, ignore schemas

Didn't really have a better title for this but...

I've started building out a feature in our application that uses multiple schemas. This means, that when I later use rails-pg-extras and RailsPGExtras.index_usage I get indexes for materialized views I've created in this other schema. Since the views I'm creating have the same name as tables in the public schema, I'll get duplicate entries for users, for example. The output doesn't include the schema name so I don't get that information and can't pick the correct version of the index I care about.

Basically, the end goal is I want to include only the public schema for index_usage, and basically anything else that would include things in multiple schemas. So either I need to be able to customize the query, or get more information from the query so I can ignore it later on, or something else. I'm open to suggestions. I could fork the gem, but this seems like something that could be useful for other people.

Ideas? I can make a PR if there's some direction you think would be best.

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.