Gill Bates
Gill Bates

Reputation: 15227

How to dump data owned by postgres in case of lack of privileges for writing

I have DB owned by postgres, and I need to dump it, but postgres user does not have rights to write. So it boils down to login to DB as postgres but under different user in OS. How can I do that? I tried -U postgres but get an error even without password prompt. Basically I seek for `mysql -u root -p' in Postgres.

Upvotes: 1

Views: 1354

Answers (1)

Daniel Vérité
Daniel Vérité

Reputation: 61726

Dump to the standard output, and have another OS user write to the file.

Assuming you're root:

# (su postgres -c 'pg_dump -U postgres dbname') > /path/to/backup.sql

The resulting file will created and written by root.

Upvotes: 7

Related Questions