摘要: 为了验证对数据缓冲区 PqSendBuffer写入数据未满时,也要进行flush。对代码进行如下修改:pqcomm.c 的internal_putbytes 函数:头部加入:fprintf(stderr,"len is: %d",len); fprintf(stderr," , PqSendPointer is: %d\n", PqSendPointer);pqcomm.c 的pq_flush 函数:头部加入:fprintf(stderr," pq_flush is called\n.");重新编译后,启动Postgresql(非后台 阅读全文
posted @ 2012-07-17 14:27 健哥的数据花园 阅读(251) 评论(0) 推荐(0) 编辑
摘要: message level 函数pq_putmessage调用 low level 函数 pq_putbytes,pq_putbytes调用 internal_putbytes。从internal_putbyes上来看,就可以发现其数据发送的机制:有一个小技巧,如果数据缓冲区满了,就发送,否则就先堆在那儿。如果原有数据+本次数据量大于数据缓冲去大小那就分多次循环发送。internal_putbytes(const char *s, size_t len) { size_t amount; while (len > 0) { /* I... 阅读全文
posted @ 2012-07-17 13:50 健哥的数据花园 阅读(237) 评论(0) 推荐(0) 编辑
摘要: async.c的 static void NotifyMyFrontEnd(const char *channel, const char *payload, int32 srcPid) 函数中的主要逻辑是这样的:if (whereToSendOutput == DestRemote) { StringInfoData buf; pq_beginmessage(&buf, 'A'); //cursor 为 A pq_sendint(&buf, srcPid, sizeof(int32)); //追加 srcPid pq_sends... 阅读全文
posted @ 2012-07-17 10:00 健哥的数据花园 阅读(305) 评论(0) 推荐(0) 编辑
摘要: 磨砺技术珠矶,践行数据之道,追求卓越价值回到上一级页面:PostgreSQL基础知识与基本操作索引页 回到顶级页面:PostgreSQL索引页接PostgreSQL的notify 与listen (六)的内容,探讨一下谁真正接受notify 消息。修改PostgreSQL的源代码:src/backend/command/async.c:NotifyMyFrontEnd(const char *channel, const char *payload, int32 srcPid)函数if (whereToSendOutput == DestRemote){ StringInfoData ... 阅读全文
posted @ 2012-07-13 16:10 健哥的数据花园 阅读(799) 评论(0) 推荐(0) 编辑
摘要: 磨砺技术珠矶,践行数据之道,追求卓越价值回到上一级页面:PostgreSQL基础知识与基本操作索引页 回到顶级页面:PostgreSQL索引页开两个终端执行psql,进行notify 与 listen动作的实验,当时我有一个疑问:从listen 端看到的PID ,到底是谁的ID?验证如下:启动 postgres, 执行 ps -ef|grep postgres看到除了系统级别的postgres外,并没有其他的。postgres -D /usr/local/data (进程号为19651/父进程号为1)postgres:writer processpostgres:wal writer pro. 阅读全文
posted @ 2012-07-13 15:09 健哥的数据花园 阅读(541) 评论(0) 推荐(0) 编辑
摘要: src/test/examples/testlibpq2.c 中,有如下一段代码:sock = PQsocket(conn); FD_ZERO(&input_mask); FD_SET(sock, &input_mask); if (select(sock + 1, &input_ma... 阅读全文
posted @ 2012-07-13 12:30 健哥的数据花园 阅读(370) 评论(0) 推荐(0) 编辑
摘要: 程序逻辑大致如下: /* Make a connection to the database */ conn = PQconnectdb(conninfo); /* Check to see that the backend connection was successfully made */ if (PQstatus(conn) != CONNECTION_OK) { fprintf(stderr, "Connection to database failed: %s", PQerrorMessage(conn));... 阅读全文
posted @ 2012-07-13 10:21 健哥的数据花园 阅读(448) 评论(0) 推荐(0) 编辑
摘要: 磨砺技术珠矶,践行数据之道,追求卓越价值回到上一级页面:PostgreSQL基础知识与基本操作索引页 回到顶级页面:PostgreSQL索引页利用PostgreSQL的notify /listen 机制,可以实现在psql客户端看到通知消息。但是,如果是Java 应用程序,将会是怎样的?按照PostgreSQL的官方文档,是这样说的:http://jdbc.postgresql.org/documentation/91/listennotify.htmlA key limitation of theJDBCdriver is that it cannot receive asynchrono. 阅读全文
posted @ 2012-07-12 16:36 健哥的数据花园 阅读(2007) 评论(0) 推荐(0) 编辑
摘要: 磨砺技术珠矶,践行数据之道,追求卓越价值回到上一级页面:PostgreSQL基础知识与基本操作索引页 回到顶级页面:PostgreSQL索引页将 trigger 和 notify 结合起来,可以使客户端在 服务器端数据库表发生变化时,得到通知。从而实现 观察者模式:创建一个用于触发器的函数postgres#create function raise_evt() returns trigger as $$postgres$#beginpostgres$# notify gao;postgres$# return NEW;postgres$#end; $$postgres-#langua... 阅读全文
posted @ 2012-07-12 15:40 健哥的数据花园 阅读(1492) 评论(0) 推荐(0) 编辑
摘要: 磨砺技术珠矶,践行数据之道,追求卓越价值回到上一级页面:PostgreSQL基础知识与基本操作索引页 回到顶级页面:PostgreSQL索引页事实上,准确地说,notify命令的格式是:NOTIFY channel [ , payload ]首先是信息通道,然后才是 具体信息流。验证如下:session Apostgres#listen channel;session Bpostgres#notify channel '1';postgres#notify channel '2';回到session A随便执行一个命令:postgres#select curre 阅读全文
posted @ 2012-07-12 15:13 健哥的数据花园 阅读(966) 评论(0) 推荐(0) 编辑