Postgresql:创建视图并使用默认表空间?

发布于 2025-01-09 03:34:10 字数 262 浏览 1 评论 0原文

当我尝试在 PostgreSQL 13 中创建视图时,收到一条错误消息:“表空间 tbs_dft 的权限被拒绝”。正如你所看到的,我已经更改了系统默认表空间。通过授予在表空间“tbs_dft”上创建的权限,这个问题很容易解决。但我的问题是:为什么在创建包含简单 select 语句的视图时需要访问“默认表空间”?虽然这不是一个实际问题,但我正在尝试学习来自 Oracle 的 Postgresql,因此我不确定它是什么,我不了解 Postgresql 中视图创建的工作方式。

任何信息均感激不尽。

When I try to create a view in PostgreSQL 13 I get an error saying: "permission denied for tablespace tbs_dft". As you can see I've changed the system default tablespace. The problem is easy to fix by granting create on tablespace 'tbs_dft'. But my question is: why does it need to access the 'default tablespace' when creating a view containing a simple select statement? Although this is not a practical issue I am trying to learn Postgresql having come from Oracle and hence I'm not sure what it is I don't understand about the way View creation works in Postgresql.

Any information gratefully received.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦罢 2025-01-16 03:34:10

原因是每当创建关系时都会执行此检查(在 src/backend/commands/tablecmds.c 中的 DefineRelation 中)。关系是存储在 pg_class 中的任何内容:表、索引、序列、复合类型、视图或物化视图。

现在视图或复合类型没有数据文件,因此在这种情况下可以跳过检查。如果这对您很重要,请联系 pgsql-hackers 邮件列表上的开发人员。我认为这可以改进。

这是有问题的代码:

    /* Check permissions except when using database's default */
    if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
    {
        AclResult   aclresult;

        aclresult = pg_tablespace_aclcheck(tablespaceId, GetUserId(),
                                           ACL_CREATE);
        if (aclresult != ACLCHECK_OK)
            aclcheck_error(aclresult, OBJECT_TABLESPACE,
                           get_tablespace_name(tablespaceId));
    }

The reason is that this check is done whenever a relation is created (in DefineRelation in src/backend/commands/tablecmds.c). A relation is anything stored in pg_class: a table, an index, a sequence, a composite type, a view or a materialized view.

Now views or composite types do not have data files, so the check could be skipped in this case. If that is important for you, get in touch with development on the pgsql-hackers mailing list. This could be improved in my opinion.

Here is the code in question:

    /* Check permissions except when using database's default */
    if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
    {
        AclResult   aclresult;

        aclresult = pg_tablespace_aclcheck(tablespaceId, GetUserId(),
                                           ACL_CREATE);
        if (aclresult != ACLCHECK_OK)
            aclcheck_error(aclresult, OBJECT_TABLESPACE,
                           get_tablespace_name(tablespaceId));
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文