Skip to content

Commit

Permalink
Improved information content of error messages if the user does not h…
Browse files Browse the repository at this point in the history
…ave the necessary grants
  • Loading branch information
Mikhail Grigorev committed Apr 16, 2024
1 parent fd3bbf6 commit 64980be
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions internal/collector/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package collector

import (
"context"
"fmt"
"net"
"regexp"
"strconv"
Expand Down Expand Up @@ -82,7 +83,7 @@ func newPostgresServiceConfig(connStr string) (postgresServiceConfig, error) {
// Get Postgres block size.
err = conn.Conn().QueryRow(context.Background(), "SELECT setting FROM pg_settings WHERE name = 'block_size'").Scan(&setting)
if err != nil {
return config, err
return config, fmt.Errorf("failed to get info from pg_settings (block_size), error: %s", err)
}
bsize, err := strconv.ParseUint(setting, 10, 64)
if err != nil {
Expand All @@ -94,7 +95,7 @@ func newPostgresServiceConfig(connStr string) (postgresServiceConfig, error) {
// Get Postgres WAL segment size.
err = conn.Conn().QueryRow(context.Background(), "SELECT setting FROM pg_settings WHERE name = 'wal_segment_size'").Scan(&setting)
if err != nil {
return config, err
return config, fmt.Errorf("failed to get info from pg_settings (wal_segment_size), error: %s", err)
}
walSegSize, err := strconv.ParseUint(setting, 10, 64)
if err != nil {
Expand All @@ -106,7 +107,7 @@ func newPostgresServiceConfig(connStr string) (postgresServiceConfig, error) {
// Get Postgres server version
err = conn.Conn().QueryRow(context.Background(), "SELECT setting FROM pg_settings WHERE name = 'server_version_num'").Scan(&setting)
if err != nil {
return config, err
return config, fmt.Errorf("failed to get info from pg_settings (server_version_num), error: %s", err)
}
version, err := strconv.Atoi(setting)
if err != nil {
Expand All @@ -122,15 +123,15 @@ func newPostgresServiceConfig(connStr string) (postgresServiceConfig, error) {
// Get Postgres data directory
err = conn.Conn().QueryRow(context.Background(), "SELECT setting FROM pg_settings WHERE name = 'data_directory'").Scan(&setting)
if err != nil {
return config, err
return config, fmt.Errorf("failed to get info from pg_settings (data_directory), error: %s", err)
}

config.dataDirectory = setting

// Get setting of 'logging_collector' GUC.
err = conn.Conn().QueryRow(context.Background(), "SELECT setting FROM pg_settings WHERE name = 'logging_collector'").Scan(&setting)
if err != nil {
return config, err
return config, fmt.Errorf("failed to get info from pg_settings (logging_collector), error: %s", err)
}

if setting == "on" {
Expand Down

0 comments on commit 64980be

Please sign in to comment.