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.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top