开发者社区> 问答> 正文

为什么PostgreSQL启动后有个UDP监听localhost

PostgreSQL启动后,通过netstat -anpo可以看到监听了一个UDP端口。
udp 0 0 127.0.0.1:51869 127.0.0.1:51869 ESTABLISHED 13443/postgres
为什么呢?
这个端口干什么用的?
有没有危险?

展开
收起
德哥 2016-01-07 15:00:36 3417 0
1 条回答
写回答
取消 提交回答
  • 公益是一辈子的事, I am digoal, just do it. 阿里云数据库团队, 擅长PolarDB, PostgreSQL, DuckDB, ADB等, 长期致力于推动开源数据库技术、生态在中国的发展与开源产业人才培养. 曾荣获阿里巴巴麒麟布道师称号、2018届OSCAR开源尖峰人物.

    用于pgstat进程发送和接收统计信息用的,见代码:
    src/backend/postmaster/pgstat.c

    /* ----------
     * pgstat_init() -
     *
     *      Called from postmaster at startup. Create the resources required
     *      by the statistics collector process.  If unable to do so, do not
     *      fail --- better to let the postmaster start with stats collection
     *      disabled.
     * ----------
     */
    void
    pgstat_init(void)
    {
            ACCEPT_TYPE_ARG3 alen;
            struct addrinfo *addrs = NULL,
                               *addr,
                                    hints;
            int                     ret;
            fd_set          rset;
            struct timeval tv;
            char            test_byte;
            int                     sel_res;
            int                     tries = 0;
    
    #define TESTBYTEVAL ((char) 199)
    
            /*
             * This static assertion verifies that we didn't mess up the calculations
             * involved in selecting maximum payload sizes for our UDP messages.
             * Because the only consequence of overrunning PGSTAT_MAX_MSG_SIZE would
             * be silent performance loss from fragmentation, it seems worth having a
             * compile-time cross-check that we didn't.
             */
            StaticAssertStmt(sizeof(PgStat_Msg) <= PGSTAT_MAX_MSG_SIZE,
                                       "maximum stats message size exceeds PGSTAT_MAX_MSG_SIZE");
    
            /*
             * Create the UDP socket for sending and receiving statistic messages
             */
            hints.ai_flags = AI_PASSIVE;
            hints.ai_family = AF_UNSPEC;
            hints.ai_socktype = SOCK_DGRAM;
            hints.ai_protocol = 0;
            hints.ai_addrlen = 0;
            hints.ai_addr = NULL;
            hints.ai_canonname = NULL;
            hints.ai_next = NULL;
            ret = pg_getaddrinfo_all("localhost", NULL, &hints, &addrs);
            if (ret || !addrs)
            {
                    ereport(LOG,
                                    (errmsg("could not resolve \"localhost\": %s",
                                                    gai_strerror(ret))));
                    goto startup_failed;
            }
    2019-07-17 18:23:44
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
PostgreSQL监控实战 立即下载
PostgreSQL复制原理及高可用集群 立即下载
Oracle 至PostgreSQL案例分享 立即下载

相关镜像