Recently, when I attempted to import the SQL file, I encountered the ‘permission denied’ error. First, let’s examine the error that occurs during SQL file import, and then we will discuss the solution to resolve this issue.
Psql import SQL file permission denied
For Windows users, enter the psql command prompt by using the command below. If it asks for a password, enter the password for the psql user.
psql -U postgres
Now, suppose we have an SQL file on our computer, such as D:\Backup\name.sql, and we want to import it. For this, use the command below.
\i D:\Backup\name.sql
After running the above command, we encounter an error, ‘Permission denied,’ as shown in the screenshot below.

Solution
For Windows users
To solve the error for Windows users, use the double slashes ( \\ ) in the place of single slashes ( \ ) and wrap the path of the SQL file within a single quotation mark ( ‘ ‘ ). Use the below command.
\i 'D:\\Backup\\name.sql'

In the above output, we have successfully imported the SQL file, created the table with some data, and resolved the ‘Permission denied’ issue. Please refer to the screenshot above for your reference.
For Linux users
For Linux users, log in to PostgreSQL as a Postgres user to access the databases and then enter the psql prompt using the below command:
sudo su -l postgres
-- after the above command enter the psql command
psql
-- then enter the below command to import the SQL file
\i '//home//saurabh//database.sql
After executing the above query, I got the expected output as per the screenshot below.

Use the double slashes ( // ) in the place of single slashes ( / ) and wrap the path of the SQL file within a single quotation mark ( ‘ ‘ ). Use the below command.
We have also now resolved the error for Linux systems.
Conclusion
In this article, we discussed the solution to fix the error “Psql import SQL file permission denied”.
You may also like following the related articles.
I am Bijay having more than 15 years of experience in the Software Industry. During this time, I have worked on MariaDB and used it in a lot of projects. Most of our readers are from the United States, Canada, United Kingdom, Australia, New Zealand, etc.
Want to learn MariaDB? Check out all the articles and tutorials that I wrote on MariaDB. Also, I am a Microsoft MVP.