3

I have the following work flow which I'd like to automate with short PHP script.

  1. Download gzfile (with db dump) from specific URL (potentially FTP).
  2. Decode the file to txt.
  3. Import the txt to local postgre with psql (using cmd).

Now I have 2 questions:

  • What is the best way to pass the gunzipped file to pg_query?
  • I get an error when PHP reaches this line:
    COPY rf (datum, id_emailu_op, recency, frequency) FROM stdin; 2011-08-29 8484 3 1. Can the stdin be a problem?

Thank you all!

3
  • 2
    gzcat dump.gz|psql at a shell prompt would decompress the .gz file and sent the output directly to postgres. Commented Aug 30, 2011 at 14:35
  • A short Bash script is probably simpler, depending on what your needs are. Commented Sep 2, 2011 at 3:09
  • I would recommend dumping using pg_dump -Fc and restore using pg_restore. Commented Sep 28, 2011 at 18:48

1 Answer 1

2

A pg_dump file is meant to be imported via psql. You can load the file contents in, and even decompress it with php, then open a pipe to psql writing data out to that process (assuming you are on a unix machine). When psql is executed in this way as far as it's concerned the data you're writing via your php script is coming in via stdin.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.