监控postgresql操作
- 
刚开始学习OE,客户端字段对应的数据库中的那个表和字段,不容易找到。 
 解决方法,开启pg的慢日志功能,运行代码,直接监视数据库的操作,
 只要在Form上动动鼠标,就能直接看到是操作了哪个表,哪个字段了。
 程序代码:
 # -- encoding: utf-8 --
 import time
 import re
 import os
 def lastfile (path):
 flage=None
 lastfile=None
 for i in os.listdir(path):
 file=path+i
 if ( os.path.isfile(file) 
 t=os.stat(file).st_ctime
 if (flage):
 if t > flage :
 lastfile=i
 else:
 flage=t
 lastfile=i
 return path + lastfile
 class tail:
 def init (self,file,match):
 self.f=open(file)
 self.match=match
 
 def auto (self,):
 f=self.f
 f.seek(0,2)
 while True :
 line=f.readline()
 if not line:
 time.sleep(0.1)
 continue
 if self.match in line:
 yield line
 
 if name == "main":
 path=r'C:\PostgreSQL\8.4\data\pg_log\'
 lastfile=lastfile(path)
 lines=tail( lastfile, 'update').auto()
 for line in lines:
 obj_re = re.search('statement:.*',line)
 print obj_re.group()
 程序代码:
- 
pg的配置文件中 logging_collector = on 
 然后重启服务