ITPub博客

首页 > 数据库 > PostgreSQL > PostgreSQL pgsocket: Extension for Simple TCP/IP Socket Client

PostgreSQL pgsocket: Extension for Simple TCP/IP Socket Client

原创 PostgreSQL 作者:digoal 时间:2018-10-09 14:56:01 0 删除 编辑

背景

PostgreSQL 插件,向外部tpc/ip socket服务发生字节流。

pgsocket is an extension for PostgreSQL server to send bytes to remote TCP/IP socket server.

For the first version only single function provided for one way data send in bytearray.

This extension is compiled in Linux against PostgreSQL version 10.

Download source code from   https://github.com/AbdulYadi/pgsocket . Build in Linux as usual:

$ USE_PGXS=1 make clean  
$ USE_PGXS=1 make  
$ USE_PGXS=1 make install

On successful compilation, install this extension in PostgreSQL environment

$ create extension pgsocket;

Let us send bytes to –for example– host with IP address nnn.nnn.nnn.nnn, port 9090, send time out 30 seconds, messages 'Hello'

$ select pgsocketsend('nnn.nnn.nnn.nnn', 9090, 30, (E'\\x' || encode('Hello', 'hex'))::bytea);

Or using address host name instead of IP address

$ select pgsocketsend('thesocketserver', 9090, 30, (E'\\x' || encode('Hello', 'hex'))::bytea);

Now, sending text from a table to remote TCP/IP socket server is easy. Assuming there is a table words:

id    txt  
——————–  
1    Life is easy  
2    with PostgreSQL

just do:

$ select pgsocketsend('thesocketserver', 9090, 30, (E'\\x' || encode(t.txt, 'hex'))::bytea)  
  
  
from words t WHERE t.id = 1;

参考

https://abdulyadi.wordpress.com/2018/09/11/pgsocket-extension-for-simple-socket-client/

https://github.com/AbdulYadi/pgsocket

https://abdulyadi.wordpress.com/2015/11/14/extension-for-qr-code-bitmap/

https://abdulyadi.wordpress.com/2012/03/03/consume-soap-web-service-from-postgresql-user-defined-function-in-c/

原文地址:https://github.com/digoal/blog/blob/master/201809/20180913_03.md

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23503672/viewspace-2215715/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
周正中 阿里云高级技术专家, 网名: 德哥 ( digoal );PostgreSQL 中国社区 发起人之一;PostgreSQL 象牙塔 发起人之一;DBA+社群 联合发起人之一;10余项数据库相关专利;完成了对数据库HA、容灾、备份、恢复、分布式、数据仓库架构设计和建设;数据库管理和开发的标准化体系建立。

注册时间:2018-09-30

  • 博文量
    55
  • 访问量
    52304