How to log connections to the database? I'm trying to write a small program that is meant to connect to a database over TCP/IP using raw sockets with Python. I can't open a connection so tried to see what's happening on PostgreSQL's side but I can't get logging to work. 

So, how can I enable connection logging? If logging is not possible how can I debug connection attempts in the database server?

Update

I tried to open a connection using netcat but it always gets closed, I still don't know why.

$ nc -vvv 127.0.0.1 5432
localhost [127.0.0.1] 5432 (postgresql) open
user=myuser
sent 17, rcvd 0
I found that I need to send the protocol version along with the user, otherwise the connection is simply dropped, as the documentation states.