Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission denied with a Copy From (pgAdmin4, postgresql10)

I use pgAdmin4 and postgresql 10 on a window 10 laptop. When I use a COPY FROM to import a CSV file

COPY BD.CP FROM 'C:\Users\NOMUSER\Desktop\MONDOSSIER\Fichier.csv' with delimiter ';';

PGS returns an error message of Permission denied :

ERROR: ERREUR: n'a pas pu ouvrir le fichier « C:\Users\NOMUSER\Desktop\MONDOSSIER\Fichier.csv » pour une lecture : Permission denied

HINT: COPY TO indique au serveur PostgreSQL de lire un fichier. Vous pourriez vouloir utiliser la fonctionnalité \copy de psql pour lire en local.

SQL state: 42501

What is the problem please ? I look at a solution but I do not find! Thanks a lot :)``

like image 342
Logique Avatar asked Sep 18 '25 14:09

Logique


2 Answers

Use \copy instead of just "copy".

COLS=STATE,COUNTY,LINK_ID
psql -d tosm -c "\COPY alias ($COLS) FROM 'alias.txt' (FORMAT CSV, HEADER, DELIMITER('|'))";
like image 191
Stan Sokolov Avatar answered Sep 21 '25 15:09

Stan Sokolov


Ok, so you (and I) need to change the user authorization of the destination folder from where you want to COPY FROM or COPY TO. At the installation of Postgresql, windows does not create a new service named postgresql but uses Network service. So in the properties of your folder, you need to authorize "Network Service" as a user and to give "total control" on the folder. I have done it and it is ok for now!

like image 27
Logique Avatar answered Sep 21 '25 17:09

Logique