This instruction provide steps to install and configure 64-bit ODBC driver for old version of PostgreSQL, setup a linked server connection in Microsoft SQL Server Management Studio, and run a sample SQL query. It includes downloading and installing the ODBC driver, configuring a new connection, setting advanced options, setting up the provider, creating a linked server connection, and running a SQL query to retrieve data from PostgreSQL.
Download and install psqlodbc_09_05_0400-x64.zip from PostgreSQL ODBC drivers.
-
Open ODBC Data Source Administrator (64-bit)
%windir%\system32\odbcad32.exe -
Select System DSN tab and click Add...
-
Choose PostgreSQL Unicode(x64) in Create new Data Source window
-
Enter details
- Data Source name β it will be used in SQL Server connection e.g.
POSTGRES - SSL Mode - default disabled
- Database - name of your database
- Server - ip/host address of the database
- Port - default 5432
- User Name/Password - database user credentials
π‘ Click Test and check if connection is successful. You could remove User Name and Password for now.
Click Datasource button and check if options described below are βοΈ selected.
Page 1
- Recognize Unique Indexes
- Use Declare/Fetch
- Unknowns as LongVarChar
- Max Varchar:
1024 - Max Long VarChar:
1000000
Page 2
- bytea as LO
- uncheck Server Side prepare
π Now you can close the configuration window. You will see the newly created connection (with it's name and version) on the System DSN list.
- Open Microsoft SQL Server Management Studio and connect to your SQL Server.
- Expand in Object Explorer tree: Server Objects > Linked Servers > Providers and double click on MSDASQL.
- On General page enable Level zero only provider option.
- Click OK.
- While staying in the Object Explorer, right-click on the Linked Servers and select New Linked Server.
- In General page select Microsoft OLE DB Provider for ODBC Drivers.
- Enter Linked server name (e.g. POSTGRES).
- Enter Data source which is the name of your newly created ODBC in step 2.4 (e.g. POSTGRES).
- You could write PostgreSQL as the Product name.
- Open Security page and select Be made using this security context β enter database username and password.
- Open Server Options and check if True only at Data Access, RPC, RPC Out, Use Remote Collation, Enable Promotion of Distributed Transaction.
- Click OK and close the window. Now you should be able to see new icon in Linked Server folder.
SELECT TOP 100 * FROM [POSTGRES]...[information_schema.sql_features];
I created the instruction after struggling with the "ended pipe" error.
A transport-level error has occurred when receiving results from the server. (provider: Shared Memory Provider, error: 0 - The pipe has been ended.)