使用 PostgreSQL Java/JDBC Copy API 进行批量插入的经验
在版本 8.4 中,PostgreSQL 最终将专有 API 集成到其 JDBC 驱动程序 中,该驱动程序允许基于流的插入和选择。所谓的 Copy API 授予对 COPY TO/COPY FROM 的访问权限SQL 命令,一次将文本数据从流/读取器读取到一张表中,或者将文本数据从一张表写入流/写入器。插入操作考虑约束和触发器。可以使用基本转换(分隔符、引号、空值等)。性能提升相当令人印象深刻,这可能是因为对象实例化较少以及客户端和服务器后端之间的协议更加简单。
有没有人使用过这个 API,无论好坏。生产准备好了吗?有什么必须注意的陷阱吗?顺便说一句:它是一个专有 API,这一事实对我来说不是问题。
With version 8.4 PostgreSQL finally integrated a proprietary API into their JDBC driver, which allows stream based inserts and selects. The so called Copy API grants access to COPY TO/COPY FROM SQL commands, which read text data from a stream/reader into one table at a time or write text data to a stream/writer from one table. Constraints and triggers are regarded for insert operations. Basic transformations (delimiter, quotation, null values etc.) are available. The performance gain is quite impressive, which probably is because of less object instantiation and a much simpler protocol between client and server backend.
Has anyone experiences with this API, good or bad. Is it production ready? Are there any pitfalls one has to be aware of? BTW: The fact that it is a proprietary API is a non-issue for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
COPY API 在 PostgreSQL C 库中存在至少 6 年。它非常稳定。
请参阅:http://www.postgresql.org/docs/9.0/interactive /libpq-copy.html
和 http://www.postgresql.org/docs/9.0/interactive/ sql-copy.html
JDBC实现应该具有相同的属性,但我没有使用它。
附言。我认为当你称其为“专有”时存在误解。协议规范和服务器/客户端/驱动程序源代码都是免费的(就像自由一样)。
The COPY API is present in PostgreSQL C library for at least 6 years. It is very stable.
See: http://www.postgresql.org/docs/9.0/interactive/libpq-copy.html
and http://www.postgresql.org/docs/9.0/interactive/sql-copy.html
JDBC implementation should have same properties, but I haven't used it.
PS. I think there is a misunderstanding when you call this "proprietary". Both protocol specification and server/client/driver source code is free (as in freedom).