postgresql中水平分片的好方法是什么
postgresql 中水平分片的好方法是什么
1. pgpool 2
2. gridsql
这是使用分片的更好方法
是否可以在不更改客户端代码的情况下进行分区
如果有人可以分享如何设置和使用分片的简单教程或食谱示例,那就太好了
what is a good way to horizontal shard in postgresql
1. pgpool 2
2. gridsql
which is a better way to use sharding
also is it possible to paritition without changing client code
It would be great if some one can share a simple tutorial or cookbook example of how to setup and use sharding
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
PostgreSQL 允许以两种不同的方式进行分区。 一种是按范围,另一种是按列表。 两者都使用表继承来进行分区。
按范围(通常是日期范围)分区是最常见的,但如果作为分区的变量是静态且不倾斜的,则按列表分区可能会很有用。
分区是通过表继承完成的,因此要做的第一件事是设置新的子表。
然后需要使用规则或触发器将数据删除到正确的表中。
规则在批量更新时速度更快,在单个更新时触发并且更易于维护。 这是一个示例触发器。
以及执行插入的触发器函数
这些示例是 postgresql 文档的简化版本,以便于阅读。
我不熟悉pgpool2,但gridsql是一个为EnterpriseDB设计的商业产品,EnterpriseDB是一个构建在postgresql之上的商业数据库。 他们的产品非常好,但我认为它不适用于标准 postgresl。
PostgreSQL allows partitioning in two different ways. One is by range and the other is by list. Both use table inheritance to do partition.
Partitioning by range, usually a date range, is the most common, but partitioning by list can be useful if the variables that is the partition are static and not skewed.
Partitioning is done with table inheritance so the first thing to do is set up new child tables.
Then either rules or triggers need to be used to drop the data in the correct tables.
Rules are faster on bulk updates, triggers on single updates as well as being easier to maintain. Here is a sample trigger.
and the trigger function to do the insert
These examples are simplified versions of the postgresql documentation for easier reading.
I am not familiar with pgpool2, but gridsql is a commercial product designed for EnterpriseDB, a commercial database that is built on top of postgresql. Their products are very good, but I do not think that it will work on standard postgresl.
好吧,如果问题是关于分片的,那么 pgpool 和 postgresql 分区功能就不是有效的答案。
分区假设分区位于同一服务器上。
分片更为通用,通常在数据库拆分到多台服务器上时使用。 当分区不再可能时,例如对于无法容纳在单个磁盘上的大型数据库,则使用分片。
对于真正的分片,Skype 的 pl/proxy 可能是最好的。
Well, if the question is about sharding, then pgpool and postgresql partitioning features are not valid answers.
Partitioning assumes the partitions are on the same server.
Sharding is more general and is usually used when the database is split on several servers. Sharding is used when Partitioning is not possible any more, e.g for large database that cannot fit on a single disk.
For true sharding then Skype's pl/proxy is probably the best.
pl/proxy(Skype 提供)是一个很好的解决方案。 它要求您通过函数 API 进行访问,但一旦您拥有了它,它就可以使其变得非常透明。
pl/proxy (by Skype) is a good solution for this. It requires your access to be through a function API, but once you have that it can make it pretty transparent.
实现 PostgreSQL 集群的最佳实践是使用:
替代方案:Postgres-XL
对于分片(负载平衡),您可以使用:
注意:
集群的目的是包含大数据集和主要用于数据仓库。
分片的目的是为了负载平衡,主要用于高事务数据库。
** 警告 **
避免使用 pgpool,因为过多的开销会导致将来出现问题。
希望这个回答对您以后的发展有所帮助。
Best practice to achieve PostgreSQL cluster is using:
Alternative: Postgres-XL
For Sharding (loadbalance) you can use:
Note:
Cluster purpose is contain big dataset and mostly for data warehouse.
Sharding purpose is for loadbalance and mostly used for high-transaction database.
** WARNING **
avoid pgpool because too many overhead that will lead issue in the future.
Hope this answer will help you in future development.