Обсуждение: Problem with sql COPY command

Поиск
Список
Период
Сортировка

Problem with sql COPY command

От
"Jon Asher"
Дата:

Hi,

I'm trying to do a simple import of a comma delimited text file with COPY but it's returning an error.  The file has been granted all permissions in Linux, so it's not clear to me what the problem is.  Version 7.41 is installed... see below for details:

A comma delimited text file has been placed in a local directory with permissions set to allow any user to read or write to it:
/root/Desktop/server_transfer/WorldPoints_v2.txt'

I'm trying to use the COPY command to import this text file into a table from the PSQL command prompt.

First, open PSQL with parameters to open the right db:  psql my_database -h xxxx -U xxx

To import this file from the PSQL command line, call the COPY command:
copy public.world_stopwatch_v2 FROM '/root/Desktop/server_transfer/WorldPoints_v2.txt' using delimiters ',';

COPY fails with this error message:
could not open file "/root/Desktop/server_transfer/WorldPoints_v2.txt" for reading: Permission denied

(Database checked- it contains a table called: public.world_stopwatch_v2)

Thanks, Jon

 

Re: Problem with sql COPY command

От
Doug McNaught
Дата:
"Jon Asher" <jon@vagabond-software.com> writes:

>    A comma delimited text file has been placed in a local directory with
>    permissions set to allow any user to read or write to it:
>    /root/Desktop/server_transfer/WorldPoints_v2.txt'

The '/root' directory is often not world-readable.  Try putting the
file under '/tmp' or '/var/tmp', and remember that the file will be
read as the "postgres" user (or whatever your database server runs
as).

-Doug
--
Let us cross over the river, and rest under the shade of the trees.
   --T. J. Jackson, 1863

Re: Problem with sql COPY command

От
Richard Poole
Дата:
On Fri, Aug 27, 2004 at 03:03:34PM -0700, Jon Asher wrote:

> COPY fails with this error message:
> could not open file "/root/Desktop/server_transfer/WorldPoints_v2.txt" for
> reading: Permission denied

Don't forget that you'll need to set permissions on all the intermediate
directories as well as the file itself. It is probably safer to put the
file somewhere else than to make /root world-accessible. /tmp or an
ordinary user's home directory would be possibilities.


Richard

Re: Problem with sql COPY command

От
Tino Wildenhain
Дата:
Hi,

Am Sa, den 28.08.2004 schrieb Jon Asher um 0:03:
> Hi,
>
> I'm trying to do a simple import of a comma delimited text file with
> COPY but it's returning an error.  The file has been granted all
> permissions in Linux, so it's not clear to me what the problem is.
> Version 7.41 is installed... see below for details:
>
> A comma delimited text file has been placed in a local directory with
> permissions set to allow any user to read or write to it:
> /root/Desktop/server_transfer/WorldPoints_v2.txt'
>
> I'm trying to use the COPY command to import this text file into a
> table from the PSQL command prompt.
>
> First, open PSQL with parameters to open the right db:  psql
> my_database -h xxxx -U xxx
>
> To import this file from the PSQL command line, call the COPY command:
> copy public.world_stopwatch_v2 FROM
> '/root/Desktop/server_transfer/WorldPoints_v2.txt' using delimiters
> ',';
>
> COPY fails with this error message:
> could not open file "/root/Desktop/server_transfer/WorldPoints_v2.txt"
> for reading: Permission denied
>
> (Database checked- it contains a table called:
> public.world_stopwatch_v2)

*wild guessing* Is desktop and server the same
machine? If not, you cannot use the copy command
that way. If you issue a copy command with a path
to a file, the backand on the server has to find
the file. If its on your desktop, this operation
will not succeed.

Either you copy your file to the server in that case
or use copy from stdin with psql.

HTH
Tino Wildenhain


Re: Problem with sql COPY command - FIXED

От
"Jon Asher"
Дата:
Thanks to all...  it's importing now.  I'm still learning Linux after
upgrading from Windows.  Moving the file to another dir (\tmp) did it.   Jon

-----Original Message-----
From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org] On Behalf Of Richard Poole
Sent: Friday, August 27, 2004 3:16 PM
To: pgsql-general@postgresql.org
Subject: Re: [GENERAL] Problem with sql COPY command

On Fri, Aug 27, 2004 at 03:03:34PM -0700, Jon Asher wrote:

> COPY fails with this error message:
> could not open file "/root/Desktop/server_transfer/WorldPoints_v2.txt"
> for
> reading: Permission denied

Don't forget that you'll need to set permissions on all the intermediate
directories as well as the file itself. It is probably safer to put the file
somewhere else than to make /root world-accessible. /tmp or an ordinary
user's home directory would be possibilities.


Richard

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings