开发者

Import postgresql database dump

开发者 https://www.devze.com 2023-03-31 14:21 出处:网络
I have the following work flow which I\'d like to automate with short PHP script. Download gzfile (with db dump) from specific URL (potentially FTP).

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 er开发者_运维问答ror 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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消