在 postgresql 中设置 extra_float_digits = 3

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24680696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:32:40  来源:igfitidea点击:

SET extra_float_digits = 3 in postgresql

sqldatabasepostgresql

提问by WinSupp

Whenever I start Postgresql DB engine, I have almost 7-8 queries running in the background SET extra_float_digits = 3

每当我启动 Postgresql 数据库引擎时,我都会在后台运行近 7-8 个查询 SET extra_float_digits = 3

I am not sure why these are running all the times. I know that the extra_float_digits variable adjusts the number of digits displayed for floating-point values in Postgresql, however I am not sure why these queries run in the background when I start the DB engine.

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

I already have the extra_float_digits = 3 in the config file. Even if I comment it out, these queries still run in the background..

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

need help..Thanks

需要帮助..谢谢

回答by Craig Ringer

The queries aren't really running. As Nick says in the comments, the connections will be in idle state. pg_stat_activityshows the last statement that finished running when a query is idle.

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

As for the other part: I'd say you're using PgJDBC. SET extra_float_digitsensures that PgJDBC doesn't lose precision when it gets floating point values from the database. It's part of the initial connection conversation. It's normal and you can ignore it. If you're on a recent PgJDBC, send the additional connection parameter assumeMinServerVersion=9.0and it'll go away.

至于另一部分:我会说您正在使用 PgJDBC。SET extra_float_digits确保 PgJDBC 从数据库获取浮点值时不会丢失精度。这是初始连接对话的一部分。这是正常的,你可以忽略它。如果您使用的是最近的 PgJDBC,发送额外的连接参数assumeMinServerVersion=9.0,它就会消失

So what you have there is a bunch of new, idle connections.

所以你有一堆新的空闲连接。

Look into your application / application server's configuration. Your connection pool probably doesn't have reasonable limits set.

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

回答by HectorBonilha

I've had this problem with Java and Postgresql. I've resolved this issue by using PGPoolingDataSource and Close connection.

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

Here how I've built my classes:

在这里,我如何构建我的课程:

//Class Factory Connection:

//类工厂连接:

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;      
    }
}

//Class userDAO - class to interact with database

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

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;
}

回答by Bles

in my option you can end this connections with a pg-command. For example:

在我的选项中,您可以使用 pg 命令结束此连接。例如:

SELECT pg_terminate_backend(t.pid) FROM (SELECT pid FROM pg_stat_activity WHERE state = 'idle' AND query like '%float%' AND state_change<(now() - interval '1 hour')) AS t;

SELECT pg_terminate_backend(t.pid) FROM (SELECT pid FROM pg_stat_activity WHERE state = 'idle' AND query like '%float%' AND state_change<(now() - interval '1 hours')) AS t;

回答by Nissamudeen Abdulsalam Rawther

Whenever a new connection is established, postgres triggers this extra_float_digitssetting. Issue was with my database health check module.

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