COPY Command in PostgreSQL:
The COPY
command allows high-speed bulk data transfer to or from the server. Copy-in and copy-out operations each switch the connection into a distinct sub-protocol, which lasts until the operation is completed.
COPY
command is supported in PostgreSQL Protocol v3.0 (Postgresql 7.4 or newer).
For more info follow the below link:
GENERAL SYNTAX:
COPY (<select-query-here>) TO <file-path>;
Here is one answer I found to your question of how to run it:
https://ieftimov.com/postgresql-copy
Try this One:
\copy
(note the backslash) lets you copy to/from remote databases and does not require superuser privileges.
psql -h remotehost -d remote_mydb -U
myuser -c "\copy mytable (column1, column2) from '/path/to/local/file.csv' with delimiter as ','"