40
40
#include "storage/ipc.h"
41
41
#include "tcop/backend_startup.h"
42
42
#include "utils/memutils.h"
43
+ #include "utils/wait_event.h"
43
44
44
45
/*----------------------------------------------------------------
45
46
* Global authentication functions
@@ -993,6 +994,7 @@ pg_GSS_recvauth(Port *port)
993
994
elog (DEBUG4 , "processing received GSS token of length %u" ,
994
995
(unsigned int ) gbuf .length );
995
996
997
+ pgstat_report_wait_start (WAIT_EVENT_GSSAPI_ACCEPT_SEC_CONTEXT );
996
998
maj_stat = gss_accept_sec_context (& min_stat ,
997
999
& port -> gss -> ctx ,
998
1000
port -> gss -> cred ,
@@ -1004,6 +1006,7 @@ pg_GSS_recvauth(Port *port)
1004
1006
& gflags ,
1005
1007
NULL ,
1006
1008
pg_gss_accept_delegation ? & delegated_creds : NULL );
1009
+ pgstat_report_wait_end ();
1007
1010
1008
1011
/* gbuf no longer used */
1009
1012
pfree (buf .data );
@@ -1215,6 +1218,7 @@ pg_SSPI_recvauth(Port *port)
1215
1218
/*
1216
1219
* Acquire a handle to the server credentials.
1217
1220
*/
1221
+ pgstat_report_wait_start (WAIT_EVENT_SSPI_ACQUIRE_CREDENTIALS_HANDLE );
1218
1222
r = AcquireCredentialsHandle (NULL ,
1219
1223
"negotiate" ,
1220
1224
SECPKG_CRED_INBOUND ,
@@ -1224,6 +1228,8 @@ pg_SSPI_recvauth(Port *port)
1224
1228
NULL ,
1225
1229
& sspicred ,
1226
1230
& expiry );
1231
+ pgstat_report_wait_end ();
1232
+
1227
1233
if (r != SEC_E_OK )
1228
1234
pg_SSPI_error (ERROR , _ ("could not acquire SSPI credentials" ), r );
1229
1235
@@ -1289,6 +1295,7 @@ pg_SSPI_recvauth(Port *port)
1289
1295
elog (DEBUG4 , "processing received SSPI token of length %u" ,
1290
1296
(unsigned int ) buf .len );
1291
1297
1298
+ pgstat_report_wait_start (WAIT_EVENT_SSPI_ACCEPT_SECURITY_CONTEXT );
1292
1299
r = AcceptSecurityContext (& sspicred ,
1293
1300
sspictx ,
1294
1301
& inbuf ,
@@ -1298,6 +1305,7 @@ pg_SSPI_recvauth(Port *port)
1298
1305
& outbuf ,
1299
1306
& contextattr ,
1300
1307
NULL );
1308
+ pgstat_report_wait_end ();
1301
1309
1302
1310
/* input buffer no longer used */
1303
1311
pfree (buf .data );
@@ -1395,11 +1403,13 @@ pg_SSPI_recvauth(Port *port)
1395
1403
1396
1404
CloseHandle (token );
1397
1405
1406
+ pgstat_report_wait_start (WAIT_EVENT_SSPI_LOOKUP_ACCOUNT_SID );
1398
1407
if (!LookupAccountSid (NULL , tokenuser -> User .Sid , accountname , & accountnamesize ,
1399
1408
domainname , & domainnamesize , & accountnameuse ))
1400
1409
ereport (ERROR ,
1401
1410
(errmsg_internal ("could not look up account SID: error code %lu" ,
1402
1411
GetLastError ())));
1412
+ pgstat_report_wait_end ();
1403
1413
1404
1414
free (tokenuser );
1405
1415
@@ -1496,8 +1506,11 @@ pg_SSPI_make_upn(char *accountname,
1496
1506
*/
1497
1507
1498
1508
samname = psprintf ("%s\\%s" , domainname , accountname );
1509
+
1510
+ pgstat_report_wait_start (WAIT_EVENT_SSPI_TRANSLATE_NAME );
1499
1511
res = TranslateName (samname , NameSamCompatible , NameUserPrincipal ,
1500
1512
NULL , & upnamesize );
1513
+ pgstat_report_wait_end ();
1501
1514
1502
1515
if ((!res && GetLastError () != ERROR_INSUFFICIENT_BUFFER )
1503
1516
|| upnamesize == 0 )
@@ -1512,8 +1525,10 @@ pg_SSPI_make_upn(char *accountname,
1512
1525
/* upnamesize includes the terminating NUL. */
1513
1526
upname = palloc (upnamesize );
1514
1527
1528
+ pgstat_report_wait_start (WAIT_EVENT_SSPI_TRANSLATE_NAME );
1515
1529
res = TranslateName (samname , NameSamCompatible , NameUserPrincipal ,
1516
1530
upname , & upnamesize );
1531
+ pgstat_report_wait_end ();
1517
1532
1518
1533
pfree (samname );
1519
1534
if (res )
@@ -2112,7 +2127,9 @@ CheckPAMAuth(Port *port, const char *user, const char *password)
2112
2127
return STATUS_ERROR ;
2113
2128
}
2114
2129
2130
+ pgstat_report_wait_start (WAIT_EVENT_PAM_AUTHENTICATE );
2115
2131
retval = pam_authenticate (pamh , 0 );
2132
+ pgstat_report_wait_end ();
2116
2133
2117
2134
if (retval != PAM_SUCCESS )
2118
2135
{
@@ -2125,7 +2142,9 @@ CheckPAMAuth(Port *port, const char *user, const char *password)
2125
2142
return pam_no_password ? STATUS_EOF : STATUS_ERROR ;
2126
2143
}
2127
2144
2145
+ pgstat_report_wait_start (WAIT_EVENT_PAM_ACCT_MGMT );
2128
2146
retval = pam_acct_mgmt (pamh , 0 );
2147
+ pgstat_report_wait_end ();
2129
2148
2130
2149
if (retval != PAM_SUCCESS )
2131
2150
{
@@ -2265,7 +2284,11 @@ InitializeLDAPConnection(Port *port, LDAP **ldap)
2265
2284
}
2266
2285
2267
2286
/* Look up a list of LDAP server hosts and port numbers */
2268
- if (ldap_domain2hostlist (domain , & hostlist ))
2287
+ pgstat_report_wait_start (WAIT_EVENT_LDAP_HOST_LOOKUP );
2288
+ r = ldap_domain2hostlist (domain , & hostlist );
2289
+ pgstat_report_wait_end ();
2290
+
2291
+ if (r )
2269
2292
{
2270
2293
ereport (LOG ,
2271
2294
(errmsg ("LDAP authentication could not find DNS SRV records for \"%s\"" ,
@@ -2359,11 +2382,15 @@ InitializeLDAPConnection(Port *port, LDAP **ldap)
2359
2382
2360
2383
if (port -> hba -> ldaptls )
2361
2384
{
2385
+ pgstat_report_wait_start (WAIT_EVENT_LDAP_START_TLS );
2362
2386
#ifndef WIN32
2363
- if (( r = ldap_start_tls_s (* ldap , NULL , NULL )) != LDAP_SUCCESS )
2387
+ r = ldap_start_tls_s (* ldap , NULL , NULL );
2364
2388
#else
2365
- if (( r = ldap_start_tls_s (* ldap , NULL , NULL , NULL , NULL )) != LDAP_SUCCESS )
2389
+ r = ldap_start_tls_s (* ldap , NULL , NULL , NULL , NULL );
2366
2390
#endif
2391
+ pgstat_report_wait_end ();
2392
+
2393
+ if (r != LDAP_SUCCESS )
2367
2394
{
2368
2395
ereport (LOG ,
2369
2396
(errmsg ("could not start LDAP TLS session: %s" ,
@@ -2523,9 +2550,12 @@ CheckLDAPAuth(Port *port)
2523
2550
* Bind with a pre-defined username/password (if available) for
2524
2551
* searching. If none is specified, this turns into an anonymous bind.
2525
2552
*/
2553
+ pgstat_report_wait_start (WAIT_EVENT_LDAP_BIND_FOR_SEARCH );
2526
2554
r = ldap_simple_bind_s (ldap ,
2527
2555
port -> hba -> ldapbinddn ? port -> hba -> ldapbinddn : "" ,
2528
2556
port -> hba -> ldapbindpasswd ? ldap_password_hook (port -> hba -> ldapbindpasswd ) : "" );
2557
+ pgstat_report_wait_end ();
2558
+
2529
2559
if (r != LDAP_SUCCESS )
2530
2560
{
2531
2561
ereport (LOG ,
@@ -2548,13 +2578,16 @@ CheckLDAPAuth(Port *port)
2548
2578
filter = psprintf ("(uid=%s)" , port -> user_name );
2549
2579
2550
2580
search_message = NULL ;
2581
+
2582
+ pgstat_report_wait_start (WAIT_EVENT_LDAP_SEARCH );
2551
2583
r = ldap_search_s (ldap ,
2552
2584
port -> hba -> ldapbasedn ,
2553
2585
port -> hba -> ldapscope ,
2554
2586
filter ,
2555
2587
attributes ,
2556
2588
0 ,
2557
2589
& search_message );
2590
+ pgstat_report_wait_end ();
2558
2591
2559
2592
if (r != LDAP_SUCCESS )
2560
2593
{
@@ -2623,7 +2656,9 @@ CheckLDAPAuth(Port *port)
2623
2656
port -> user_name ,
2624
2657
port -> hba -> ldapsuffix ? port -> hba -> ldapsuffix : "" );
2625
2658
2659
+ pgstat_report_wait_start (WAIT_EVENT_LDAP_BIND );
2626
2660
r = ldap_simple_bind_s (ldap , fulluser , passwd );
2661
+ pgstat_report_wait_end ();
2627
2662
2628
2663
if (r != LDAP_SUCCESS )
2629
2664
{
@@ -3072,8 +3107,12 @@ PerformRadiusTransaction(const char *server, const char *secret, const char *por
3072
3107
return STATUS_ERROR ;
3073
3108
}
3074
3109
3075
- if (sendto (sock , radius_buffer , packetlength , 0 ,
3076
- serveraddrs [0 ].ai_addr , serveraddrs [0 ].ai_addrlen ) < 0 )
3110
+ pgstat_report_wait_start (WAIT_EVENT_RADIUS_SENDTO );
3111
+ r = sendto (sock , radius_buffer , packetlength , 0 ,
3112
+ serveraddrs [0 ].ai_addr , serveraddrs [0 ].ai_addrlen );
3113
+ pgstat_report_wait_end ();
3114
+
3115
+ if (r < 0 )
3077
3116
{
3078
3117
ereport (LOG ,
3079
3118
(errmsg ("could not send RADIUS packet: %m" )));
@@ -3121,7 +3160,10 @@ PerformRadiusTransaction(const char *server, const char *secret, const char *por
3121
3160
FD_ZERO (& fdset );
3122
3161
FD_SET (sock , & fdset );
3123
3162
3163
+ pgstat_report_wait_start (WAIT_EVENT_RADIUS_WAIT );
3124
3164
r = select (sock + 1 , & fdset , NULL , NULL , & timeout );
3165
+ pgstat_report_wait_end ();
3166
+
3125
3167
if (r < 0 )
3126
3168
{
3127
3169
if (errno == EINTR )
@@ -3154,8 +3196,12 @@ PerformRadiusTransaction(const char *server, const char *secret, const char *por
3154
3196
*/
3155
3197
3156
3198
addrsize = sizeof (remoteaddr );
3199
+
3200
+ pgstat_report_wait_start (WAIT_EVENT_RADIUS_RECVFROM );
3157
3201
packetlength = recvfrom (sock , receive_buffer , RADIUS_BUFFER_SIZE , 0 ,
3158
3202
(struct sockaddr * ) & remoteaddr , & addrsize );
3203
+ pgstat_report_wait_end ();
3204
+
3159
3205
if (packetlength < 0 )
3160
3206
{
3161
3207
ereport (LOG ,
0 commit comments