I have a large (3 GB) SQL file that came from a SQL dump. Reading it is impossible because it's formatted poorly. For example each table has a giant INSERT statement that is indecipherable.

Is there a CLI tool available for Linux that can automatically format this thing? Maybe something like jq but operates on a SQL file instead of JSON?


1 Answer 1


There used to be a few of them available, but I haven't tried any of them personally for a while. Therefore I do not know how well they can handle multi-gigabyte SQL dumps.

I remember, for Node.js/JavaScript there is sql-formatter. See also the README on GitHub.

You could also search for "SQL beautifiers". The search results mention a lot of online-formatters, but these are targeted at smaller queries, single SQL statements. I haven't looked closely though. Maybe there is an offline beautifier among them.

  • Thanks yeah of all the online formatters, only one had a local tool and it was a "premium" tool. I tried probably a dozen different tools I found on github, including one that I use in other places (prettier from npm) but it chokes at 2.5 GB of SQL Apr 22, 2022 at 1:41
  • @Freedom_Ben: perhaps you can split the multi-GB SQL file manually into a few 100-MB Files, then try again. Split with sed, or perl, or some other tool. - Besides, In VScode you can also "Format Selection", but this would mean that the Editor opens/loads the file efficiently.
    – knb
    Apr 22, 2022 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.