Connecting to PostgreSQL
Description
Alpha Anywhere AlphaDAO includes a PostgreSQL extension driver built on a version of the PostgreSQL ODBC driver. In order to configure a PostgreSQL connection it is necessary to first do the following.
You must install the 32-bit ANSI or Unicode version of the PostgreSQL client.
When configuring data sources on 64-bit systems you must use the 32-bit version of the ODBC Data Source Administrator. This is applicable for ALL ODBC drivers we don't wrap directly.
In order to verify that the driver is properly installed (for all ODBC drivers and extension drivers - meaning everything except for Oracle, DB2, and PostgreSQL) on 64-bit systems, you must use the 32-bit version of the ODBC Data Source Administrator.
For all servers, clients must also be granted access to the server. Problems with this will be identified in trying to create a DSN using ODBC, but
In all cases, the server must open the appropriate firewall port (they vary by database see the connection string dialog for defaults and they can be overridden, which is often recommended).
For PostgreSQL, this also requires editing of the file pg_hba.conf in the server installs data directory (located under PostgreSQL - for example c:\Program Files\PostgreSQL\9.0\data on 32-bit Windows XP).
Example
To be sure that the 32-bit ANSI or Unicode driver is installed, please look at the drivers tab of the 32-bit ODBC Administrator:
Next test the PostgreSQL driver by creating and testing a DSN using the ODBC Data Source Administrator:
Follow the same steps in the Alpha Anywhere Connection String dialog:
Result:
Using the PostgreSQL Connection String Dialog
When you select PostgreSQL as your connection type in the connection string dialog, the dialog below will be displayed. Enter your host and server name and provide any authentication information required to connect to your database. The values you select will be generated into the connection string at the top of the dialog for you as you make changes. Before you begin, make sure you have installed and configured your PostgreSQL server. For more information on installing and configuring PostgreSQL, see https://www.postgresql.org/
The PostgreSQL connection string dialog has tab pages for general properties, TLS/SSL, SSH tunneling, and advanced properties. Each of the properties are described below.
The TLS/SSL tab is used to enable TLS (also called SSL) connections. These connections are encrypted between Alpha Anywhere and the database. The database presents a certificate to the client and the client verifies that it trusts the certificate. You will need to provide a certificate file with trusted certificates (and possibly the certificate being provided by the server). You can also require that the server certificate match a name, company and/or unit values that you provide.
The SSH tab is used to enable a connection to a database using an SSH2 tunnel. These connections are made from a local tunnel that is connected to a remote server and then finally to the actual database, typically behind a firewall. Alpha Anywhere will create and manage the tunnel for you based on the values you provide on this page.
The Advanced tab is used to set an initial command to be executed at connect time or to select the Unicode version of the PostgreSQL ODBC driver.
To execute one or more commands immediately after connecting to the database, enter native PostgreSQL commands separated by a semi-colon.
To load the PostgreSQL Unicode ODBC driver instead of the PostgreSQL ANSI ODBC driver, check the box entitled Load Unicode Driver.
PostgreSQL Connection String Properties
- Connection Property
- Description
- A5API
Setting the connection property A5API to 'PostgreSQL' will load the PostgreSQL driver when you open a connection.
- Server
Enter the DNS name or IP address of your server.
- Port
PostgreSQL defaults to an IP address of 2638. It is a good practice to set the server port to a different value so that it is not as obvious that PostgreSQL is being served. This is not a substitute for using secure connections.
- UserName
Set this value to the user name you wish to connect to the database with.
- Password
Set this value to the password value you wish to connect to the database with. Using the connection string dialog will obscure the password within the connection string. Publish functions encrypt the connection string.
- Database
Enter or select the name of the database you are targeting.
- A5LoginTimeout
Set this value to control the timeout for new connections in seconds. Omit this setting to use the PostgreSQL ODBC driver default value.
- A5ConnectionTimeOut
Set this value to control the timeout for the lifetime of a connection in seconds. Omit this setting to use the PostgreSQL ODBC driver default value.
- A5QueryTimeOut
Set this value to control the timeout for a single executing query in seconds. Omit this setting to use the PostgreSQL ODBC driver default value.
- A5TraceSQL
Set this value to Y to trace SQL statements. Within Alpha Anywhere messages are written to the trace pane. For Application Servers the output is written to a file. The actual location varies by server.
- A5LoadUnicodeDriver
Set this value to Y to load the PostgreSQL Unicode ODBC driver. If the setting is omitted or set to N, the PostreSQL ANSI ODBC driver is loaded.
- A5TraceSQLLevel
Set this value to determine how much detail will be written to the trace log. When set to "Errors", only errors will be reported. When set to "SQL" a summary of each statement and the results will be reported, including errors. When set to "Complete" all errors and SQL will be reported as well as key function calls and translated queries with argument markers as well as any caller context provided. When set to "Diagnostic", all of the previous output will be included along with the user thread name, the argument values and bind mappings. All other values are treated as if "SQL" was set.
- A5TraceSQLFormat
Set this value to indicate the output format desired. When set to "JSON", information will be written in JSON format with a trailing comma. Parsing a file in JSON format can be done by stripping the last trailing comma and wrapping the text in square brackets "[]". When set to "Text", the output is written as formatted text. This is the default format.
- A5UseServerSidePrepare
Set this value to Y to force statements to be prepared on the server side. This can improve performance in some cases. The default value for this parameter is 'N'.
- A5SSL
The conection string properties for TLS connections are discussed separately in Connecting Securely with TLS and SSL.
- A5SSHTunnel
The conection string properties for SSH connections are discussed separately in Connecting Securely with SSH.
- A5InitialCommand
Set this value to the semi-colon delimited list of commands you want to execute after a connection is opened.
Using Portable SQL with PostgreSQL
A PostgreSQL connection automatically selects PostgreSQL as it's syntax. The PostgreSQL syntax handler reads table information, and generates DDL (Data Definition Language) such as CREATE TABLE, DROP TABLE and DML (Data Manipulation Language) such as SELECT, INSERT, UPDATE, DELETE. It is also responsible for translating AlphaDAO Portable SQL functions into native implementations.
- The PostgreSQL syntax handler may be used with the ODBC and ADO.Net drivers as well.