Question

I use PuTTy to connect a remote Ubuntu. I want to transfer a table from another windows computer into a database in the Ubuntu. I searched in the Internet and the code is

pg_dump -C -t table_name -h 192.168.1.106 -p 5432 database_name1| psql -h localhost -p 5432 -U postgres database_name2

But the PuTTy shows:

Password for user postgres: Password:

I need to input two password: one is the Ubuntu user postgres pw, and the other is windows computer user postgres pw.

I guess the right way is to input Ubuntu user pw first, and then the computer pw. But it shows:

pg_dump: [archiver (db)] connection to database "database_name1" failed

Is this error caused by PuTTY? What would it be like if I use the Ubuntu computer directly? I also used the separated way: first pg_dump, then psql. It worked. Can anyone tell me why I can not transfer a table using pg_dump | psql directly?

Was it helpful?

Solution

This won't work well because both programs are trying to read from the same terminal input stream at the same time. Some of them get some parts of each of what you type, so passwords are mangled.

Use a ~/.pgpass file to supply the passwords, or use the PGPASSWORD environment variable:

PGPASSWORD='pw_for_dump' pg_dump .... | PGPASSWORD='pw_for_restore' pg_restore ...

The .pgpass file is preferable.

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