Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vE8nL-0066dU-Ro for pgsql-sql@arkaria.postgresql.org; Wed, 29 Oct 2025 16:13:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vE8nK-002DLG-Lu for pgsql-sql@arkaria.postgresql.org; Wed, 29 Oct 2025 16:13:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vE8nK-002DL7-8q for pgsql-sql@lists.postgresql.org; Wed, 29 Oct 2025 16:13:05 +0000 Received: from mail-lj1-x236.google.com ([2a00:1450:4864:20::236]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vE8nH-004PaC-21 for pgsql-sql@lists.postgresql.org; Wed, 29 Oct 2025 16:13:04 +0000 Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-378cfd75fb0so79262081fa.1 for ; Wed, 29 Oct 2025 09:13:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761754382; x=1762359182; darn=lists.postgresql.org; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=oYv4ROscdA57XNU5rRoXAnu/31GQIhLhqM0qIDxDcbg=; b=d9BrPvtmdu275HpnFcaWFcCsiVqsxUoCCYTw10822GYDrkSMH+23yaqYdhiO4+jb3C z7KRgFd5tQnTQ4CCaMAmrArFI/QbWwe+rr4yX0XpfZymX1ICtc/jGTXwyIO97cO51kRu wwQ1D+rKdyLr8UIejVx6dGE5lPVEqBCtGSGZ5ZirG3/n23MIJdwCDy+8h/4B3XjXMVru psauWNzGf0T47pGAc6BGsPTeZOgwVoz95nG6P2n6O1aKwpmsic17zNBS798aQL1Mk4DI 57QgqumJl29tP8jG0EmacXYssi757/1ZxLi6T7xp6EoikGaSH0bby8zeJAUz2M7rNDru HLhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761754382; x=1762359182; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=oYv4ROscdA57XNU5rRoXAnu/31GQIhLhqM0qIDxDcbg=; b=ix7PJq7jq2cXdN2hn6TvxT6ap1VrB6beXxY3RSXNJJLmjtCUXwuGwTMhZpKB/OHt5A p7dolpZxZf2nnBEjlm9/6jwsbVjehsZjBW4OfKQqg4CB6AetNM1Z+1elMP875xMdT1V/ zQGkTQyjuqE1Uagk7O7Bl0Kxb4Wvhcewy+nBU7gzkSkKJXVPnldbGBKFCOdp9Ntyt2Xg FzHAyoUNERMTNSVowabzc7aQTW3TIE/sH/OB3tknwCjU4PzI6yLJXNDklDVPcUiXssj/ qqLzZxc64CmsfREttPRcyRpGMuVxCykOUZuYUUQs+PhhHh59Sm0ADpn3KzbH/VqoYlur p4VA== X-Gm-Message-State: AOJu0YyfDlNvEvqzNyffqh+msq57yLOSnEH3t3l4RmCHKsd1w22CQK2A jubycftgUuSz2OmjNgorG0xQUcN9E60bcBwGp3xLagqFWkyxUA8HsXV6NYjpWw== X-Gm-Gg: ASbGnctVfiBB56i0FotvOQryP5O87cdOiXM4xOu2cUzgOXAtmGtGawxvgHtT8CXSLVE lPw1jpeRIXtneK8F1eOcptZ7f/4Ud/GFSc4C8zQWJuXiSwEfdXX+2KdIZ3RpZRNZag0zhioawh3 lQnXOlY5U2hrtQ7cxrLoVr4TahoENS9/QGV0Z6BNjzmpIJA+eOrn8ZvanZxfANq2FHPMaBjfGHd eQ6wjcnQUddD+McEl4Z59pgfQEiSnU/+11S/D1/+BFelUffQdVreAbMOvdoWQp+4bVYHVGlOg0T GPQi7l5CyBELmoaZCzNFLWpLdMlqxAytM5xNmtpVWYPcs27tPf2Rl9hEdT9MALoAjr1BnR52kXy JtvYcSKdA7lznc0ZjJRv3QZVPj+99dBddrdcLMjmj9er7kxTzXEGhwt1LvHeyiwdtv+ZrutfMCe 2k72XmKju4mXg0/rzEeKeU73FIKgTlasergzydGjHt8jde8bhsWWE= X-Google-Smtp-Source: AGHT+IH9wL6ZKLATBgUnhqngC6hayqtQJPWIif3kmY1alZe67du8nUou2R1C24Kwhy8RhPX8jdKIXQ== X-Received: by 2002:a05:651c:1603:b0:378:cff9:93f with SMTP id 38308e7fff4ca-37a1093a6aamr129741fa.12.1761754381722; Wed, 29 Oct 2025 09:13:01 -0700 (PDT) Received: from [10.96.240.181] (mobile-access-b04858-250.dhcp.inet.fi. [176.72.88.250]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-378ee0e505bsm34302591fa.52.2025.10.29.09.13.00 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Oct 2025 09:13:01 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------6l00JYm71nhPVmghUfgaBXce" Message-ID: <7d2f7e34-c724-4227-a1c2-8d5882a6a3d4@gmail.com> Date: Wed, 29 Oct 2025 18:12:59 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Linux file permission for COPY TO SQL command To: pgsql-sql@lists.postgresql.org References: <8ABD45BB-37B7-4394-AB59-10BC1C25797F@gmail.com> Content-Language: en-US From: =?UTF-8?Q?Roland_M=C3=BCller?= In-Reply-To: <8ABD45BB-37B7-4394-AB59-10BC1C25797F@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------6l00JYm71nhPVmghUfgaBXce Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hello, COPY TO  stores the output into a file on the server rather than in your local where client is running. Spaces in the file name are actually no issue: $ psql -h 172.17.0.2 -U postgres -c "COPY (SELECT * FROM pg_class) TO '/var/tmp/pg_class.       OUT  x'" Password for user postgres: COPY 420 ... but the output file is on the server - in this example inside a docker container postgres@7680e256387f:~$ ls -ltr /var/tmp total 208 ... -rw-r--r-- 1 postgres postgres 49291 Oct 29 16:08 'pg_class.  OUT  x' Copying to client side can be done with \copy () to ''; BR/Pozdrawiam, Roland On 10/29/25 01:03, Rob Sargent wrote: > > >> On Oct 28, 2025, at 9:39 AM, Krzysztof wrote: >> >>  >> >> I try to use COPY TO command to copy results of a SELECT but I get >> this message: >> >> ERROR:  could not open file "a file" for writing: Permission denied >> > > Is there really a space in the actual file name. That might get > tricky. You’re suggesting the file already exists: is that true? > Directory permissions? >> >> User, group and other are granted full permission to this file. What >> should I do more to get this working? >> >> -- >> Pozdrawiam >> Krzysztof Jasieński --------------6l00JYm71nhPVmghUfgaBXce Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

Hello,


COPY TO  stores the output into a file on the server rather than in your local where client is running.


Spaces in the file name are actually no issue:

$ psql -h 172.17.0.2 -U postgres -c "COPY (SELECT * FROM pg_class) TO '/var/tmp/pg_class.       OUT  x'"
Password for user postgres: 
COPY 420

... but the output file is on the server - in this example inside a docker container

postgres@7680e256387f:~$ ls -ltr /var/tmp
total 208
...
-rw-r--r-- 1 postgres postgres 49291 Oct 29 16:08 'pg_class.       OUT  x'


Copying to client side can be done with \copy (<query or table>) to '<output file>';


BR/Pozdrawiam,

Roland


On 10/29/25 01:03, Rob Sargent wrote:


On Oct 28, 2025, at 9:39 AM, Krzysztof <kj@limes.com.pl> wrote:



I try to use COPY TO command to copy results of a SELECT but I get this message:

ERROR:  could not open file "a file" for writing: Permission denied


Is there really a space in the actual file name. That might get tricky. You’re suggesting the file already exists: is that true? Directory permissions?

User, group and other are granted full permission to this file. What should I do more to get this working?

-- 
Pozdrawiam
Krzysztof Jasieński
--------------6l00JYm71nhPVmghUfgaBXce--