为什么所有数据库在 PostgreSQL 中都有一个公共模式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2134574/
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
Why do all databases have a public schema in PostgreSQL?
提问by rlb3
I was just curious why all databases in PostgreSQL have a public
schema that is accessible to all users. I know I can revoke privileges and grant them to one user but why is that not the default?
我只是好奇为什么 PostgreSQL 中的所有数据库都有一个public
可供所有用户访问的模式。我知道我可以撤销权限并将它们授予一个用户,但为什么这不是默认设置?
采纳答案by Dana the Sane
There isn't much justification given, but see section [5.7.6][1]in the manual, but I think the following answers your question:
没有给出太多理由,但请参阅手册中的[5.7.6][1]部分,但我认为以下内容可以回答您的问题:
If you do not create any schemas then all users access the public schema implicitly. This simulates the situation where schemas are not available at all. This setup is mainly recommended when there is only a single user or a few cooperating users in a database. This setup also allows smooth transition from the non-schema-aware world.
如果您不创建任何架构,则所有用户都会隐式访问公共架构。这模拟了模式根本不可用的情况。当数据库中只有一个用户或几个合作用户时,主要推荐使用此设置。此设置还允许从非模式感知世界平滑过渡。
回答by Evan Carroll
My guess would be the SQL spec. But, this is fairly logical what would create user
do otherwise, require you to explicitly say what schema the user had access too?
我的猜测是 SQL 规范。但是,这是相当合乎逻辑的,create user
否则会做什么,需要您明确说明用户也可以访问什么模式?
If your users don't have access to any single shared resource, why not just create a new DB for them? Unlike in MySQL, a new database is a new database, and not an alias for a new schema.
如果您的用户无权访问任何单个共享资源,为什么不为他们创建一个新数据库?与 MySQL 不同,新数据库是新数据库,而不是新模式的别名。
I just wanted to clarify this, it means that each database has its own public.
schema.
我只是想澄清这一点,这意味着每个数据库都有自己的public.
架构。