Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top