51.47. pg_shdepend
В каталоге pg_shdepend записываются отношения зависимости между объектами баз данных и разделяемыми объектами, такими как роли. Эта информация позволяет Postgres Pro удостовериться, что эти объекты не используется, прежде чем удалять их.
Также смотрите каталог pg_depend, который играет подобную роль в отношении зависимостей объектов в одной базе данных.
В отличие от большинства системных каталогов, pg_shdepend разделяется всеми базами данных кластера: есть только один экземпляр pg_shdepend в кластере, а не отдельные в каждой базе данных.
Таблица 51.47. Столбцы pg_shdepend
| Имя | Тип | Ссылки | Описание |
|---|---|---|---|
dbid | oid | | OID базы данных, в которой находится зависимый объект, или ноль, если это глобальный объект |
classid | oid | | OID системного каталога, в котором находится зависимый объект |
objid | oid | любой столбец OID | OID определённого зависимого объекта |
objsubid | int4 | Для столбца таблицы это номер столбца (objid и classid указывают на саму таблицу). Для всех других типов объектов это поле содержит ноль. | |
refclassid | oid | | OID системного каталога, к которому относится вышестоящий объект (это должен быть разделяемый каталог) |
refobjid | oid | любой столбец OID | OID определённого вышестоящего объекта |
deptype | char | Код, определяющий конкретную семантику данного отношения зависимости; см. текст |
Во всех случаях, запись в pg_shdepend показывает, что вышестоящий объект нельзя удалить, не удаляя подчинённый объект. Однако есть несколько подвидов зависимости, задаваемых в поле deptype:
SHARED_DEPENDENCY_OWNER(o)Вышестоящий объект (это должна быть роль) является владельцем зависимого объекта.
SHARED_DEPENDENCY_ACL(a)Вышестоящий объект (это должна быть роль) упоминается в ACL (списке управления доступом, то есть списке прав) подчинённого объекта. (Запись
SHARED_DEPENDENCY_ACLне создаётся для владельца объекта, так как для владельца всё равно имеется записьSHARED_DEPENDENCY_OWNER.)SHARED_DEPENDENCY_POLICY(r)Вышестоящий объект (это должна быть роль) упомянут в качестве целевого в объекте зависимой политики.
SHARED_DEPENDENCY_PIN(p)Зависимый объект отсутствует; этот тип записи показывает, что система сама зависит от вышестоящего объекта, так что этот объект нельзя удалять ни при каких условиях. Записи этого типа создаются только командой
initdb. Поля зависимого объекта в такой записи содержат нули.
В будущем могут появиться и другие подвиды зависимости. Заметьте в частности, что с текущим определением вышестоящими объектами могут быть только роли.
51.47. pg_shdepend
The catalog pg_shdepend records the dependency relationships between database objects and shared objects, such as roles. This information allows Postgres Pro to ensure that those objects are unreferenced before attempting to delete them.
See also pg_depend, which performs a similar function for dependencies involving objects within a single database.
Unlike most system catalogs, pg_shdepend is shared across all databases of a cluster: there is only one copy of pg_shdepend per cluster, not one per database.
Table 51.47. pg_shdepend Columns
| Name | Type | References | Description |
|---|---|---|---|
dbid | oid | | The OID of the database the dependent object is in, or zero for a shared object |
classid | oid | | The OID of the system catalog the dependent object is in |
objid | oid | any OID column | The OID of the specific dependent object |
objsubid | int4 | For a table column, this is the column number (the objid and classid refer to the table itself). For all other object types, this column is zero. | |
refclassid | oid | | The OID of the system catalog the referenced object is in (must be a shared catalog) |
refobjid | oid | any OID column | The OID of the specific referenced object |
deptype | char | A code defining the specific semantics of this dependency relationship; see text |
In all cases, a pg_shdepend entry indicates that the referenced object cannot be dropped without also dropping the dependent object. However, there are several subflavors identified by deptype:
SHARED_DEPENDENCY_OWNER(o)The referenced object (which must be a role) is the owner of the dependent object.
SHARED_DEPENDENCY_ACL(a)The referenced object (which must be a role) is mentioned in the ACL (access control list, i.e., privileges list) of the dependent object. (A
SHARED_DEPENDENCY_ACLentry is not made for the owner of the object, since the owner will have aSHARED_DEPENDENCY_OWNERentry anyway.)SHARED_DEPENDENCY_POLICY(r)The referenced object (which must be a role) is mentioned as the target of a dependent policy object.
SHARED_DEPENDENCY_PIN(p)There is no dependent object; this type of entry is a signal that the system itself depends on the referenced object, and so that object must never be deleted. Entries of this type are created only by
initdb. The columns for the dependent object contain zeroes.
Other dependency flavors might be needed in future. Note in particular that the current definition only supports roles as referenced objects.