GaussDB Logical Objects: Tablespaces, Databases, Schemas, Users & Permissions
This article explains GaussDB's logical object hierarchy — tablespaces, databases, schemas, users, and roles — detailing their relationships, default behaviors, search_path mechanics, and permission management including system vs object privileges, ANY privileges, and special schema access rules, with a comparison to MySQL's schema model.
Reading font
GaussDB Logical Objects
Tablespaces, Databases, and Tables
GaussDB logical objects include tablespaces, databases, tables, and indexes. A database is a logical collection of data; a tablespace is the physical storage directory. All database objects are stored in tablespaces.
Tablespace : A directory; multiple tablespaces can exist. Each tablespace can correspond to multiple databases. The system default tablespace is pg_default; tables created without a specified tablespace use this default.
Database : A logical abstraction; databases are isolated from each other. Objects within a single database can reside in multiple tablespaces. GaussDB creates a default postgres database.
Table : A structured view of data. Each table belongs to exactly one database and maps to exactly one tablespace; all its data files must reside in that tablespace.
Key relationships:
A database instance can define multiple databases and tablespaces.
A database can contain multiple tablespaces.
A tablespace can contain multiple databases.
A database can contain multiple tables.
A table must belong to one database and be stored in one tablespace.
Users and Schemas
Users, roles, and schemas serve distinct purposes:
User : An entity for authentication and permission management. Users are shared across the instance; a single user can connect to any database, but data access is controlled by permissions.
Role : A collection of users (or other roles) forming a hierarchy. Permissions granted to a role are inherited by its members, enabling bulk assignment and revocation.
Schema : A container for database objects (tables, views, procedures, functions). Each database can have multiple schemas, providing logical isolation. A default public schema exists after database creation.
When a new user is created, GaussDB automatically creates a same-named schema in the current database; attempting to create another same-named schema in that database will report an error. For other databases, a same-named schema must be created manually.
If a schema is not explicitly specified when accessing a table, the search_path determines which schema's table is used. The search path is an ordered list of schema names; the first match wins. pg_temp and pg_catalog are always the first two entries. The first schema in the search path is the current_schema (viewable via show current_schema), and new objects are created there by default.
User–Database–Schema relationships:
A database can contain multiple users; users are instance-wide.
A database can define multiple schemas; schemas are isolated, and different databases can have schemas with the same name.
A schema contains multiple objects, but each object belongs to exactly one schema.
Access to different schemas across databases is controlled by granting specific permissions to users or roles.
Permission Management
GaussDB follows Oracle-style privilege management with two levels:
System privileges : Rights to use database features, e.g., LOGIN, CREATEDB, CREATEROLE.
Object privileges : Rights to perform actions on specific objects (databases, schemas, tables, views, functions), e.g., SELECT, UPDATE, INSERT, DELETE.
Common authorization scenarios:
Grant system privileges to roles or users (e.g., SYSADMIN, MONADMIN).
Grant object privileges on specific objects to roles or users (e.g., all privileges on a schema, all privileges on tables within a schema).
Grant a role or user to other users or roles (e.g., create a read-only role and grant it to multiple users).
Grant ANY privileges (e.g., CREATE ANY, SELECT ANY TABLE). Granting SELECT ANY TABLE gives a user query access to all schemas in the current database, convenient for read-only users.
Permission granularity is very fine; practical management follows the principle of least privilege. Typical patterns:
Global read-only users receive SELECT ANY privileges.
Business read-write users receive object-level DML privileges.
System views like pg_catalog and sys require specific grants.
Important caveats:
Access to the DBE_PREF system schema requires MONADMIN privilege; a simple SELECT grant is insufficient.
To access objects inside a schema, the user must have USAGE privilege on that schema.
Comparison with MySQL
In MySQL:
Schema is essentially a synonym for database ; creating a database creates a schema.
Tables are the basic storage unit.
Tablespaces: InnoDB has a system tablespace and, with innodb_file_per_table enabled, a separate tablespace file per table containing data, indexes, and insert buffers.
Logically, a MySQL database instance corresponds to a GaussDB database; a MySQL instance can contain multiple databases/schemas, each holding tables, and they share the system tablespace and resources.
Summary
Logically, GaussDB separates data by databases . An instance contains multiple databases; each database contains schemas; schemas contain objects.
Physically, tablespaces map to storage directories. A database can use multiple tablespaces, and a tablespace can serve multiple databases. The article recommends using the default tablespace in practice.
Permission control uses fine-grained grants to users/roles on specific objects to achieve least privilege.
References:
https://doc.hcs.huawei.com/db/zh-cn/gaussdbqlh/24.1.30
https://blog.csdn.net/weixin_38623994/article/details/100047552
https://bbs.huaweicloud.com/blogs/236381
For questions about attribution, corrections or content rights, please contactand we will review it promptly.