public inbox for [email protected]  
help / color / mirror / Atom feed
From: Roland Müller <[email protected]>
To: [email protected]
Subject: Re: Linux file permission for COPY TO SQL command
Date: Wed, 29 Oct 2025 22:11:19 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>

I think the best solution is to use the psql '\copy' that works the same 
way as server-side COPY or COPY TO.

in addition, the output is always stored in the client machine 
regardless whetehr the server is in localhost, remote or inside a container.

postgres=# \copy (SELECT * FROM pg_class) to /home/MYACCOUNT/Desktop/OUT
COPY 420
postgres=# \! ls -ltr /home/MYACCOUNT/Desktop/OUT
-rw-rw-r-- 1 MYACCOUNT MYACCOUNT 49291 Oct 29 22:06 
/home/MYACCOUNT/Desktop/OUT

On 10/29/25 21:55, Tom Lane wrote:
> Krzysztof <[email protected]> writes:
>> Actually server and client are installed on the same machine.
>> The file (real file) permissions are as follows:
>> -rwxrwxrwx+ 1 kaj kaj 2 Oct 27 22:36 fd/fdo.txt
>> The directory permissions are as follows:
>> drwxrwxrwx+  4 kaj kaj     4096 Oct 27 22:36 fd
>> The SQL command which tries to write to the file is this:
>> copy (select key from xcg where add=false) to '/home/kaj/fd/fdo.txt';
> The /home and /home/kaj directories would also need to be
> world-searchable for the server to be able to write there.
> (Do not make them world-writable...)
>
> Did you notice the HINT that goes with that error message?
>
> HINT:  COPY TO instructs the PostgreSQL server process to write a file. You may want a client-side facility such as psql's \copy.
>
> 			regards, tom lane
>
>





reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Linux file permission for COPY TO SQL command
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox