Top
Enterprise Postgres 17 SP1 Application Development Guide

4.3.3 Connection String

Specify the following connection information to connect to the database.

Server=127.0.0.1;Port=27500;Database=mydb;Username=myuser;Password=myuser01;...; 
       (1)            (2)            (3)          (4)             (5)      (6)

(1) Specify the host name or IP address of the server to be connected. This must be specified.

(2) Specify the port number for the database server. The default is "27500".

(3) Specify the database name to be connected.

(4) Specify the username that will connect with the database.

(5) Specify the password for the user that will connect to the database.

(6) Refer to the following for information on how to specify other connection information.


The table below shows keywords that are available to specify in the connection string in .NET Data Provider (Npgsql):

Note that some settings require care if using an Oracle database-compatible feature (refer to "10.2.3 Notes when Integrating with the Interface for Application Development" for details).

Basic connection

Keyword

Description

Default

Host

Specify the host name of the server to be connected. Multiple hosts may be specified. A host name must be specified.

Port

Specify the TCP port number of the server.

27500

Database

Specify the database name to connect to.

Same as Username

Username

Specify the username for the username that will connect to the database. Not required if using Integrated Security.

PGUSER

Password

Specify the password for the username that will connect to the database. Not required if using Integrated Security.

PGPASSWORD

Passfile

Specify the path of the password file (PGPASSFILE) to obtain the password.

PGPASSFILE

Security and encryption

Keyword

Description

Default

SSL Mode

Specify one of the following values to indicate whether or not to use SSL, depending on your server's support.

Disable: No SSL connection is made.

Allow: SSL connection will be made only if the server requires it.

Prefer: Make an SSL connection if possible.

Require: Perform SSL connection. It does not verify the authenticity of Connection Server at this time.

VerifyCA: Make an SSL connection. At this time, verify the authenticity of the connection server.

VerifyFull: Make an SSL connection. This time it verifies the authenticity of the Connection Server and verifies that it is the server you specified.

Prefer

SSL Certificate

Specify the location of the client certificate sent to the server.

PGSSLCERT

SSL Key

Specify the location of the client key for the client certificate sent to the server.

PGSSLKEY

SSL Password

Specify the password for the client certificate key.

Root Certificate

Specify the location of the CA certificate used to validate server certificates.

PGSSLROOTCERT

Check Certificate Revocation

Specify whether to check the certificate revocation list during authentication.

false

Integrated Security

Specify whether to log in using integrated security (GSS/SSPI).

false

Persist Security Info

Gets or sets a Boolean value that indicates whether security-sensitive information, such as passwords, should not be returned as part of a connection if it is connected or has ever been connected.

false

Kerberos Service Name

Specify the Kerberos service name used for authentication.

postgres

Include Realm

Specify the Kerberos realm used for authentication.

Include Error Detail

When enabled, database error and notification details are included in PostgresException.Detail and PostgresNotice.Detail. These can contain confidential information.

false

Log Parameters

When enabled, parameter values are logged when the command is executed.

false

Pooling

Keyword

Description

Default

Pooling

Specify whether to use connection pooling.

true

Minimum Pool Size

Minimum connection pool size.

0

Maximum Pool Size

Maximum size of the connection pool.

100

Connection Idle Lifetime

Specify the time (in seconds) to wait before disconnecting idle connections in the pool when the number of all connections exceeds the Minimum Pool Size.

300

Connection Pruning Interval

Specify the number of seconds the pool waits before attempting to prune an idle connection that has exceeded its lifetime. See Connection Idle Lifetime.

10

ConnectionLifetime

Specify the total maximum lifetime of the connection in seconds. Connections beyond this value are discarded rather than returned from the pool. This is useful in cluster configurations that force load balancing between running servers and servers that have just come online.

0 (disabled)

Timeouts and keepalive

Keyword

Description

Default

Timeout

Specify the amount of time (in seconds) to wait before terminating the attempt and generating an error during connection establishment.

15

Command Timeout

Specify how long to wait (in seconds) while executing a command before terminating the attempt and generating an error. Set to 0 for infinity.

30

