Client - ClientRead
The ClientRead
event occurs when PostgreSQL is waiting to receive data from the client.
An PostgreSQL database instance is waiting to receive data from the client. The PostgreSQL database instance must receive the data from the client before it can send more data to the client. The time that the cluster waits before receiving data from the client is a ClientRead
event.
Common causes for the ClientRead
event to appear in top waits include the following:
-
Increased network latency
There might be increased network latency between the PostgreSQL database instance and client. Higher network latency increases the time required for database instance to receive data from the client.
-
Increased load on the client
There might be CPU pressure or network saturation on the client. An increase in load on the client can delay transmission of data from the client to the PostgreSQL database instance.
-
Excessive network round trips
A large number of network round trips between the PostgreSQL database instance and the client can delay transmission of data from the client to the PostgreSQL database instance.
-
Large copy operation
During a copy operation, the data is transferred from the client’s file system to the PostgreSQL database instance. Sending a large amount of data to the database instance can delay transmission of data from the client to the database instance.
-
Idle client connection
When a client connects to the PostgreSQL database instance in an
idle in transaction
state, the database instance might wait for the client to send more data or issue a command. A connection in this state can lead to an increase inClientRead
events. -
PgBouncer used for connection pooling
PgBouncer has a low-level network configuration setting called
pkt_buf
, which is set to 4,096 by default. If the workload is sending query packets larger than 4,096 bytes through PgBouncer, we recommend increasing thepkt_buf
setting to 8,192. If the new setting doesn’t decrease the number ofClientRead
events, we recommend increasing thepkt_buf
setting to larger values, such as 16,384 or 32,768. If the query text is large, the larger setting can be particularly helpful.
We recommend different actions depending on the causes of your wait event.
Check whether you have an increasing number of idle in transaction
connections. To do this, monitor the state
column in the pg_stat_activity
table. You might be able to identify the connection source by running a query similar to the following.
select client_addr, state, count(1) from pg_stat_activity
where state like 'idle in transaction%'
group by 1,2
order by 3 desc