postgresql – How do I trace Postgres Frontend and Backend messages?

As per my understanding when we execute a Command or Query. Postgres Client sends Frontend Message and in return gets the response in the Backend Message format.

How do I capture and check these messages on Linux box?

For e.g. let’s say I am executing the below command via psql client

 psql --username=foo --dbname=mydb --password=foobar

I believe the client creates StartupMessage

is there a way to trace down this interaction? considering server and client are running on the same machine.