Skip site navigation (1) Skip section navigation (2)

Re: COPY (query) TO file

From: "Mark Woodward" <pgsql(at)mohawksoft(dot)com>
To: "Tino Wildenhain" <tino(at)wildenhain(dot)de>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: COPY (query) TO file
Date: 2006-06-02 22:44:43
Message-ID: 18725.24.91.171.78.1149288283.squirrel@mail.mohawksoft.com (view raw or flat)
Thread:
Lists: pgsql-hackers
> Mark Woodward wrote:
> ...
>
>>>> pg_dump -t mytable | psql -h target -c "COPY mytable FROM STDIN"
>>>>
>>>> With a more selective copy, you can use pretty much this mechanism to
>>>> limit a copy to a sumset of the records in a table.
>>> Ok, but why not just implement this into pg_dump or psql?
>>> Why bother the backend with that functionality?
>>
>> Because "COPY" runs on the back-end, not the front end, and the front
>> end
>> may not even be in the same city as the backend. When you issue a "COPY"
>> the file it reads or writes local to the backend. True, the examples I
>> gave may not show how that is important, but consider this:
>
>
> We were talking about COPY to stdout :-) Copy to file is another
> issue :-) Copy to (server fs) file has so many limitations I dont see
> wide use for it. (Of course there are usecases)

"wide use for" is not always the same as "useful." Sometimes "useful" is
something not easily doable in other ways or completes a feature set.

>
>> psql -h remote masterdb -c "COPY (select * from mytable where ID <
>> xxlastxx) as mytable TO '/replicate_backup/mytable-060602.pgc'"
>>
>> This runs completely in the background and can serve as a running
>> backup.
>
> And you are sure it would be much faster then a server local running
> psql just dumping the result of a query?

No I can't be sure of that at all, but .... The COPY command has a
specific use that is understood and an operation that is separate from the
normal query mechanism.

> (And you could more easy avoid raceconditions in contrast to several
> remote clients trying to trigger your above backup )

Again, the examples may not have been precise in presenting "why," the
focus was mostly "what" so it could be discussed. As a generic feature it
has many potential uses. Trying to debate and defend a specific use limits
the potential scope of the feature.

Why have COPY anyway? Why not just use "SELECT * FROM TABLE?"

In response to

Responses

pgsql-hackers by date

Next:From: Rodrigo HjortDate: 2006-06-02 22:55:02
Subject: Re: Connection Broken with Custom Dicts for TSearch2
Previous:From: Tom LaneDate: 2006-06-02 22:36:40
Subject: Re: More thoughts about planner's cost estimates

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group