Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WaUWK-0004Hh-79 for pgsql-bugs@arkaria.postgresql.org; Wed, 16 Apr 2014 18:25:16 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WaUWJ-0005BE-HU for pgsql-bugs@arkaria.postgresql.org; Wed, 16 Apr 2014 18:25:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WaUIb-0001ls-5p for pgsql-bugs@postgresql.org; Wed, 16 Apr 2014 18:11:05 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WaUIY-0000xV-W1 for pgsql-bugs@postgresql.org; Wed, 16 Apr 2014 18:11:04 +0000 MIME-Version: 1.0 Subject: BUG #10053: Re: COPY (...) TO 'file' doesn't create file To: pgsql-bugs@postgresql.org From: postgresql.org@ch.pkts.ca Date: Wed, 16 Apr 2014 18:10:27 +0000 Message-ID: <20140416181027.17202.41813@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.9 (-) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 10053 Logged by: PFudd Email address: postgresql.org@ch.pkts.ca PostgreSQL version: 9.2.8 Operating system: CentOS 6.5 Description: Apparently I'm *partially* a doofus. The "copy" command does its work on the server, not the client. Use "\copy" for the client, without quotes or trailing semicolon: # psql -h 1.2.3.4 -U username -c "\\copy (select * from history) to /tmp/foo.txt" dbname I did check on the server in the /tmp directory, but no file was created. This is probably a postgres permissions issue, but I can see no way to show or change the relevant permission to write to the filesystem; more googling required. I'm only *partially* a doofus because the original command should generate an error message if it's not actually opening and writing to the specified file on the server. Let that be my bug report! :-) Thanks! > In psql, this command works: > # copy (select * from history) to STDOUT; > It prints 957 lines to stdout. > > However, if I do: > # copy (select * from history) to '/tmp/foo.txt'; > it prints > COPY 957 > but doesn't create the file /tmp/foo.txt. > > If the filename is changed to 'foo.txt' it says: > ERROR: relative path not allowed for COPY to file > so we know that it's at least looking at the filename critically. > > If the filename is changed to /tmp/foo.txt without the single quotes, it says: > ERROR: syntax error at or near "/" > as expected. > > It doesn't matter if I'm doing this as a regular user or as the root user. > > Using strace, it can be seen there was no attempt to stat or open that filename for writing: > > # env PGPASSWORD=password strace -fo/tmp/strace.log psql -h 1.2.3.4 -U username -c "copy (select * from history where num=5) to '/tmp/foo.txt'" analyzer_local > > # cat /tmp/foo.txt > cat: /tmp/foo.txt: No such file or directory > > # grep -c foo.txt /tmp/strace.log > 0 > > This was tried with psql 9.2.8 and psql 9.1.13, connecting to a server running 9.2.4. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs