manager

package
v1.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func New

func New(conn pg.PoolConn, opt ...Opt) (*Manager, error)

func (*Manager) CreateDatabase

func (manager *Manager) CreateDatabase(ctx context.Context, meta schema.DatabaseMeta) (_ *schema.Database, err error)

CreateDatabase creates a new database with the specified metadata. The database creation cannot be done in a transaction, but ACL grants are applied within a transaction. If ACL grants fail, the database is deleted to maintain consistency.

func (*Manager) CreateExtension

func (manager *Manager) CreateExtension(ctx context.Context, meta schema.ExtensionMeta, cascade bool) (_ *schema.Extension, err error)

CreateExtension installs an extension in a database. The Database field in meta specifies which database to install into. If cascade is true, dependent extensions are also installed.

func (*Manager) CreateReplicationSlot

func (manager *Manager) CreateReplicationSlot(ctx context.Context, meta schema.ReplicationSlotMeta) (_ *schema.ReplicationSlot, err error)

CreateReplicationSlot creates a new replication slot with the specified metadata. Type must be "physical" or "logical". Logical slots require a plugin name.

func (*Manager) CreateRole

func (manager *Manager) CreateRole(ctx context.Context, meta schema.RoleMeta) (_ *schema.Role, err error)

CreateRole creates a new role with the specified metadata. The name must be a valid identifier and cannot have the reserved "pg_" prefix.

func (*Manager) CreateSchema

func (manager *Manager) CreateSchema(ctx context.Context, database string, meta schema.SchemaMeta) (_ *schema.Schema, err error)

CreateSchema creates a new schema in the specified database with the given metadata. ACL grants are applied after schema creation. If ACL grants fail, the schema is deleted to maintain consistency.

func (*Manager) CreateTablespace

func (manager *Manager) CreateTablespace(ctx context.Context, meta schema.TablespaceMeta, location string) (_ *schema.Tablespace, err error)

CreateTablespace creates a new tablespace with the specified metadata and location. The tablespace creation cannot be done in a transaction, but ACL grants are applied within a transaction. If ACL grants fail, the tablespace is deleted to maintain consistency.

func (*Manager) DeleteConnection

func (manager *Manager) DeleteConnection(ctx context.Context, pid uint64) (_ *schema.Connection, err error)

DeleteConnection terminates a connection by process ID and returns the terminated connection. Returns an error if the pid is zero or the connection is not found.

func (*Manager) DeleteDatabase

func (manager *Manager) DeleteDatabase(ctx context.Context, name string, force bool) (_ *schema.Database, err error)

DeleteDatabase drops a database by name and returns its metadata before deletion. If force is true, the database is dropped even if there are active connections.

func (*Manager) DeleteExtension

func (manager *Manager) DeleteExtension(ctx context.Context, database, name string, cascade bool) (err error)

func (*Manager) DeleteReplicationSlot

func (manager *Manager) DeleteReplicationSlot(ctx context.Context, name string) (_ *schema.ReplicationSlot, err error)

DeleteReplicationSlot drops a replication slot by name. Returns the slot metadata before deletion.

func (*Manager) DeleteRole

func (manager *Manager) DeleteRole(ctx context.Context, name string) (_ *schema.Role, err error)

DeleteRole deletes a role by name and returns the deleted role. Returns an error if the name is empty, has a reserved prefix, or the role is not found.

func (*Manager) DeleteSchema

func (manager *Manager) DeleteSchema(ctx context.Context, database, namespace string, force bool) (_ *schema.Schema, err error)

DeleteSchema drops a schema by database and namespace name, returning its metadata before deletion. If force is true, the schema is dropped with CASCADE even if there are dependent objects.

func (*Manager) DeleteTablespace

func (manager *Manager) DeleteTablespace(ctx context.Context, name string) (_ *schema.Tablespace, err error)

DeleteTablespace drops a tablespace by name and returns its metadata before deletion. Returns an error if the name is empty or the tablespace is not found.

func (*Manager) GetConnection

func (manager *Manager) GetConnection(ctx context.Context, pid uint64) (_ *schema.Connection, err error)

GetConnection retrieves a single connection by process ID. Returns an error if the pid is zero or the connection is not found.

func (*Manager) GetDatabase

func (manager *Manager) GetDatabase(ctx context.Context, name string) (_ *schema.Database, err error)

GetDatabase retrieves a single database by name. Returns an error if the name is empty or the database is not found.

func (*Manager) GetExtension

func (manager *Manager) GetExtension(ctx context.Context, name string) (_ *schema.Extension, err error)

func (*Manager) GetInstalledExtension

func (manager *Manager) GetInstalledExtension(ctx context.Context, name, database string) (_ *schema.Extension, err error)

func (*Manager) GetObject

func (manager *Manager) GetObject(ctx context.Context, database, namespace, name string) (_ *schema.Object, err error)

func (*Manager) GetReplicationSlot

func (manager *Manager) GetReplicationSlot(ctx context.Context, name string) (_ *schema.ReplicationSlot, err error)

GetReplicationSlot retrieves a single replication slot by name. Returns an error if the name is empty or the slot is not found.

func (*Manager) GetRole

func (manager *Manager) GetRole(ctx context.Context, name string) (_ *schema.Role, err error)

GetRole retrieves a single role by name. Returns an error if the name is empty or the role is not found.

func (*Manager) GetSchema

func (manager *Manager) GetSchema(ctx context.Context, database, namespace string) (_ *schema.Schema, err error)

GetSchema retrieves a single schema by database and namespace name. Returns an error if the database or namespace is empty or the schema is not found.

func (*Manager) GetSetting

func (manager *Manager) GetSetting(ctx context.Context, name string) (_ *schema.Setting, err error)

GetSetting returns a single setting by name.

func (*Manager) GetTablespace

func (manager *Manager) GetTablespace(ctx context.Context, name string) (_ *schema.Tablespace, err error)

GetTablespace retrieves a single tablespace by name. Returns an error if the name is empty or the tablespace is not found.

func (*Manager) ListConnections

func (manager *Manager) ListConnections(ctx context.Context, req schema.ConnectionListRequest) (_ *schema.ConnectionList, err error)

ListConnections returns a list of active database connections matching the request criteria. It supports filtering by database, role, and state, as well as pagination.

func (*Manager) ListDatabases

func (manager *Manager) ListDatabases(ctx context.Context, req schema.DatabaseListRequest) (_ *schema.DatabaseList, err error)

ListDatabases returns a list of databases matching the request criteria. It supports pagination through the OffsetLimit fields in the request.

func (*Manager) ListExtensions

func (manager *Manager) ListExtensions(ctx context.Context, req schema.ExtensionListRequest) (_ *schema.ExtensionList, err error)

ListExtensions returns a list of extensions. If Database is specified, shows extensions for that specific database (with installed status). If Database is not specified, shows available extensions cluster-wide from the current connection. Use the Installed filter to show only installed, only not-installed, or all extensions.

func (*Manager) ListObjects

func (manager *Manager) ListObjects(ctx context.Context, req schema.ObjectListRequest) (_ *schema.ObjectList, err error)

func (*Manager) ListReplicationSlots

func (manager *Manager) ListReplicationSlots(ctx context.Context, req schema.ReplicationSlotListRequest) (_ *schema.ReplicationSlotList, err error)

ListReplicationSlots returns a list of replication slots with their status. Includes lag information for connected replicas.

func (*Manager) ListRoles

func (manager *Manager) ListRoles(ctx context.Context, req schema.RoleListRequest) (_ *schema.RoleList, err error)

ListRoles returns a list of roles matching the request criteria. It supports pagination through the OffsetLimit fields in the request.

func (*Manager) ListSchemas

func (manager *Manager) ListSchemas(ctx context.Context, req schema.SchemaListRequest) (_ *schema.SchemaList, err error)

ListSchemas returns a list of schemas across all databases matching the request criteria. It supports pagination through the OffsetLimit fields in the request. If Database is specified in the request, only schemas from that database are returned.

func (*Manager) ListSettingCategories

func (manager *Manager) ListSettingCategories(ctx context.Context, req schema.SettingCategoryListRequest) (_ *schema.SettingCategoryList, err error)

ListSettingCategories returns all distinct setting categories.

func (*Manager) ListSettings

func (manager *Manager) ListSettings(ctx context.Context, req schema.SettingListRequest) (_ *schema.SettingList, err error)

ListSettings returns all server settings, optionally filtered by category.

func (*Manager) ListStatements

func (manager *Manager) ListStatements(ctx context.Context, req schema.StatementListRequest) (*schema.StatementList, error)

ListStatements returns a list of statement statistics from pg_stat_statements. The request can filter by database, user, and order by various fields. Returns ErrNotAvailable if pg_stat_statements is not installed.

func (*Manager) ListTablespaces

func (manager *Manager) ListTablespaces(ctx context.Context, req schema.TablespaceListRequest) (_ *schema.TablespaceList, err error)

