0

I have been doing some research and I am yet to see a solution regarding this question. Does anyone know if it's actually possible to create a linked server from an Azure SQL database in order to connect it to a PostgreSQL database?

I noticed the folder server objects is present in the local database, however, on Azure that folder is non-existent. Am I right to assume linked server is not supported on the Azure SQL database?

2
  • 1
    Appears to be supported only in Azure SQL Managed Instances - learn.microsoft.com/en-us/sql/relational-databases/… Commented Mar 5, 2020 at 10:15
  • I know this was long time ago, but I am trying to connect to PostgreSQL db in Azure from Azure SQL DB, but I cannot execute the CREATE EXTERNAL DATASOURCE command because the connection_options parameter is not available. Did you get this to work somehow? Commented Mar 28, 2022 at 10:58

1 Answer 1

1

Yes, you're right.

Azure SQL database(single database) doesn't support linked server. We can not create the linked server to any other Server.

enter image description here

I found an another way may can help you connect to Postgresql.

Please reference this tutorial: Connect to PostgreSQL as an External Data Source using PolyBase:

Use the CData ODBC Driver for PostgreSQL and PolyBase to create an external data source in SQL Server 2019 with access to live PostgreSQL data.

Creating a Master Encryption Key

Execute the following SQL command to create a new master key, 'ENCRYPTION,' to encrypt the credentials for the external data source.

CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'password';

Creating a Credential Database

Execute the following SQL command to create credentials for the external data source connected to PostgreSQL data.

CREATE DATABASE SCOPED CREDENTIAL postgresql_creds
WITH IDENTITY = 'username', SECRET = 'password';

Create an External Data Source for PostgreSQL

Execute the following SQL command to create an external data source for PostgreSQL with PolyBase, using the DSN and credentials configured earlier.

CREATE EXTERNAL DATA SOURCE cdata_postgresql_source
WITH ( 
  LOCATION = 'odbc://SERVERNAME[:PORT]',
  CONNECTION_OPTIONS = 'DSN=CData PostgreSQL Sys',
  -- PUSHDOWN = ON | OFF,
  CREDENTIAL = postgresql_creds
);

Create External Tables for PostgreSQL

The statement to create an external table based on a PostgreSQL Orders would look similar to the following:

CREATE EXTERNAL TABLE Orders(
  ShipName [nvarchar](255) NULL,
  ShipCity [nvarchar](255) NULL,
  ...
) WITH ( 
  LOCATION='Orders',
  DATA_SOURCE=cdata_postgresql_source
);

I couldn't test this for you because I don't have PostgreSQL.

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.