diff --git a/src/Testcontainers.PostgreSql/PostgreSqlBuilder.cs b/src/Testcontainers.PostgreSql/PostgreSqlBuilder.cs
index fc7e5be11..5dd387c3e 100644
--- a/src/Testcontainers.PostgreSql/PostgreSqlBuilder.cs
+++ b/src/Testcontainers.PostgreSql/PostgreSqlBuilder.cs
@@ -123,18 +123,10 @@ protected override PostgreSqlBuilder Merge(PostgreSqlConfiguration oldValue, Pos
///
private sealed class WaitUntil : IWaitUntil
{
- private static readonly string[] LineEndings = { "\r\n", "\n" };
-
///
- public async Task UntilAsync(IContainer container)
+ public Task UntilAsync(IContainer container)
{
- var (stdout, stderr) = await container.GetLogsAsync(timestampsEnabled: false)
- .ConfigureAwait(false);
-
- return 2.Equals(Array.Empty()
- .Concat(stdout.Split(LineEndings, StringSplitOptions.RemoveEmptyEntries))
- .Concat(stderr.Split(LineEndings, StringSplitOptions.RemoveEmptyEntries))
- .Count(line => line.Contains("database system is ready to accept connections")));
+ return ((PostgreSqlContainer)container).IsReadyAsync();
}
}
}
\ No newline at end of file
diff --git a/src/Testcontainers.PostgreSql/PostgreSqlContainer.cs b/src/Testcontainers.PostgreSql/PostgreSqlContainer.cs
index c771e6f11..8922bb58d 100644
--- a/src/Testcontainers.PostgreSql/PostgreSqlContainer.cs
+++ b/src/Testcontainers.PostgreSql/PostgreSqlContainer.cs
@@ -48,4 +48,19 @@ await CopyAsync(Encoding.Default.GetBytes(scriptContent), scriptFilePath, Unix.F
return await ExecAsync(new[] { "psql", "--username", _configuration.Username, "--dbname", _configuration.Database, "--file", scriptFilePath }, ct)
.ConfigureAwait(false);
}
+
+ ///
+ /// Test whether the database is ready to accept connections or not with the pg_isready command.
+ ///
+ /// if the database is ready to accept connections; if the database is not yet ready.
+ internal async Task IsReadyAsync()
+ {
+ var command = new[] {
+ "pg_isready",
+ "--dbname", _configuration.Database,
+ "--username", _configuration.Username,
+ };
+ var result = await ExecAsync(command);
+ return result.ExitCode == 0;
+ }
}
\ No newline at end of file