Supported Versions: Current (17) / 16 / 15 / 14 / 13
Development Versions: devel
Unsupported versions: 12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 / 8.2 / 8.1 / 8.0 / 7.4 / 7.3
This documentation is for an unsupported version of PostgreSQL.
You may want to view the same page for the current version, or one of the other supported versions listed above instead.

4.2. Connecting to the Database Server

One connects to a database using the following statement:

EXEC SQL CONNECT TO target [AS connection-name] [USER user-name];

The target can be specified in the following ways:

  • dbname[@hostname][:port]

  • tcp:postgresql://hostname[:port][/dbname][?options]

  • unix:postgresql://hostname[:port][/dbname][?options]

  • character variable

  • character string

  • DEFAULT

There are also different ways to specify the user name:

  • userid

  • userid/password

  • userid IDENTIFIED BY password

  • userid USING password

The userid and password may be a constant text, a character variable, or a character string.

The connection-name is used to handle multiple connections in one program. It can be omitted if a program uses only one connection.