Unexpected SQL queries to Postgres database on Rails/Heroku

前端 未结 4 854
灰色年华
灰色年华 2021-02-07 10:47

I was diving into a really long request to one of my Rails applications using NewRelic and found a number of SQL queries that appear entirely foreign that are taking up a signif

4条回答
  •  清酒与你
    2021-02-07 11:26

    The tables pg_class, pg_attribute, pg_depend etc all describe table, columns and dependencies in postgres. In Rails, model classes are defined by the tables, so Rails reads the tables and columns to figure out the attributes for each model.

    In development mode it looks up these values everytime the model is accessed, so if you've mad e a recent change, Rails knows about it. In production mode, Rails caches this so you would see these much less frequently, and so it really isn't a concern.

提交回复
热议问题