TCP/IP Sockets, UNIX Sockets

Started by Daniel Åkerudalmost 25 years ago4 messagesgeneral
Jump to latest
#1Daniel Åkerud
zilch@home.se

How do you force pgsql to use either TCP/IP Sockets or UNIX Sockets?
And how do you know which one it uses?

It is for a performance analysis.

Thanks!

Daniel Åkerud

#2Peter Eisentraut
peter_e@gmx.net
In reply to: Daniel Åkerud (#1)
Re: TCP/IP Sockets, UNIX Sockets

Daniel �kerud writes:

How do you force pgsql to use either TCP/IP Sockets or UNIX Sockets?

This depends greatly on what exactly "pgsql" stands for. In the server
you can turn off the TCP/IP socket, so no client can use it. In the
client library you just connect() to whatever socket you want. The
existing clients should have a function or an option to decide. For
example in psql you use -h 'hostname' for TCP/IP, or -h '' for unix
domain.

And how do you know which one it uses?

You follow the documentation of the interface you use and trust it's doing
the right thing. When in doubt use netstat or something similar.

--
Peter Eisentraut peter_e@gmx.net http://funkturm.homeip.net/~peter

#3Daniel Åkerud
zilch@home.se
In reply to: Peter Eisentraut (#2)
Re: TCP/IP Sockets, UNIX Sockets

Well,
oops

What I means was, using the C API for PostgreSQL, how can I choose whether I
want to use UNIX Sockets or regular TCP/IP Socktets? On MySQL I write either
127.0.0.1 for TCP/IP or "localhost" for UNIX Sockets.

Daniel �kerud

Show quoted text

Daniel �kerud writes:

How do you force pgsql to use either TCP/IP Sockets or UNIX Sockets?

This depends greatly on what exactly "pgsql" stands for. In the server
you can turn off the TCP/IP socket, so no client can use it. In the
client library you just connect() to whatever socket you want. The
existing clients should have a function or an option to decide. For
example in psql you use -h 'hostname' for TCP/IP, or -h '' for unix
domain.

And how do you know which one it uses?

You follow the documentation of the interface you use and trust it's doing
the right thing. When in doubt use netstat or something similar.

--
Peter Eisentraut peter_e@gmx.net http://funkturm.homeip.net/~peter

#4Peter Eisentraut
peter_e@gmx.net
In reply to: Daniel Åkerud (#3)
Re: TCP/IP Sockets, UNIX Sockets

Daniel �kerud writes:

What I means was, using the C API for PostgreSQL, how can I choose whether I
want to use UNIX Sockets or regular TCP/IP Socktets? On MySQL I write either
127.0.0.1 for TCP/IP or "localhost" for UNIX Sockets.

Please peruse the description at
http://www.de.postgresql.org/devel-corner/docs/postgres/libpq.html#LIBPQ-CONNECT.

In particular look for the "host" parameter. If it's empty or starts with
a slash, then it's a unix domain socket, otherwise it's TCP/IP. (Note
that "localhost" is TCP/IP in libpq.)

--
Peter Eisentraut peter_e@gmx.net http://funkturm.homeip.net/~peter