I presume since this is tagged with "ruby-on-rails" that you have ActiveSupport loaded. This will provide the Time#end_of_month helper method. With it you can rewrite your query as:
time = Date.new(year, month).to_time
Post.all(:created_at => time..time.end_of_month)
Not only is this simpler, it eliminates raw SQL from the query (so the query is more portable to things other than RDBMS), and most importantly it will probably perform much better than the other query. With EXTRACT
the database will likely have to perform a full table scan to extract the year and month from created_at in every row, and then compare them against your expected values. If you have a large dataset, this could be a significant load on your DB. However, provided your created_at column is indexed, the above approach should be extremely efficient in comparison.