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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With