title: Importing a CSV file into postgres. Error: No such file or directory
body: <p>I'm trying to import a CSV file into postgresql database.<br />
  First of all I tried following query:</p>
  <pre><code>copy temporaryData
  from '/home/milad/Desktop/myFolder/csvFiles/test.csv'
  delimiter ',' csv;
  </code></pre>
  <p>But it gave me below Error:</p>
  <pre><code>SQL Error [42501]: ERROR: could not open file &quot;/home/milad/Desktop/myFolder/test.csv&quot; for reading: Permission denied
  </code></pre>
  <p>This error is reasonable as suggested by <a href="https://stackoverflow.com/q/19463074/10813146">this thread</a> and also by <a href="https://www.postgresqltutorial.com/import-csv-file-into-posgresql-table/" rel="nofollow noreferrer">postgresql tutorial</a>:</p>
  <blockquote>
  <p>Notice that the file must be read directly by the PostgreSQL server, not by the client application. Therefore, it must be accessible by the PostgreSQL server machine. Also, you need to have superuser access in order to execute the COPY statement successfully.</p>
  </blockquote>
  <p>Since I don't like to change my system permissions just to import a file, To solve this issue I decided to move my CSV file to <code>/tmp/</code> directory which is suggested by <a href="https://stackoverflow.com/a/29899948/10813146">this answer</a>.</p>
  <p>Then I tried to run below script:</p>
  <pre><code>create or replace procedure loadInstructorOfCourses()
  language plpgsql
  as $$
  begin 
      create table temporaryData(
          courseSectionID varchar(10),
          instructorID    varchar(25),
          courseTitle     varchar(50)
      );
  
      copy temporaryData
      from '/tmp/test.csv'
      delimiter ',' csv;
  
      drop table temporaryData;
  end;$$;
  
  call loadInstructorOfCourses();
  </code></pre>
  <p>And now it gives me below error:</p>
  <p><code>SQL Error [58P01]: ERROR: could not open file &quot;/tmp/test.csv&quot; for reading: No such file or directory</code></p>
  <p>But I'm sure the file has <code>read</code> permission for <code>others</code> and also it's available:</p>
  <pre><code>&gt; ls -l -d /tmp
  drwxrwxrwt 25 root root 700 Oct 20 09:53 /tmp
  &gt; ls -l /tmp/test.csv
  -rw-r--r-- 1 milad milad 6700 Oct 20 09:53 /tmp/test.csv
  </code></pre>
  <p><strong>Why does this problem happen and how to resolve it?</strong></p>
  <p><strong>INFO:</strong>
  My OS is Manjaro KDE:</p>
  <pre><code>&gt; uname -r
  5.4.150-1-MANJARO
  </code></pre>
  <p>And also I use <a href="https://dbeaver.io/" rel="nofollow noreferrer">DBeaver</a> to connect to postgresql server and run my scripts.</p>
  <p><strong>UPDATES:</strong> Using <em>psql</em> I have the same issue too. When I connect to db by <em>psql</em>:</p>
  <pre><code>psql -U postgres -d IUTPlanning
  </code></pre>
  <p>and run my procedure:</p>
  <pre><code>call loadInstructorOfCourses();
  </code></pre>
  <p>I'll get the same error:</p>
  <pre><code>ERROR:  could not open file &quot;/tmp/test.csv&quot; 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.
  CONTEXT:  SQL statement &quot;copy temporaryData
          from '/tmp/test.csv'
          delimiter ',' csv&quot;
  PL/pgSQL function loadinstructorofcourses() line 9 at SQL statement
  </code></pre>