导入 postgresql 数据库转储

发布于 2024-12-02 06:22:15 字数 356 浏览 3 评论 0原文

我有以下工作流程,我想使用简短的 PHP 脚本实现自动化。

  1. 从特定 URL(可能是 FTP)下载 gzfile(带有数据库转储)。
  2. 将文件解码为txt。
  3. 使用 psql 将 txt 导入本地 postgre(使用 cmd)。

现在我有两个问题:

  • 将gunzipped文件传递给pg_query的最佳方法是什么?
  • 当 PHP 到达此行时出现错误:
    从标准输入复制 rf(数据、id_emailu_op、新近度、频率); 2011-08-29 8484 3 1 。 stdin 会是一个问题吗?

谢谢大家!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

完美的未来在梦里 2024-12-09 06:22:15

pg_dump 文件旨在通过 psql 导入。您可以加载文件内容,甚至使用 php 对其进行解压缩,然后打开 psql 管道,将数据写入该进程(假设您在 UNIX 计算机上)。当 psql 以这种方式执行时,就其而言,您通过 php 脚本编写的数据将通过 stdin 传入。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文