With PostgreSQL, what is the difference between a session and a connection

Géry PANNEQUIN
Géry PANNEQUIN used Ask the Experts™
on
PostgreSQL world :

With pgbadger (postgres tool), some results speak about SESSIONS, others about CONNECTIONS.

With PostgreSQL, what is the difference between a session and a connection ?

Your site contains the answer for Oracle but not for Postgres...

Thanks a lot.

Gery
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
lcohanDatabase Analyst

Commented:
That is actually defined here: https://severalnines.com/blog/postgresql-log-analysis-pgbadger

Session: Total number of sessions, peak sessions time, total duration of sessions, average duration of sessions, average queries found per session, average queries duration per session.
Connections: Total number of connections, peak connections, and total number of databases connected to.

Normally there is one session on each connection, but there could be multiple session on a single connection and there are also sessions that have no connection.

The link below is an example of multiple sessions per connection provided by pgbadger:
https://www.postgresql.org/message-id/53BC1C3F.1000407@pinpointresearch.com
Géry PANNEQUINConsultant

Author

Commented:
Thanks Icohan for the text and the links.
I should be happy to have more details about :
Normally there is one session on each connection, but there could be multiple session on a single connection and there are also sessions that have no connection.
Best regards,
Gery
lcohanDatabase Analyst

Commented:
One fast example that comes to my mind is "MARS - Multiple Active Result Sets" and explanation about what they are and how they are implemented can be found here: https://github.com/npgsql/npgsql/issues/462
One reason to not do what someone suggested at above link "Why don't EF simply open another connection?" is that Postgres has usually a limited number of connections set in its config files as they tie directly to hardware resources so is not like other DB engines where new connection may not matter too much so you just through another connection at DB to do whatever work that could have been done on another connection.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial