Database Reference
In-Depth Information
How to do it...
You need to specify the following five parameters to connect to PostgreSQL:
F host or host address
F port
F database name
F user
F password (or other means of authentication, if any)
To connect, there must be a PostgreSQL server running on host , listening on port number
port . On that server, a database named dbname and user must also exist. The host must
explicitly allow connections from your client—this is explained in the next recipe, and you must
also pass authentication using the method the server specifies. For example, specifying a
password won't work if the server has requested a different form of authentication.
Almost all PostgreSQL interfaces use the libpq interface library. When using libpq, most
of the connection parameter handling is identical, so we can just discuss that once.
If you don't specify the preceding parameters, we look for values set through environment
variables, which are as follows:
F PGHOST or PGHOSTADDR
F PGPORT (or set to 5432 if this is not set)
F PGDATABASE
F PGUSER
F PGPASSWORD (though this one is definitely not recommended)
If you specify the first four parameters somehow, but not the password, then we look
for a password file, discussed in a later recipe.
Some PostgreSQL interfaces use the client-server protocol directly, so the way defaults are
handled may differ. The information we need to supply won't vary significantly, so please
check the exact syntax for that interface.
How it works...
The PostgreSQL server is a client-server database. The system it runs on is known as the
host. We can access the PostgreSQL server remotely through the network. However, we must
specify the host, which is a hostname, or a hostaddr, which is an IP address. We can specify
a host of "localhost" if we wish to make a TCP/IP connection to the same system. It is often
better to use a Unix socket connection, which is attempted if the host begins with a slash ( / )
and the name is presumed to be a directory name (default is /tmp ).
 
Search WWH ::




Custom Search