MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / isDatabaseInUse

Method isDatabaseInUse

agent/utils/postgresql/client/remote.go:149–165  ·  view source on GitHub ↗
(name string, timeout uint)

Source from the content-addressed store, hash-verified

147}
148
149func (r *Remote) isDatabaseInUse(name string, timeout uint) (bool, error) {
150 ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
151 defer cancel()
152
153 var count int
154 if err := r.Client.QueryRowContext(
155 ctx,
156 "SELECT COUNT(*) FROM pg_stat_activity WHERE datname = $1 AND pid <> pg_backend_pid()",
157 name,
158 ).Scan(&count); err != nil {
159 return false, err
160 }
161 if errors.Is(ctx.Err(), context.DeadlineExceeded) {
162 return false, buserr.New("ErrExecTimeOut")
163 }
164 return count > 0, nil
165}
166
167func (r *Remote) ChangePrivileges(info Privileges) error {
168 super := "SUPERUSER"

Callers 1

DeleteMethod · 0.95

Calls 2

IsMethod · 0.80
ScanMethod · 0.65

Tested by

no test coverage detected