PostgreSQL – How to Prevent Writes to a Schema Temporarily

pg-dumppostgresqlschema

I am moving a schema from one server to another using pg_dump + pg_restore + drop schema cascade. I need to know that no applications are writing to it (or at least that the writes will fail) during this process to avoid losing data.

At the moment I am renaming the schema before starting the dump. Is that sufficient to prevent writes? What if a large batch insert is busy when I rename the schema? Will that still complete?

Best Answer

You can REVOKE access from that schema, but I am affraid the application will have some unwanted effects. PostgreSQL has fine tuned permission administration. And later you can GRANT access to that schema.