postges: psql csv import fails although file exists Trying to import a csv file as follows:

psql -h 127.0.0.1 -d jira_statistics -U admin -p 5432 -c "COPY bugs FROM '/home/centos/bugs.csv' delimiter '|' csv;"
Password for user admin: 
ERROR:  could not open file "/home/centos/bugs.csv" for reading: No such file or directory
HINT:  COPY FROM instructs the PostgreSQL server process to read a file. You may want a client-side facility such as psql's \copy.


However both the file and the table exist in jira_statistics db

[root@jira-statistics ~]# ls /home/centos/bugs.csv
/home/centos/bugs.csv


[root@jira-statistics ~]# psql -h 127.0.0.1 -p 5432 -U admin jira_statistics
Password for user admin: 
psql (9.2.24, server 11.1 (Debian 11.1-3.pgdg90+1))
WARNING: psql version 9.2, server version 11.0.
         Some psql features might not work.
Type "help" for help.

jira_statistics=# \dt
         List of relations
 Schema |   Name   | Type  | Owner 
--------+----------+-------+-------
 public | bugs     | table | admin
 public | devtasks | table | admin
 public | releases | table | admin
 public | stories  | table | admin
The most common reason for COPY failing is what is suggested in the hint, but then the error is a "Permission denied".

Since you get "No such file or directory", and a simple ls shows that the file exists, there are first a few plausible explanations that you want to check:


/home/centos/bugs.csv is a soft link pointing to an non-existing file. Use ls -l to be sure an check the destination if it's a soft link.
127.0.0.1:5432 is redirected at the network level to a different machine. This technique is widely used to connect to remote services through SSH tunnels.
Your OS uses fancy security/isolation features that forbids postgres to read /home/centos/bugs.csv without issuing a Permission denied error. Try ls -l /home/centos/bugs.csv under the postgres OS account.
Your server and client don't run under the same MOUNT namespace, due to containerization.


In cases #2 #3 or #4, just use \copy as suggested in the HINT part of the error message.