Can I connect to PostgreSQL on Azure configured with Azure Active Directory authentication in Database Toolbox R2020b?
17 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 5 Fév 2021
Réponse apportée : MathWorks Support Team
le 5 Fév 2021
Our company is running PostgreSQL on Azure and it is configured to work with Azure Active Directory authentication. Can I connect to this database from MATLAB?
Réponse acceptée
MathWorks Support Team
le 5 Fév 2021
It should be possible to work with this database in MATLAB. As documented from the Azure end:
"Azure unware" PostgreSQL clients (like the standard PostgreSQL JDBC driver, and MATLAB can work with JDBC connections) can connect to the database you just need to make sure you specify the correct username and use an Azure AD token as password. So on the MATLAB end you would then be able to use:
% Load the PostgreSQL JDBC driver
javaaddpath('c:\Downloads\postgresql-42.2.18.jar')
% Connect using:
conn = database('','myUser@myPrincipal.onmicrosoft.com@myDatabaseName.postgres.database.azure.com'...
,token,...
'org.postgresql.Driver',...
'jdbc:postgresql://myDatabaseName.postgres.database.azure.com:5432/postgres?sslmode=require');
Where:
"myUser@myPrincipal.onmicrosoft.com" is the "User Principal Name" as found in the Azure AD for the user account you want to connect with.
"myDatabaseName.postgres.database.azure.com" is the "Server name" as found in the Overview for the Azure Database for PostgreSQL server in Azure Portal.
"myDatabaseName.postgres.database.azure.com:5432" was copied from the JDBC string as shown under "Connection strings" for the Azure Database for PostgreSQL.
"postgres" is the database name where Azure has by default automatically created this postgres database. You really need to enter it here as part of the URL and so leave the first input of "database" empty.
Further, token can be obtained from the Azure console as shown in the Azure web page linked above, but it can also be obtained inside MATLAB by following the instructions in the related article:
When following that article note that:
1. You must work with a User based approach here, you cannot directly authenticate on an application level here.
2. You need to request a token for the following scope:
https://ossrdbms-aad.database.windows.net/.default
3. Make sure that the App which you configure on Azure has the correct API permissions for PostgreSQL.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Database Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!