背景

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 fromhttps://github.com/AbdulYadi/pgsocket. Build in Linux as usual:

$USE_PGXS=1makeclean$USE_PGXS=1make$USE_PGXS=1makeinstall

On successful compilation, install this extension in PostgreSQL environment

$createextensionpgsocket;

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

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

Or using address host name instead of IP address

$selectpgsocketsend('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:

idtxt——————–1Lifeiseasy2withPostgreSQL

just do:

$selectpgsocketsend('thesocketserver',9090,30,(E'\\x'||encode(t.txt,'hex'))::bytea)fromwordstWHEREt.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