Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving from MySQL to to Postgres on Rails 3

Aside from removal of some MySQL specific queries, the migration was pretty smooth. The problem now is, that during developement there is a lot more queries to the DB than before.

Started GET "/profiles/data" for 127.0.0.1 at Tue Sep 21 10:26:18 +0200 2010
 Processing by ProfilesController#data as JSON
 User Load (24.3ms)  SELECT "users".* FROM "users" ORDER BY updated_at DESC LIMIT 1
 CACHE (0.0ms)  SELECT "users".* FROM "users" ORDER BY updated_at DESC LIMIT 1
 SQL (10.5ms)   SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
 FROM pg_attribute a LEFT JOIN pg_attrdef d
 ON  a.attrelid = d.adrelid AND a.attnum = d.adnum
 WHERE a.attrelid = '"users"'::regclass
 AND a.attnum > 0 AND NOT a.attisdropped
 ORDER BY a.attnum

Every single query results in 3-8 additional queries like the above. What and why is happening? One of the problems now is, that developement.log is bloated and unreadable. I waste loads of time scrolling inbetween those queries looking for the right thing...

Update: Tue Sep 21

This is not related to the query type. All the queries are generating this kind of stuph:

ree-1.8.7-2010.02 > User.first
  SQL (0.3ms)  SHOW client_min_messages
  SQL (2.0ms)  SET client_min_messages TO 'panic'
  SQL (6.3ms)  SET standard_conforming_strings = on
  SQL (18.3ms)  SET client_min_messages TO 'notice'
  SQL (15.6ms)  SET time zone 'UTC'
  SQL (17.2ms)  SHOW TIME ZONE
  SQL (23.8ms)   SELECT tablename FROM pg_tables WHERE schemaname = ANY (current_schemas(false)) 
  User Load (162.4ms)  SELECT "users".* FROM "users" LIMIT 1
  SQL (7.5ms)   SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc,
    a.attnotnull FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid
    AND a.attnum = d.adnum WHERE a.attrelid = '"users"'::regclass AND a.attnum > 0 AND
    NOT a.attisdropped ORDER BY a.attnum 

[...] 1 row in set ree-1.8.7-2010.02 >

like image 213
mdrozdziel Avatar asked Sep 21 '10 08:09

mdrozdziel


2 Answers

I stole this from another post: You might want to have a look at http://github.com/dolzenko/silent-postgres That plugin strips those queries out. Those log noise occurs because of the high postgresql log level.

like image 64
baldmark Avatar answered Sep 30 '22 04:09

baldmark


The second query is used by your application to get information about the datatype used and to see if the column is nullable or not. If you're using pgAdmin3 you'll see a lot these type of queries as well, just to get meta data of the results. Most applications don't need queries like this, it's mostly usefull during development and for tools like pgAdmin.

like image 44
Frank Heikens Avatar answered Sep 30 '22 02:09

Frank Heikens