ListTablespaces returns a list of tablespaces matching the request criteria. It supports pagination through the OffsetLimit fields in the request.

func (*Manager) Ping

func (manager *Manager) Ping(ctx context.Context) (err error)

Ping the database connection - returns an error if the connection is not healthy.

func (*Manager) RegisterConnectionMetrics

func (manager *Manager) RegisterConnectionMetrics(name string) error

func (*Manager) RegisterDatabaseMetrics

func (manager *Manager) RegisterDatabaseMetrics(name string) (err error)

func (*Manager) RegisterReplicationSlotMetrics

func (manager *Manager) RegisterReplicationSlotMetrics(name string) error

func (*Manager) RegisterSchemaMetrics

func (manager *Manager) RegisterSchemaMetrics(name string) error

func (*Manager) RegisterTablespaceMetrics

func (manager *Manager) RegisterTablespaceMetrics(name string) error

func (*Manager) ReloadConfig

func (manager *Manager) ReloadConfig(ctx context.Context) (err error)

ReloadConfig calls pg_reload_conf() to reload server configuration. This applies changes to settings with 'sighup' context without requiring a restart.

func (*Manager) ResetStatements

func (manager *Manager) ResetStatements(ctx context.Context) error

ResetStatements resets the statistics for all statements. Returns ErrNotAvailable if pg_stat_statements is not installed.

func (*Manager) Run added in v1.2.1

func (manager *Manager) Run(ctx context.Context) error

Run the manager - currently this just waits for the context to be cancelled, but in the future it will run background tasks

func (*Manager) UpdateDatabase

func (manager *Manager) UpdateDatabase(ctx context.Context, name string, meta schema.DatabaseMeta) (_ *schema.Database, err error)

UpdateDatabase modifies an existing database's metadata including name, owner, and ACLs. All changes are applied within a transaction to ensure atomicity. If meta.Name is provided and differs from name, the database is renamed. ACL changes are synchronized by revoking removed privileges and granting new ones.

func (*Manager) UpdateExtension

func (manager *Manager) UpdateExtension(ctx context.Context, name string, meta schema.ExtensionMeta) (_ *schema.Extension, err error)

UpdateExtension updates an extension's version and/or schema. The Database field in meta specifies which database to update. The Version field specifies the target version (empty means latest). The Schema field specifies a new schema to move the extension to (only for relocatable extensions). Note: Name and Owner cannot be changed for extensions in PostgreSQL.

func (*Manager) UpdateRole

func (manager *Manager) UpdateRole(ctx context.Context, name string, meta schema.RoleMeta) (_ *schema.Role, err error)

UpdateRole updates an existing role with the specified metadata. If meta.Name is set and different from the current name, the role is renamed. If meta.Groups is set (even if empty), the group memberships are updated.

func (*Manager) UpdateSchema

func (manager *Manager) UpdateSchema(ctx context.Context, database, namespace string, meta schema.SchemaMeta) (_ *schema.Schema, err error)

UpdateSchema modifies an existing schema's metadata including name, owner, and ACLs. If meta.Name is provided and differs from namespace, the schema is renamed. ACL changes are synchronized by revoking removed privileges and granting new ones.

func (*Manager) UpdateSetting

func (manager *Manager) UpdateSetting(ctx context.Context, name string, meta schema.SettingMeta) (_ *schema.Setting, err error)

UpdateSetting updates a setting value. If meta.Value is nil, the setting is reset to default. Returns the updated setting. Check the Context field to determine if ReloadConfig() or a server restart is needed for the change to take effect. Returns an error for settings with 'internal' context (cannot be changed) or 'postmaster' context (requires server restart, not supported via API).

func (*Manager) UpdateTablespace

func (manager *Manager) UpdateTablespace(ctx context.Context, name string, meta schema.TablespaceMeta) (_ *schema.Tablespace, err error)

UpdateTablespace modifies an existing tablespace's metadata including name, owner, and ACLs. All changes are applied within a transaction to ensure atomicity. If meta.Name is provided and differs from name, the tablespace is renamed. ACL changes are synchronized by revoking removed privileges and granting new ones.

type Opt

type Opt func(*opts) error

Opt configures a Manager during construction.

func WithClusterName

func WithClusterName(cluster string) Opt

WithClusterName sets the name to be used as an attribute on all metrics and spans.

func WithMeter

func WithMeter(meter metric.Meter) Opt

WithMeter sets the OpenTelemetry meter used for manager metrics.

func WithTracer

func WithTracer(tracer trace.Tracer) Opt

WithTracer sets the OpenTelemetry tracer used for manager spans.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL