Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do all databases have a public schema in PostgreSQL?

Tags:

postgresql

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?

like image 685
rlb3 Avatar asked Jan 25 '10 18:01

rlb3


People also ask

What is public schema Postgres?

Public schema and public roleWhen a new database is created, PostgreSQL by default creates a schema named public and grants access on this schema to a backend role named public . All new users and roles are by default granted this public role, and therefore can create objects in the public schema.

Is public default schema in PostgreSQL?

In PostgreSQL, by default, every database owns a default Schema named public. If you do not mention schema_name while creating or accessing the object then PostgreSQL will consider the schema_name as public.

Can you drop public schema in PostgreSQL?

PostgreSQL DROP SCHEMA statement overview Third, use CASCADE to delete schema and all of its objects, and in turn, all objects that depend on those objects. If you want to delete schema only when it is empty, you can use the RESTRICT option. By default, the DROP SCHEMA uses the RESTRICT option.

What is the use of schema in PostgreSQL?

Schema is a collection of logical structures of data. In PostgreSQL, schema is a named collection of tables, views, functions, constraints, indexes, sequences etc. PostgreSQL supports having multiple schemas in a single database there by letting you namespace different features into different schemas.


1 Answers

There isn't much justification given, but see section [5.7.6][1] in the manual, but I think the following answers your question:

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.

like image 104
Dana the Sane Avatar answered Sep 20 '22 16:09

Dana the Sane