diff --git a/internal/postgres/users.go b/internal/postgres/users.go index 7e6367b2f3..1c0a52d4d1 100644 --- a/internal/postgres/users.go +++ b/internal/postgres/users.go @@ -25,6 +25,11 @@ var RESERVED_SCHEMA_NAMES = map[string]bool{ "public": true, // This is here for documentation; Postgres will reject a role named `public` as reserved "pgbouncer": true, "monitor": true, + + // A "postgres" schema precedes "public" in the default search_path and + // would capture objects the superuser creates for "public", such as the + // "pg_stat_statements" view used by pgMonitor. + "postgres": true, } func sanitizeAlterRoleOptions(options string) string { diff --git a/internal/postgres/users_test.go b/internal/postgres/users_test.go index 4e68985063..265d02ff3e 100644 --- a/internal/postgres/users_test.go +++ b/internal/postgres/users_test.go @@ -226,10 +226,15 @@ func TestWriteUsersSchemasInPostgreSQL(t *testing.T) { Name: "public", Databases: []string{"db3"}, }, + { + Name: "postgres", + Databases: []string{"postgres"}, + }, }, )) - // The spec.users has four elements, but two will be skipped: + // The spec.users has five elements, but three will be skipped: // * the user with the reserved name `public` + // * the user with the reserved name `postgres` // * the user with 0 databases assert.Equal(t, calls, 2) })