Use the CONNECT statement shown below to create a connection to the database server.
Format
EXEC SQL CONNECT TO target [AS connection-name] [USER user-name]END-EXEC.
Write in one of the following formats:
dbname@host:port
tcp:postgresql://host:port/dbname[?options]
unix:postgresql://host[:port][/dbname][?options]
(Definition method when using the UNIX domain socket)
SQL string literal containing one of the above formats
Reference to a character variable containing one of the above formats
DEFAULT
Write in one of the following formats:
username
username/password
username IDENTIFIED BY password
username USING password
Description of the arguments
Argument | Description |
---|---|
dbname | Specify the database name. |
host | Specify the host name for the connection destination. |
port | Specify the port number for the database server. The default is "26500". |
connection-name | Specify connection names to identify connections when multiple connections are to be processed within a single program. |
username | Specify the user that will connect with the database. If this is omitted, the name used will be that of the user on the operating system that is executing the application. |
password | Specify a password when authentication is required. |
options | Specify the following parameter when specifying a time for timeout. Connect parameters with & when specifying more than one. The following shows the values specified for each parameter.
|
Code examples for applications
EXEC SQL CONNECT TO tcp:postgresql://sv1:26500/mydb?connect_timeout=20&keepalives_idle=20&keepalives_interval=5&keepalives_count=2&keepalives=1 USER myuser/myuser01 END-EXEC.