Top
Symfoware Server V12.1.0 Application Development Guide
FUJITSU Software

11.2.5 Using the C Library (libpq)

It is recommended that you use a connection service file. Refer to "11.2.4 Using a Connection Service File" for details.

If a connection service file will not be used, set the following information for the database connection control functions (PQconnectdbParams, PQconnectdb, and so on) or environment variables.

Table 11.5 Information to be set

Parameter (environment variable name)

Explanation

host(PGHOST)

Specify the host names, using a comma as the delimiter.

hostaddr(PGHOSTADDR)

Specify IP address 1 and IP address 2, using a comma as the delimiter.

port(PGPORT)

Specify the connection destination port numbers, using a comma as the delimiter.
Specify the port number for the server specified for the nth host or hostaddr as the nth port.

The port number can be omitted. If omitted, the default is 26500.

If n server names are specified, the (n+1)th and later ports will be ignored.

target_server(PGXTARGETSERVER)

Specify the selection sequence of the servers to which the application will connect.
Refer to "Target server" for details.

sslmode(PGSSLMODE)

Specify this to encrypt communications. By default, this is disabled.
The setting values for sslmode are as follows:

disable: Connect without SSL

allow: Connect without SSL, and if it fails, connect with SSL

prefer: Connect with SSL, and if it fails, connect without SSL

require: Connect always with SSL

verify-ca: Connect with SSL, using a certificate issued by a trusted CA (*1)

verify-full: Connect with SSL, using a certificate issued by a trusted CA to verify if the server host name matches the certificate (*1)

sslservercertcn(PGXSSLSERVERCERTCN)

This parameter is enabled only to perform SSL authentication (sslmode=verify-full).

Specify the server certificate CN. If this is omitted, the value will be null, and the server certificate CN will be authenticated using the host name specified in host.

*1: If specifying either "verify-ca" or "verify-full", use the system environment variable PGSSLROOTCERT (connection parameter sslrootcert) of your operating system to specify the CA certificate file as shown below.

Example)
Variable name: PGSSLROOTCERT
Variable value: cACertificateFile


When using URI
postgresql://host1[:port1],host2[:port2][,...]/database_name
[?target_server={primary | prefer_standby}]
  • When using IPV6, specify the host in the "[host]" (with square brackets) format.

    [Example]

    postgresql://postgres@[2001:Db8::1234]:26500,192.168.1.1:26500/database_name

When using key-value
host=host1[,host2] port=port1[,port2] user=user1 password=pwd1 dbname=mydb [target_server={primary | prefer_standby}]
  • When using IPV6, specify the host in the "host" format.

    [Example]

    host=2001:Db8::1234,192.168.1.1 port=26500,26500

Note

If using the connection parameter connect_timeout, this value is applied for connections to each of the specified hosts. If both multiplexed database servers have failed, the connection will time out when a time equal to double the connect_timeout value elapses.

Information

If using a password file (.pgpass), describe the entries matching each server.

  • Example 1:

    host1:port1:dbname:user:password
    host2:port2:dbname:user:password
  • Example 2:

    *:port:dbname:user:password