开发者社区> 嗯哼9925> 正文

PostgreSQL在何处处理 sql查询之十八

简介:
+关注继续查看

接前面,由于看到对 BasicOpenFile 函数的调用。

自然想到,如果两个进程同时访问一个表(即同一文件),会否有冲突或效率的问题。

开两个psql客户端,连接数据库后,后台生成两个进程,

分别运行 select * from tst01 进行观察...发现各进程之间互相不干扰。

我实验的方法,加入调试代码:

复制代码
/*
 * BasicOpenFile --- same as open(2) except can free other FDs if needed
 *
 * This is exported for use by places that really want a plain kernel FD,
 * but need to be proof against running out of FDs.  Once an FD has been
 * successfully returned, it is the caller's responsibility to ensure that
 * it will not be leaked on ereport()!    Most users should *not* call this
 * routine directly, but instead use the VFD abstraction level, which
 * provides protection against descriptor leaks as well as management of
 * files that need to be open for more than a short period of time.
 *
 * Ideally this should be the *only* direct call of open() in the backend.
 * In practice, the postmaster calls open() directly, and there are some
 * direct open() calls done early in backend startup.  Those are OK since
 * this module wouldn't have any open files to close at that point anyway.
 */
int
BasicOpenFile(FileName fileName, int fileFlags, int fileMode)
{
    int            fd;
    //char *tst01=(char *)fileName;
    char *tst02="base/12788/16384"; //tst01 table's file is base/12788/16384

tryAgain:

    fd = open(fileName, fileFlags, fileMode);

    char *tst01=(char *)fileName;
    fprintf(stderr,"length of fileName is:%d\n",strlen(fileName));

    if ( strcmp( fileName, tst02) == 0)
    {
        fprintf(stderr,"Sleeping.....by Process:%d\n",getpid());
        sleep(120);
    }

    //fd = open(fileName, fileFlags, fileMode);

    if (fd >= 0)
        return fd;                /* success! */

    if (errno == EMFILE || errno == ENFILE)
    {
        int            save_errno = errno;

        ereport(LOG,
                (errcode(ERRCODE_INSUFFICIENT_RESOURCES),
                 errmsg("out of file descriptors: %m; release and retry")));
        errno = 0;
        if (ReleaseLruFile())
            goto tryAgain;
        errno = save_errno;
    }

    return -1;                    /* failure */
}
复制代码

那么如果同时写入的时候又会如何,这个问题还需进一步地观察代码。

至少,不同的进程同时读一个表,在文件IO级别,没有发生阻塞。







本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2013/05/26/3100075.html,如需转载请自行联系原作者

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
JPA的EntityManager来实现SQL或者HQL语句查询
JPA的EntityManager来实现SQL或者HQL语句查询
11 0
《阿里云认证的解析与实战-数据仓库ACP认证》——云原生数据仓库AnalyticDB PostgreSQL版功能演示(上)——五、执行SQL查询
《阿里云认证的解析与实战-数据仓库ACP认证》——云原生数据仓库AnalyticDB PostgreSQL版功能演示(上)——五、执行SQL查询
17 0
提高sql查询性能-使用instr函数替换like
提高sql查询性能-使用instr函数替换like
18 0
【Python】单表多功能查询的SQL封装
【Python】单表多功能查询的SQL封装
16 0
1 SQL快速入门、查询(SqlServer)[郝斌SqlServer完整版]
系统数据库:master、model、msdb、tempdb【我们自定义数据库的管理维护运行都需要系统库支持】
17 0
Django model层之执行原始SQL查询
Django model层之执行原始SQL查询
26 0
【大数据开发运维解决方案】Oracle Sql基础查询
空字符串在oracle中常常相当于null,为什么不说空字符串等价于null呢,看案例: 可以看到,本身deptno是number类型的,而‘’字符串本身是varchar类型,这与null可以是任何类型不同,所以也就不等价。
54 0
Zp
Oracle给sql查询字段的结果后加上%
Oracle给sql查询字段的结果后加上%
195 0
【SQL系列】指定顺序返回查询结果
【SQL系列】指定顺序返回查询结果
88 0
+关注
嗯哼9925
文章
问答
视频
文章排行榜
最热
最新
相关电子书
更多
第十二届 BigData NoSQL Meetup — 基于hbase的New sql落地实践
立即下载
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
相关实验场景
更多
相关镜像