From 18cd15e706ac1f2d6b1c49847a82774ca143352f Mon Sep 17 00:00:00 2001 From: Melanie Plageman Date: Wed, 12 Mar 2025 11:33:08 -0400 Subject: Add connection establishment duration logging Add log_connections option 'setup_durations' which logs durations of several key parts of connection establishment and backend setup. For an incoming connection, starting from when the postmaster gets a socket from accept() and ending when the forked child backend is first ready for query, there are multiple steps that could each take longer than expected due to external factors. This logging provides visibility into authentication and fork duration as well as the end-to-end connection establishment and backend initialization time. To make this portable, the timings captured in the postmaster (socket creation time, fork initiation time) are passed through the BackendStartupData. Author: Melanie Plageman Reviewed-by: Bertrand Drouvot Reviewed-by: Fujii Masao Reviewed-by: Daniel Gustafsson Reviewed-by: Jacob Champion Reviewed-by: Jelte Fennema-Nio Reviewed-by: Guillaume Lelarge Discussion: https://postgr.es/m/flat/CAAKRu_b_smAHK0ZjrnL5GRxnAVWujEXQWpLXYzGbmpcZd3nLYw%40mail.gmail.com --- src/test/authentication/t/001_password.pl | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/test/authentication') diff --git a/src/test/authentication/t/001_password.pl b/src/test/authentication/t/001_password.pl index e307dee5c48..8269c470b59 100644 --- a/src/test/authentication/t/001_password.pl +++ b/src/test/authentication/t/001_password.pl @@ -77,8 +77,22 @@ $node->start; # other tests are added to this file in the future $node->safe_psql('postgres', "CREATE DATABASE test_log_connections"); +my $log_connections = $node->safe_psql('test_log_connections', q(SHOW log_connections;)); +is($log_connections, 'on', qq(check log connections has expected value 'on')); + +$node->connect_ok('test_log_connections', + qq(log_connections 'on' works as expected for backwards compatibility), + log_like => [ + qr/connection received/, + qr/connection authenticated/, + qr/connection authorized: user=\S+ database=test_log_connections/, + ], + log_unlike => [ + qr/connection ready/, + ],); + $node->safe_psql('test_log_connections', - q[ALTER SYSTEM SET log_connections = receipt,authorization; + q[ALTER SYSTEM SET log_connections = receipt,authorization,setup_durations; SELECT pg_reload_conf();]); $node->connect_ok('test_log_connections', @@ -86,6 +100,7 @@ $node->connect_ok('test_log_connections', log_like => [ qr/connection received/, qr/connection authorized: user=\S+ database=test_log_connections/, + qr/connection ready/, ], log_unlike => [ qr/connection authenticated/, @@ -100,6 +115,7 @@ $node->connect_ok('test_log_connections', qr/connection received/, qr/connection authenticated/, qr/connection authorized: user=\S+ database=test_log_connections/, + qr/connection ready/, ],); # Authentication tests -- cgit v1.2.3