Skip to content

Commit bf67456

Browse files
committed
Identify if it is AlloyDB and do not check the replication stats when it's a replica (readpool) instance
1 parent 5bfa92e commit bf67456

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

input/postgres/replication.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ func GetReplication(ctx context.Context, c *Collection, db *sql.DB) (state.Postg
8080
return repl, err
8181
}
8282

83-
// Skip follower statistics on Aurora for now - there might be a benefit to support this for monitoring
83+
// Skip follower statistics on Aurora and AlloyDB for now - there might be a benefit to support this for monitoring
8484
// logical replication in the future, but it requires a bit more work since Aurora will error out
85-
// if you call pg_catalog.pg_current_wal_lsn() when wal_level is not logical.
86-
if c.PostgresVersion.IsAwsAurora {
85+
// if you call pg_catalog.pg_current_wal_lsn() when wal_level is not logical, and AlloyDB read
86+
// pool replicas will error out on replication queries.
87+
if c.PostgresVersion.IsAwsAurora || c.PostgresVersion.IsAlloyDB {
8788
return repl, nil
8889
}
8990

input/postgres/version.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ func getPostgresVersion(ctx context.Context, db *sql.DB) (version state.Postgres
3232
}
3333
version.IsAwsAurora = isAwsAurora
3434

35+
isAlloyDB, err := GetIsAlloyDB(ctx, db)
36+
if err != nil {
37+
return
38+
}
39+
version.IsAlloyDB = isAlloyDB
40+
3541
err = db.QueryRowContext(ctx, QueryMarkerSQL+"SELECT pg_catalog.count(1) = 1 FROM pg_extension WHERE extname = 'citus'").Scan(&version.IsCitus)
3642
if err != nil {
3743
return
@@ -45,3 +51,9 @@ func GetIsAwsAurora(ctx context.Context, db *sql.DB) (bool, error) {
4551
err := db.QueryRowContext(ctx, QueryMarkerSQL+"SELECT pg_catalog.count(1) = 1 FROM pg_settings WHERE name = 'rds.extensions' AND setting LIKE '%aurora_stat_utils%'").Scan(&isAurora)
4652
return isAurora, err
4753
}
54+
55+
func GetIsAlloyDB(ctx context.Context, db *sql.DB) (bool, error) {
56+
var isAlloyDB bool
57+
err := db.QueryRowContext(ctx, QueryMarkerSQL+"SELECT pg_catalog.count(1) >= 1 FROM pg_settings WHERE name LIKE 'alloydb.%'").Scan(&isAlloyDB)
58+
return isAlloyDB, err
59+
}

state/postgres_version.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type PostgresVersion struct {
2323

2424
// For collector use only, to avoid calling functions that don't work
2525
IsAwsAurora bool // Amazon Aurora
26+
IsAlloyDB bool // Google AlloyDB for PostgreSQL
2627
IsCitus bool // Citus extension (e.g. with Azure CosmosDB for PostgreSQL)
2728
IsEPAS bool // EnterpriseDB Advanced Server
2829
}

0 commit comments

Comments
 (0)