Getting Around Linux: PostgreSQL’s ‘COPY FROM’ and Permissions in the Home Directory

After slinging some code into the dead of night, I ran into a few problems regarding read permissions. One of the tasks I needed to accomplish involved dumping a ‘.csv’ file into a table in a PostgreSQL database. That part was easy, all you have to do is use the ‘COPY FROM’ command in the psql interpreter and voila’, file imported right?

It turns out that the ‘COPY FROM’ command uses a different program that doesn’t have read access to your home directory. This resulted in the following error:

 ERROR:  could not open file "/home/alex/data/widgets.dat" for reading: Permission denied

I tried running chmod 777 on all the files in the ‘/home/alex/data’ directory, but that didn’t work. After some searching, I ran into a forum post that solved my problem. It turns out that you need to give read permissions to directories below the subdirectory you are reading from. You can accomplish this by typing the following:


chmod o+rx /home/alex

Leave a Reply