首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在postgresql中设置extra_float_digits =3

在postgresql中设置extra_float_digits =3
EN

Stack Overflow用户
提问于 2014-07-10 23:36:19
回答 4查看 15.9K关注 0票数 15

每当我启动Postgresql DB引擎时,我几乎有7-8个查询在后台SET extra_float_digits = 3中运行

我不确定为什么这些总是在运行。我知道extra_float_digits变量会调整Postgresql中浮点值的显示位数,但是我不确定为什么当我启动DB引擎时,这些查询会在后台运行。

我已经在配置文件中设置了extra_float_digits =3。即使我将其注释掉,这些查询仍然在后台运行。

需要help..Thanks

EN

回答 4

Stack Overflow用户

发布于 2014-07-11 11:05:06

查询并没有真正运行。正如Nick在评论中所说,连接将处于空闲状态。pg_stat_activity显示查询空闲时完成运行的最后一条语句。

至于另一部分:我会说你使用的是PgJDBC。SET extra_float_digits确保PgJDBC在从数据库获取浮点值时不会丢失精度。这是初始连接对话的一部分。这很正常,你可以忽略它。If you're on a recent PgJDBC, send the additional connection parameter assumeMinServerVersion=9.0 and it'll go away

因此,您所拥有的是一堆新的空闲连接。

查看应用程序/应用程序服务器的配置。您的连接池可能没有设置合理的限制。

票数 13
EN

Stack Overflow用户

发布于 2014-11-10 22:50:41

每当建立新连接时,postgres都会触发此extra_float_digits设置。问题出在我的数据库健康检查模块。

票数 1
EN

Stack Overflow用户

发布于 2016-02-28 03:44:58

我在使用Java和Postgresql时遇到过这个问题。我已经通过使用PGPoolingDataSource和Close connection解决了这个问题。

下面是我是如何构建类的:

//类工厂连接:

代码语言:javascript
复制
public class FacConn {

    public static PGPoolingDataSource getConnection2() {
    PGPoolingDataSource source = new PGPoolingDataSource();
    source.setServerName("local");
    source.setPortNumber(5432);
    source.setDatabaseName("mydbname");
    source.setUser("LoginUser");
    source.setPassword("password");
    source.setAssumeMinServerVersion("9.0");
    source.setConnectTimeout(50000);        

    return source;      
    }
}

//类userDAO -与数据库交互的类

代码语言:javascript
复制
public class UsuarioDAO {

    private PGPoolingDataSource poolDS = FabConexao.getConnection2();
    private Connection con = null;

    public User searchById(Integer id){
        try{con = poolDS.getConnection();}
        catch (SQLException e){throw new RuntimeException(e);}

        String sql = "Select * from people where id_people=?";
        ResultSet rs = null;

        try (PreparedStatement smtm = con.prepareStatement(sql)){
            smtm.setInt(1, id);
            rs = smtm.executeQuery();
            People people = new People();
            if(rs.next()){
                people.setId_People(rs.getInt("id_people"));
                people.setFirtname(rs.getString("firstname"));
                people.setLastname(rs.getString("lastname"));
                people.setAge(rs.getInt("age"));
                people.setActiv(rs.getBoolean("activ"));
            } 
            smtm.close();   
            return people;
        } catch (SQLException e){
            e.printStackTrace();
            System.err.println( e.getClass().getName()+": "+ e.getMessage() );          
        }  finally {
            if (rs != null) {
                try {rs.close();} catch (SQLException e) { /* ignored */}
            }
            poolDS.close();
        }
        return null;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24680696

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档