Skip to content
Advertisement

How to use pg_dump correctly in order to do a database migration?

Hey everyone I am fairly new to doing a pg_dump in Postgre sql. I have logged into the server and am running as postgres user. I try to run the pg_dump in order to do a database migration but I keep getting a “Permission Denied” prompt. I believe that I have the highest permissions and should be able to run this. Is there something wrong with my syntax in terminal? Would appreciate the help.

Issue:

*

[user@dfhsdaf07 ~]$ sudo su
[root@dfhsdaf07 user]# su postgres
bash-4.2$ pg_dump -F t file > file.tar
bash: file.tar: Permission denied
bash-4.2$ pg_dump -F t file >./file.tar
bash: ./file.tar: Permission denied

System info:

Macbook Pro 2015

16 GB RAM

Intel I7 Processoor

OS:

macOS Big Sur 11.5.2

Advertisement

Answer

The permission you are lacking is the permission to create the dump file in the current directory.

The reason is that if you use so postgres, you remain in the previous working directory (presumably /root), and user postgres doesn’t have permissions to create a file there.

Use the - option:

su - postgres`

That will start a login shell and put you into postgres‘s home directory.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement