Exporting table data into csv format from server to local I have connected to remote server and trying to export a table data to local using the command:

copy finance.coa to 'localusername@172.16.1.44:/home/kedarisettyakhiles/akki.csv' DELIMITER ',' CSV HEADER;


I am getting the error:


  relative path not allowed for COPY to file
There are two problems:


COPY writes to a file on the database server.

If you want to write to a file on the client machine, use psql's \copy which runs COPY ... TO STDOUT under the hood.
You cannot specify a host and user name in the file name in the hope that the file will be transferred to another machine. It has to be a path on the file system (for COPY, it has to be an absolute path on the server's file system, hence the error message).


Start psql on the machine where you want the file to end up and use \copy:

\copy finance.coa to '/home/kedarisettyakhiles/akki.csv' (FORMAT 'csv', DELIMITER ',', HEADER)