-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check if Postgres database exists prior to creation #49746
base: master
Are you sure you want to change the base?
Conversation
If this change looks reasonable then I'll cut a dev build and test with that. |
How does a function that doesn't return an error prevent Teleport from starting? |
// Performs a best-effort check to see if the specified database exists. It will return 'true' if the | ||
// database is guaranteed to exist, false otherwise. An error will only be returned if it is known to | ||
// not stem from the database not existing. | ||
func CheckIfDatabaseExists(ctx context.Context, poolConfig *pgxpool.Config, log *slog.Logger) (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would unexport this until such a time that it needs to be used in other packages.
|
||
conn, err := pgx.ConnectConfig(ctx, poolConfig.ConnConfig) | ||
if err != nil { | ||
errMsg := fmt.Sprintf("Failed to verify that the %q database already exists", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and below - use structured log fields instead of sprintf.
Currently, the auth server will fail to start with postgres backend if the Teleport postgres user does not have access to the
postgres
database. This attempts to remove this hard requirement by attempting to connect to the configuration-specified database first. This validates that the database exists, negating the need to attempt to create it, which in turn removes the need forpostgres
database access.There are no tests currently covering this package, and I'm not sure how to effectively add them.
Fixes #49745
changelog: Removed the need for
postgres
database access when the required databases for the Postgres backend already exist