Creating and Managing Schemas

A schema is the logical organization of objects and data in a database. Schema management allows multiple users to use the same database without interfering with each other. Third-party applications can be added to corresponding schemas to avoid conflicts.

The same database object name can be used in different schemas in a database without causing conflicts. For example, both a_schema and b_schema can contain a table named mytable. Users with required permissions can access objects across multiple schemas in a database.

If a user is created, a schema named after the user will also be created in the current database.

Public mode

Each database has a schema named public. All users have the ability to use the public schema in the database, but only certain roles have the authority to create objects within it.

Creating a Schema

Modifying a Schema

Setting the Schema Search Path

The GUC parameter search_path specifies the schema search sequence. The parameter value is a series of schema names separated by commas (,). If no schema is specified during object creation, the object will be added to the first schema displayed in the search path. If there are objects with the same name in different schemas and no schema is specified for an object query, the object will be returned from the first schema containing the object in the search path.

Using a Schema

If you want to create or access an object in a specified schema, the object name must contain the schema name. To be specific, the name consists of a schema name and an object name, which are separated by a dot (.).

Viewing a Schema

Schema Permission Control

By default, a user can only access database objects in its own schema. To access objects in other schemas, the user must have the usage permission of the corresponding schema.

By granting the CREATE permission for a schema to a user, the user can create objects in this schema.

Drop Schema

System Schema