Internal Command Timeout

Specify how long to wait (in seconds) before terminating the attempt and generating an error when attempting to execute an internal command. -1 uses CommandTimeout, 0 means no timeout.

-1

Cancellation Timeout

Specify the number of milliseconds to wait while trying to read a response to a cancel request for a timed-out or canceled query before terminating the attempt and generating an error. -1 skips the wait, 0 means infinite wait.

2000

Keepalive

Npgsql will send his keep-alive queries if the connection has been inactive for more than the number of seconds specified here.

0 (disabled)

Tcp Keepalive

Specify whether TCP keepalives are used by the system default if no override is specified.

false

Tcp Keepalive Time

A TCP keep-alive query is sent when the connection inactivity exceeds the number of milliseconds specified here. Use of this option is not recommended. We recommend using Keepalive. This is supported on Windows only.

0 (disabled)

Tcp Keepalive Interval

Specify the interval (in milliseconds) between successive keepalive packets sent if no acknowledgment is received. Tcp KeepAlive Time must also be non-zero. This is supported on Windows only.

TCP Keepalive Time value

Performance

Keyword

Description

Default

Max Auto Prepare

Maximum number of SQL statements that can be automatically prepared at any given time. When this number is exceeded, the last used statement is reused. A value of 0 disables autoprepare.

0

Auto Prepare Min Usages

A SQL statement is automatically prepared when its usage count exceeds the value specified here.

5

Read Buffer Size

The size of the internal buffer Npgsql uses when reading. Increasing this value may improve performance when transferring large amounts of data from the database.

8192

Write Buffer Size

Determines the size of the internal buffer Npgsql uses when writing. Increasing this value may improve performance when transferring large amounts of data to the database.

8192

Socket Receive Buffer Size

The size of the socket receive buffer.

System dependent

Socket Send Buffer Size

The size of the socket send buffer.

System dependent

No Reset On Close

When true, do not reset the connection state when the connection is returned to the pool. In some cases, this improves performance at the cost of leak conditions. Use it only if your benchmark shows performance improvements.

false

Failover and load balancing

Keyword

Description

Default

Target Session Attributes

Specifies the server type to preferentially connect to.

any: Allows any successful connection.

primary: Connect to the primary server.

standby: Connect to the standby server.

prefer-primary: Attempt to connect to the primary server first, but retry in any mode if none of the listed hosts has a primary server.

prefer-standby: Attempt to connect to the standby server first, but retry in any mode if there is no standby server on the listed host.

read-write: Connect to a server whose default transaction mode is read/write.

read-only: Connect to a server whose default transaction mode is read-only.

PGTARGETSESSIONATTRS, Any

Load Balance Hosts

Specify whether to perform load balancing among multiple hosts using the round-robin method.

false

Host Recheck Seconds

Controls how long a host's cached state is considered valid.

10

Enable Fdw Acs

Specifies whether to switch the connection destination type of the data node with on or off when using the connection routing function. This cannot be set to on when "Target Session Attributes=prefer-primary" is specified.

off

Others

Keyword

Description

Default

Options

Specify valid database connection options.

(Example: Options=-c synchronous_commit=local)

PGOPTIONS

Application Name

Specify the application name sent to the backend when opening a connection.

Enlist

Specify whether the connection should participate in transactions declared in the transaction scope.

true

Search Path

Sets the schema search path.

None

Client Encoding

Gets or sets the client_encoding parameter.

PGCLIENTENCODING

Encoding

Gets or sets the .NET encoding used to encode/decode string data in the database.

UTF8

Timezone

Gets or sets the session timezone.

PGTZ

EF Template Database

A database template that is specified when creating a database with Entity Framework.

template1

EF Admin Database

The managed database that you specify when creating and deleting databases in Entity Framework.

template1

Load Table Composites

Specify whether to load complex type definitions for tables in addition to independent complex types.

false

Array Nullability Mode

Sets how to return an array of value types when requested as an object instance. Possible values are:

Never: Always return as a non-nullable array.

Always: Always return as a nullable array.

PerInstance: The returned array is determined at runtime.

Never