Unlisten is sent to clear the connection from any previous notifications which may have been set before returning the connection to the pool.
The select Npgsql is sent to test if the connection is still valid when getting one from the pool. You can find the code here: https://github.com/npgsql/Npgsql/blob/e7913234bd1a406dc6288147fb24b52c041abd26/Npgsql/Npgsql/NpgsqlConnector.cs#L372
It used to be a simple " select 1" but we started to receive reports that the connection being returned was broken and we thought the cause was that a broken connection with a value of "1" was being put in the pool and when Npgsql read the response of the query, it was in fact reading this left value and returning a false positive. That's when we decided to use a random value for the test. But performance wise, I'm open for suggestions about any better way to make this simple validation test. Maybe use some other type of signature?
I hope it helps.