Re: Archiving data to another server using copy, psql with pipe

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Moreno Andreo <moreno(dot)andreo(at)evolu-s(dot)it>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Archiving data to another server using copy, psql with pipe
Date: 2017-04-06 15:46:58
Message-ID: CAKFQuwZ3WX6wXn9n3x2GH6L7GvkxqDWH4zqMWz25cDdGvV6zNg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Apr 6, 2017 at 4:24 AM, Moreno Andreo <moreno(dot)andreo(at)evolu-s(dot)it>
wrote:

> psql -h localhost postgres -c "copy (SELECT * FROM a WHERE time < now()) to
> stdout " | psql -h localhost postgres -c "copy b from stdin"

​The first question at hand is whether the source psql command will provoke
an EOF (which is the only thing that will stop the copy-from) even though
the complete contents of the copy-to have not yet been sent.

​The second question is whether, even if it does send EOF, the second
command will be allowed to see that EOF and complete its command. Pipeline
failure mode might impact this (from bash experience).

Unfortunately I do not know the answers to those questions.

The source code might be of some help on the first.

Another option is to replace the first psql process with custom program
that will send data to stdout and in the middle of doing so die with a
non-zero exit code.​ That should be a workable simulation of the copy to
command and evaluation of the target can be done to see what behavior is
exhibitied.

David J.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom DalPozzo 2017-04-06 15:51:12 Re: WAL being written during SELECT * query
Previous Message Magnus Hagander 2017-04-06 15:04:03 Re: A change in the Debian install