Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Biggish Data with Rails and Postgres

Biggish Data with Rails and Postgres

Tips and tricks for scaling Rails apps with large databases.

Given at RubyNation 2014

Benjamin Curtis

June 06, 2014
Tweet

More Decks by Benjamin Curtis

Other Decks in Technology

Transcript

  1. db=# EXPLAIN (format yaml) SELECT count(*) FROM errors; QUERY PLAN

    -------------------------------------- - Plan: + Node Type: "Aggregate" + Total Cost: 49971.71 + Plan Rows: 1 + Plans: + - Node Type: "Seq Scan" + Relation Name: “errors" + Total Cost: 48172.96 + Plan Rows: 719496 +
  2. db=# EXPLAIN ANALYZE SELECT id FROM errors OFFSET 500000 LIMIT

    100; ! QUERY PLAN -------------------------------------- - Plan: + Node Type: "Limit" + Actual Rows: 100 + Plans: + - Node Type: "Seq Scan" + Relation Name: "errors" + Actual Rows: 500100 +
  3. db=# EXPLAIN ANALYZE SELECT msg FROM errors WHERE id >=

    500000 AND id < 500100; ! QUERY PLAN -------------------------------------------------------- - Plan: + Node Type: "Bitmap Heap Scan" + Relation Name: "errors" + Actual Rows: 100 + Plans: + - Node Type: "Bitmap Index Scan" + Index Name: "errors_pkey" + Total Cost: 5.42 + Actual Rows: 100 + Index Cond: "((id >= 500000) AND (id <= 500100))"