close

Rather cool “delete all data from a #PostgreSQL database without dropping the ‘public’ schema and without being a superuser” which I just wrote for ⮡ tarent. Feedback & improvements welcome.

I’ve also got a “delete everything except these two tables, and everything (sequences, constraints, indicēs) belonging to them” version.

These are especially useful in a scenario where you have an application server with one PostgreSQL cluster on it, in which one or multiple databases with just one schema each are configured (the database may also run on a separate VM than the application itself), which is the default setup for most applications using dbconfig-common (Debian), Flyway or Liquibase/DB-Manul, or other (semi‑)automatic schema management (e.g. the one in VerA.web), especially when the DB schema version of the dump is not the same as the DB schema version of where you want to restore it into.

Vote for me on:

This is available under The MirOS Licenceor, at your choice, the respective StackOverflow/StackExchange site licence, or MIT (“Expat” in Debian speech).

  • Delete all data in Postgres database

    I have created a fresh db dump from a production server with the --data-only and --column-inserts flags, so I only have a bunch of insert statements to insert data when performing a restore on a st...

  • image