Postgresql – pg_dump – how to split it into directories and files

pg-dumppostgresqlversion control

I am looking for a way to dump PostgreSQL12 database model into a directory/file structure, instead of a single file – for versioning purposes.

I found this old thread, which mentions this exact case and describes a --split flag to be used with pg_dump.

However, this option does not exist in the current pg_dump for PostgreSQL12. I also tried the option --format=directory but that's not it. How do I achieve this effect?

Best Answer

The directory format will write one file per table, so that sounds like a good candidate. But if you are interested in a text diff, it is of course useless.

The only thing I can think of is to dump each table, view and function separately using the -t option. You might still be disappointed if you want a diff of the table contents, because rows in a PostgreSQL table keep changing position.

Best practice is not to meddle with the database and then to reverse engineer a diff, but to use a schema versioning tool like Liquibase and write SQL diff files yourself.