Coder Social home page Coder Social logo

Comments (8)

ankane avatar ankane commented on July 19, 2024

PgHero creates a PgHero::Connection model without a table. It's a bit of a hack but haven't found a better way to do it. Is it causing issues for your application?

from pghero.

manuelmeurer avatar manuelmeurer commented on July 19, 2024

Yes it does since I need to call ActiveRecord::Base.descendants at one point and then it complaints about the missing table.
What is Connection really needed for? It seems like establish_connection, connection_config and other methods can be called on ActiveRecord::Base as well, or am I missing something?

from pghero.

ankane avatar ankane commented on July 19, 2024

The model allows you to set ENV["PGHERO_DATABASE_URL"] to use a different user or database than your application. Does:

ActiveRecord::Base.descendants.reject{|d| d == PgHero::Connection }

do the trick?

from pghero.

manuelmeurer avatar manuelmeurer commented on July 19, 2024

Nope, that generates the same error. I think the solution is to not inherit from ActiveRecord::Base but just include/extend the necessary modules like this:

class Connection
  extend ActiveRecord::ConnectionHandling
  include ActiveRecord::Core
end

(and maybe a few more are needed)

Then you would need to call Connection.establish_connection explicitly before accessing the connection the first time.
Unfortunately I don't have a lot of time to test this out right now but I think it's the right direction. 😄

from pghero.

kmarshall008 avatar kmarshall008 commented on July 19, 2024

Hi @manuelmeurer and @ankane,

Do you have any sense why my rails production app on heroku is having a similar issue, which is causing severe memory leaks?

The following two SQL statements are consuming 99% of my apps memory in production app on heroku.

SELECT a.attname, format_type(a.atttypid, a.atttypmod), pg_get_expr(d.adbin, d.adrelid), a.attnotnull,     a.atttypid, a.atttypmod FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = ?::regclass AND a.attnum > ? AND NOT a.attisdropped ORDER BY a.attnum

SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype FROM pg_type as t LEFT JOIN pg_range as r ON oid = rngtypid

My db:rake config file is as follows:

namespace :db do
  desc "Fix 'database is being accessed by other users'"
  task :terminate => :environment do
    ActiveRecord::Base.connection.execute <<-SQL
      SELECT
        pg_terminate_backend(pid)
      FROM
        pg_stat_activity
      WHERE
        -- don't kill my own connection!
        pid <> pg_backend_pid()
        -- don't kill the connections to other databases
        AND datname = '#{ActiveRecord::Base.connection.current_database}';
    SQL
  end
end
Rake::Task["db:drop"].enhance ["db:terminate"]

I think that what I need to do is create this new class, update my puma.rb file to explicitly point to it and then re-build my production app.

But... do you think I'm barking up the right tree?

Thanks much

from pghero.

manuelmeurer avatar manuelmeurer commented on July 19, 2024

@kmarshall008 what does this have to do with the issue I reported, let alone PgHero at all?

from pghero.

ankane avatar ankane commented on July 19, 2024

@manuelmeurer Can you try master? 3f1570c

gem 'pghero', github: 'ankane/pghero'

from pghero.

manuelmeurer avatar manuelmeurer commented on July 19, 2024

Works! :shipit:

from pghero.

Related Issues (20)

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.