postgresqlwindowspsqlaccess-denied

ACESS DENIED when running .sql file in psql


I encounter an issue when i try to run .sql file in the psql shell(windows)

my code: tpchr=> \i 'C:/Users/kyyy/Desktop/ts/dbLoadTPCHR.sql';

i got error stating:

psql:C:/Users/kyyy/Desktop/ts/dbLoadTPCHR.sql:1: 
ERROR:  could not open file "C:/Users/kyyy/Desktop/ts/supplier.csv" for reading: Permission denied 
psql:C:/Users/kyyy/Desktop/ts/dbLoadTPCHR.sql:3: 
ERROR:  could not open file "C://Users/kyyy/Desktop/ts/part.csv" for reading: Permission denied

dbLoadTPCHR.sql contains the path to supplier.csv and part.csv that is stored in the same location.

I am trying to load the .sql file inside my table as the csv file contains the inform that was required to insert into the table.


Solution

  • I have faced similar issues, and I recommend trying the following steps, listed in order of significance, hopefully, one will work:

    1. Check File Permissions: Ensure CSV files are not read-only and the PostgreSQL user has read permissions. Right-click on the files, select Properties, and check the permissions.
    2. Try using \COPY: Use \COPY instead of COPY for client-side execution.
    3. Check the PostgreSQL Service User: Verify that the PostgreSQL service is running under a user with access to the CSV files.
    4. Open psql with Administrator Privileges (if you alrady havent): Run the Command Prompt or PowerShell as an administrator before launching psql.
    5. Check the Path: Ensure the path and filenames are correct and use the appropriate path separator (/ or \\).