导入 postgresql 数据库转储
我有以下工作流程,我想使用简短的 PHP 脚本实现自动化。
- 从特定 URL(可能是 FTP)下载 gzfile(带有数据库转储)。
- 将文件解码为txt。
- 使用 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.
- Download gzfile (with db dump) from specific URL (potentially FTP).
- Decode the file to txt.
- 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;
. Can the stdin be a problem?
2011-08-29 8484 3 1
Thank you all!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.