当前位置: 首页 > article >正文

postgresql 设置执行命令超时时间

通过设置statement_timeout参数设置命令最大执行时间,单位为毫秒,超过时间将取消执行.

1. 配置文件 设置

.在postgresql.conf中配置statement_timeout参数(单位为毫秒),会影响所有会话,不建议使用.

2.在当前会话中设置

仅对当前会话生效(单位为毫秒)

set statement_timeout to 30000;

3.Npgsql通过连接字符串设置

connectionString="ApplicationName=xxx;Server=xxx;Database=xxx;Userid=xxx;Password=xxx;Pooling=true;MinPoolSize=1;MaxPoolSize=100;CommandTimeout=50;"

连接字符串建议按以下格式设置
ApplicationName:应该程序名,建议设置,以便在pg中查看那些程序使用的连接
Server:pg服务器名称或ip
Database:pg数据库名称
Userid:pg数据库用户名
Password:pg数据库密码
Pooling:是否使用连接池
MinPoolSize:连接池最小数量
MaxPoolSize:连接池最大数量
CommandTimeout:执行使命超时时间(单位为秒),执行sql超过此时间将取消,并返回一个错误
虽然设置了Pooling,便使用完成后连接仍要关闭

4.JAVA

其它语言连接成功后,立即执行的命令(单位为毫秒)

    private PgConnection openDatabase(String appName, DBConfig pDBConf) throws SQLException {//https://jdbc.postgresql.org/documentation/head/connect.htmlString connString = String.format("jdbc:postgresql://%s:%d/%s",pDBConf.getServer(), pDBConf.getPort(), pDBConf.getDBName());Properties props = new Properties();props.setProperty("ApplicationName", appName);props.setProperty("user", pDBConf.getUser());props.setProperty("password", pDBConf.getPassword());props.setProperty("ssl", "false");props.setProperty("connectTimeout", String.valueOf(pDBConf.getConnTimeout())); //设置连接超时时间//props.setProperty("readOnly", "true");        //是否只读取,集群时使用从机需要设置props.setProperty("options", String.format("-c statement_timeout=%d", pDBConf.getStatementTimeout())); //设置执行命令超时时间props.setProperty("prepareThreshold", String.valueOf(pDBConf.getPrepareThreshold())); //同一sql执行至第几次开始使用预处理sqlprops.setProperty("preparedStatementCacheQueries", String.valueOf(pDBConf.getPreparedStatementCacheQueries())); //每个连接中缓存的SQL数量props.setProperty("preparedStatementCacheSizeMiB ", String.valueOf(pDBConf.getPreparedStatementCacheSizeMiB())); //预备语句查询缓存大小,单位为MB,0为禁用Connection conn = DriverManager.getConnection(connString, props);conn.setAutoCommit(false);return (PgConnection) conn;}

然后再做其它操作.

http://www.lryc.cn/news/2416502.html

相关文章:

  • nginx + lua环境配置
  • 【Excel系列9】-- 28个基础图表
  • 在JavaEye晃了一个来月真的感慨。
  • 从零开始搭建 reviewboard 环境(四) -- reviewboard 的安装过程中的问题解决
  • IP欺骗
  • 使用NE555制作多谐振荡器
  • MFC的坐标转换GetClientRect/GetWindowRect/ClientToScreen/GetCursorPos/ScreenToClient
  • Collections.synchronizedMap()与ConcurrentHashMap的区别
  • C++中critical section的使用
  • 高等数学学习笔记——第九十九讲——一阶线性微分方程组
  • 初学C语言以及C语言的常见概念
  • Sublime text 3最新注册码
  • Windows Installer Clean Up 软件正常卸载不了时,请它帮忙!
  • cocostudio使用基本要点汇总
  • AIS(自动识别系统)介绍
  • 【.NET】.NET 框架概述
  • fastDB个人使用心得
  • 进化算法——多目标优化
  • MNE溯源fieldtrip官网教程
  • JDK1.6安装详解、环境变量设置、测试安装及注意事项
  • leetcode Surrounded Regions 详解
  • java正则Matcher.matches()、Matcher.lookingAt()、Matcher.find()、 group()详解
  • 【实践】java.lang.Integer源码分析
  • CImage 从内存中读取图像
  • FileZilla Server简介及使用说明
  • 解决Adobe reader 8 突然打不开了并报许可协议的问题
  • 2023年【A特种设备相关管理(锅炉压力容器压力管道)】报名考试及A特种设备相关管理(锅炉压力容器压力管道)模拟考试题
  • vue 项目如何捕获awit 错误情况
  • 可行性分析与需求分析 —以图书馆管理系统为例
  • 破解密码的8种典型手段与防护建议