| 147 | } |
| 148 | |
| 149 | func (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 | |
| 167 | func (r *Remote) ChangePrivileges(info Privileges) error { |
| 168 | super := "SUPERUSER" |