could not open file "path/to/file.txt" for writing: Permission denied

hello everyone :), noob here
on linux, 
i'm trying to follow along with the examples of the book i'm reading on sql and it's asking me to run this command but i'm getting an error
```sql
analysis> COPY char_data_types to '/home/malup/DataGripProjects/sql_book/files_from_book_repo/typetest.txt'
              WITH (FORMAT CSV, HEADER, DELIMITER '|')
```
```
[2022-12-13 08:45:58] [42501] ERROR: could not open file "/home/malup/DataGripProjects/sql_book/files_from_book_repo/typetest.txt" for writing: Permission denied
[2022-12-13 08:45:58] Hint: COPY TO instructs the PostgreSQL server process to write a file. You may want a client-side facility such as psql's \copy.
```
can i connect datagrip to psql somehow? or how can i allow the permissions? 

0
4 comments

You can allow writing the file for everyone:

chmod ugo+w /home/malup/DataGripProjects/sql_book/files_from_book_repo/typetest.txt

to check if this is a permissions-related issue. 

 

0

hello ty for helping i tried this but same error, i don't think its a permission error anymore. i even gave postgres user owner of the file with chown and a tried to create and directory and chowned that dir to postgres user and postgres group still same issue. even with usermod to add the postgres user in the users group and wheel group.

from googling around online it really seems like the best solution to this is to just use the psql \copy function. but i don't know if i can integrate that with datagrip somehow.

0

I am not sure that the Postgres server takes the file from your local filesystem, not from the filesystem where the Postgres daemon is running. 

0

which file? i only have one machine. the postgres daemon is owned by a user called postgress that it created when i installed it. the error happens presumably because the postgres user doesn't have permissions to write to other directories outside of /tmp and /var/lib/postgres/data but i'm really struggling to change that.

0

Please sign in to leave a comment.