conninfo

A string containing database connection parameters

A conninfo string is one method of supplying PostgreSQL connection parameters to libpq and some applications based on libpq, such as psql. It consists either of parameters specified in a "keyword=value" format separated by spaces, e.g. "host=localhost dbname=testdb", or an URI-style string (as defined by RFC 3986), e.g. "postgresql://localhost/testdb".

libpq functions

libpq provides the following function for handling conninfo strings:

  • PQconninfoParse()

Change history

Examples

Connect to PostgreSQL with a conninfo string:

$ psql "host=localhost dbname=testdb"
psql (13.0)
Type "help" for help.

postgres=#

Note the string can also be provided with the -d/--dbname option, e.g.:

$ psql -d "host=localhost dbname=testdb"
psql (13.0)
Type "help" for help.

postgres=#

Categories

Database connections, PostgreSQL concept