2

I tried to make a backup of a database from Git Bash environment, but the executable does not output anything.
If I specify the filename using the -f flag, a blank file gets created, so the executable obviously runs, but it does not do anything - there is no output or activity. Using the -v flag also does not make it produce any output.
If I run pg_dump --help, I do get output though.

When I do the same from a Windows command line, I am asked for a password and the dump proceeds fine.

What is different about the Git Bash environment that pg_dump does not work there? Is there any workaround? I prefer to stay out of the Windows command line if at all possible.

1
  • You might need to use winpty. Alternatively using a cygwin shell instead of git bash might also be different enough to make a difference.
    – hlovdal
    Nov 4, 2021 at 10:57

2 Answers 2

1

TLDR: Instead of pg_dump ..., use winpty pg_dump ...

What's different about Git Bash is that it's a POSIX program running in a mintty window which (unless you've enabled a certain optional and still not production-ready feature) doesn't support the Windows Terminal API. The failure is most often seen with programs that attempt to use that API to read a password without it being printed as the user types it.

Your version of pg_dump is probably compiled to use the Windows Terminal API so that it can read a password without echoing it. (If it were compiled with the POSIX API the attempt not to display the password would fail when run in Windows Terminal.) If you run it in a mintty with winpty you will probably see the password prompt and be able to type in the password.

winpty is a shim that starts a hidden Windows Console window, runs the program you give it connected to that for I/O, and then polls the screen of that console to get the output to send back to your MinGW terminal.

1
  • Thank you for the detailed root cause analysis, it seems you are right about it.
    – JohnEye
    Nov 5, 2021 at 12:06
4

do the same from a Windows command line, I am asked for a password and the dump proceeds fine

I suspect that in the Git Bash environment it is also waiting for the password but you are not seeing the prompt for it (could stdout/stderr that it is prompting on be redirected somewhere else other than your terminal?).

Try typing the password as if you have been prompted and see what happens. Also, try providing the password by other means (as covered here). In either case this probably isn't a pg_dump specific question but a bash/bashgit/windows/other one affecting other tools that need similar input, that you'll be more likely to get useful answers about elsewhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.