postgresql_16:3.2.9 Schemas
PostgreSQL 16 > The SQL Language > Data Definition > Schemas
A PostgreSQL database cluster contains one or more named databases. Roles and a few other object types are shared across the entire cluster. A client connection to the server can only access data in a single database, the one specified in the connection request.
Note
Users of a cluster do not necessarily have the privilege to access every database in the cluster. Sharing of role names means that there cannot be different roles named, say, joe in two databases in the same cluster; but the system can be configured to allow joe access to only some of the databases.
A database contains one or more named *schemas*, which in turn contain tables. Schemas also contain other kinds of named objects, including data types, functions, and operators. The same object name can be used in different schemas without conflict; for example, both schema1 and myschema can contain tables named mytable. Unlike databases, schemas are not rigidly separated: a user can access objects in any of the schemas in the database they are connected to, if they have privileges to do so.
There are several reasons why one might want to use schemas: To allow many users to use one database without interfering with each other. To organize database objects into logical groups to make them more manageable. Third-party applications can be put into separate schemas so they do not collide with the names of other objects. Schemas are analogous to directories at the operating system level, except that schemas cannot be nested.
Subsections
- postgresql_16:3.2.9.1 Creating a Schema
- postgresql_16:3.2.9.2 The Public Schema
- postgresql_16:3.2.9.3 The Schema Search Path
- postgresql_16:3.2.9.4 Schemas and Privileges
- postgresql_16:3.2.9.5 The System Catalog Schema
- postgresql_16:3.2.9.6 Usage Patterns
- postgresql_16:3.2.9.7 Portability