pg_dump -h host_ip -U postgres -d source_db -t aa_nqrgs.act_26022017  | 
    psql -h destination_host_ip -U postgres -d destination_db

I have tried this command to transfer a table from one server to another, but it shows an error like 'invalid command \N'. How can I resolve this?

  • you can use dblink to copy a table from one host to another. – Sayad Xiarkakh Mar 8 '17 at 7:39
  • 5
    "invalid command \N" is typically not the original error, but a result of a previous error in the script and the copy command can't continue properly. So you need to find out what went wrong. If you pass -a option to psql it will output all steps, thus giving you a hint on where the processing of the script failed. – a_horse_with_no_name Mar 8 '17 at 8:09
  • As an alternative, you can also try to use a Foreign Data Wrapper, and CREATE a foreign TABLE – joanolo Mar 11 '17 at 13:57
  • pg_dump is much faster than insertion into FDW, in my experience. – sudo Mar 14 '17 at 23:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.