With the new changes to the Azure CLI, building applications has become much easier. This blog post walks you through key changes that can help enhance your productivity.
Some major changes include:
Note: Download the latest official release of the Azure CLI from the Azure CLI page or the dev build from the GitHub Azure CLI homepage.
Important: While this post focuses on Azure Database for PostgreSQL Single server, the changes described apply equally to our Flexible server deployment model.
Login to your Azure account using `az login`, select your subscription (if different from default), and then run the command `az postgres server create’ to create a Postgres Single Server Instance on Azure.
Note the following key points:
Azure Database for PostgreSQL server CLI commands now support persisting values of parameters with the `az config param-persist` command , which locally stores information such as location, resource group, administrator login and server name for every sequential CLI command you execute. You can easily turn on param persist to store information using `az config param-persist on`. With param persist turned on, you can see the contextual information using `az config param-persist show`. You can always turn off support for param persist by using `az config param-persist off`.
A summary of points that you might find helpful is listed below:
az postgres server firewall-rule create -n firewall-rule-1 --start-ip-address 107.223.9.21 --end-ip-address 107.223.9.27
Local context is turned on. Its information is saved in working directory /home/aritra. You can run `az local-context off` to turn it off.
Command argument values from local context: --resource-group: group2029187709, --server-name: server905314632
{- Finished ..
"endIpAddress": "107.223.9.27",
"id": "/subscriptions/<your-subscription-id>/resourceGroups/group2029187709/providers/Microsoft.DBforPostgreSQL/servers/server905314632/firewallRules/firewall-rule-1",
"name": "firewall-rule-1",
"resourceGroup": "group2029187709",
"startIpAddress": "107.223.9.21",
"type": "Microsoft.DBforPostgreSQL/servers/firewallRules"
}
When creating a Postgres server using our managed database service on Azure, you want to get started quickly. You can now let the create experience take care of the accessibility based on the value you pass for the --public parameter in the create command. When a server is created with any of these newly supported values, a new field `firewallName` will show up in the output of the create command. In addition to the existing values of ‘Enabled’ and ‘Disabled’, we are now supporting the below values:
Scenario | Command |
Allow all IPs from 0.0.0.0-255.255.255.255 | az postgres server create --public all |
Allow access to your client IP only | az postgres server create --public <SingleIP> |
Allow all IPs within a range | az postgres server create --public <StartIP-DestinationIP> |
Allow access to all Azure Services | az postgres server create --public 0.0.0.0 |
Allow public access, but add allowed IPs later |
az postgres server create --public Enabled. Note : You need to add allowed IPs using `firewall-rule create` command |
`az postgres server show-connection-string`: Lists the connections string for connecting your Postgres database to applications such as ADO.NET, JDBC, JDBC Spring, Node.JS, PHP, Python, and Ruby.
az postgres server show-connection-string -s server905314632 -u flexibleHorse
All placeholder fields within {} in the connection string can be substituted with actual values when you pass them as parameters in the above command.
{
"connectionStrings": {
"C++ (libpq)": "host=server905314632.postgres.database.azure.com port=5432 dbname={database} user=flexibleHorse@server905314632 password={password} sslmode=require",
"ado.net": "Server=server905314632.postgres.database.azure.com;Database={database};Port=5432;User Id=flexibleHorse@server905314632;Password={password};",
"jdbc": "jdbc:postgresql://server905314632.postgres.database.azure.com:5432/{database}?user=flexibleHorse@server905314632&password={password}",
"node.js": "var client = new pg.Client('postgres://flexibleHorse@server905314632:{password}@server905314632.postgres.database.azure.com:5432/{database}');",
"php": "host=server905314632.postgres.database.azure.com port=5432 dbname={database} user=flexibleHorse@server905314632 password={password}",
"psql_cmd": "postgresql://flexibleHorse@server905314632:{password}@server905314632.postgres.database.azure.com/{database}?sslmode=require",
"python": "cnx = psycopg2.connect(database='{database}', user='flexibleHorse@server905314632', host='server905314632.postgres.database.azure.com', password='{password}', port='5432')",
"ruby": "cnx = PG::Connection.new(:host => 'server905314632.postgres.database.azure.com', :user => 'flexibleHorse@server905314632', :dbname => '{database}', :port => '5432', :password => '{password}')"
}
}
For the commands below, the latest version of the Azure CLI supports viewing output in a tabular format, which provides you with a snapshot view.
Azure CLI has powerful utilities that can be used with PostgreSQL Server CLI commands from finding right commands, getting readable output or even running REST APIs.
--help
argument to get a complete list of commands and subgroups of a group.The improvements have been designed to support the best possible experience for developers to create and manage their PostgreSQL servers. We’d love for you to try out the improvements and share your feedback for new CLI commands or issues with existing ones.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.