backup & recover data in postgresql
You don't need to disable writes to the database while pg_dump is running. It's designed to create consistent backups by default. Quoting the manual:


  pg_dump is a utility for backing up a PostgreSQL database. It makes consistent backups even if the database is being used concurrently.  pg_dump does not block other users accessing the database (readers or writers).