Generate 50,000+ line CSV

You need to get away from ActiveRecord and access the database directly. I do believe that most DB engines support direct dumps to CSV. Check out the ActiveRecord extensions plugin (, I believe it will help you here. Otherwise, you can always just send straight SQL and deal with the result as necessary.