Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I try to use \i on a file that is not in the psql.exe folder it says C:: permission denied. For example I have a file with SQL command at C:\Users\Work\Desktop\School Work\load_database.sql and when I type \i "C:\Users\Work\Desktop\School Work\load_database.sql" it says C:: permission denied. How can I fix this?

I found a work around here where you copy the .sql file to the same folder as psql.exe is in.

By the way, does \i stand for import?

share|improve this question
Can you cd to that directory from the command prompt? If yes, then I'd expect you could run your file with \i, unless the file itself is protected from you. Copying scripts to the PostgreSQL bin folder is not a really good idea. – dezso Dec 4 '12 at 11:54
@dezso that worked! Is that the "proper" way of doing it? – Celeritas Dec 4 '12 at 12:17
up vote 5 down vote accepted

You've just run into a peculiarity of psql on Windows.

In my comment I just wanted to exclude the possibility that you really didn't have the necessary permission. Then it turned out that even on Windows, you have to use 'normal' slashes instead of backslashes, that is:

\i 'C:/Users/Work/Desktop/School Work/load_database.sql'

should work fine regardless which folder you start psql from. Notice that I used single quotes - with double quotes you'd got

"C:/Users/Work/Desktop/School Work/load_database.sql": Invalid argument
share|improve this answer
Got it thanks. How did you know to use single and not double quotes? Is that a general rule for postgres or what's the difference? – Celeritas Dec 5 '12 at 0:37
@Celeritas I think it is the result of a conflict of how Windows uses double quotes in paths and how psql (and PostgreSQL) use it in identifiers. – dezso Dec 5 '12 at 5:59
Thanks dezso. Here my test: script at "D:\script\abc.sql" , application at "C:\Program Files\PostgresPlus\9.3AS\bin\edb-psql.exe" ; we wanna run "abc.sql" ; go CMD --> go "D:\script\" , at here we run "C:\Program Files\PostgresPlus\9.3AS\bin\edb-psql.exe" , after that we run "abc.sql" script, it work fine. – Luan Huynh May 5 '15 at 4:20

Try the following command disregarding from which folder you start psql. It will work fine on windows. The SQL file may be located any where on your system. Put the address of the SQL file in single quotes and use double backslashes to specify the path, like this:

\i 'C:\\Users\\Work...'

share|improve this answer

Put the script under: C:\Program Files\PostgreSQL\9.5\scripts or under bin for older version then \i script.sql

share|improve this answer
The OP specifically states this works but needs to run scripts using the full path, so this doesn't really answer his question – Tom V Nov 24 '15 at 17:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.