天天看點

PostgreSQL核心擴充之 - ElasticSearch同步插件

elasticsearch 是開源搜尋平台的新成員,實時資料分析的神器,發展迅猛,基于 lucene、restful、分布式、面向雲計算設計、實時搜尋、全文搜尋、穩定、高可靠、可擴充、安裝+使用友善。

postgresql 是起源自伯克利大學的開源資料庫,曆史悠久,核心擴充性極強,使用者橫跨各個行業。

關于postgresql的核心擴充指南請參考

<a href="https://yq.aliyun.com/articles/55981">https://yq.aliyun.com/articles/55981</a>

例如使用者需要将資料庫中某些資料同步到es建立索引,傳統的方法需要應用來負責資料的同步。

這種方法會增加一定的開發成本,時效也不是非常的實時。

PostgreSQL核心擴充之 - ElasticSearch同步插件
PostgreSQL核心擴充之 - ElasticSearch同步插件

postgresql的擴充插件pg-es-fdw,使用postgresql的foreign data wrap,允許直接在資料庫中讀寫es,友善使用者實時的在es建立索引。

這種方法不需要額外的程式支援,時效也能得到保障。

PostgreSQL核心擴充之 - ElasticSearch同步插件

略,需要包含 --with-python

對實體表,建立觸發器函數,在使用者對實體表插入,删除,更新時,通過觸發器函數自動将資料同步到對應es的外部表。

同步過程調用fdw的接口,對es進行索引的建立,更新,删除。

<a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-repositories.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-repositories.html</a>

<a href="http://www.vpsee.com/2014/05/install-and-play-with-elasticsearch/">http://www.vpsee.com/2014/05/install-and-play-with-elasticsearch/</a>

<a href="https://github.com/mikulas/pg-es-fdw">https://github.com/mikulas/pg-es-fdw</a>

<a href="https://wiki.postgresql.org/wiki/fdw">https://wiki.postgresql.org/wiki/fdw</a>

<a href="http://multicorn.org/">http://multicorn.org/</a>

<a href="http://pgxn.org/dist/multicorn/">http://pgxn.org/dist/multicorn/</a>

<a href="http://multicorn.readthedocs.io/en/latest/index.html">http://multicorn.readthedocs.io/en/latest/index.html</a>

postgresql提供的fdw接口,允許使用者在資料庫中直接操縱外部的資料源,是以支援es隻是一個例子,還可以支援更多的資料源。

這是已經支援的,幾乎涵蓋了所有的資料源。

multicorn在fdw接口的上層再抽象了一層,支援使用python寫fdw接口,友善快速試錯,如果對性能要求不是那麼高,直接用multicore就可以了。

開發人員如何編寫fdw? 可以參考一下如下:

<a href="https://www.postgresql.org/docs/9.6/static/fdwhandler.html">https://www.postgresql.org/docs/9.6/static/fdwhandler.html</a>