You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/postgresql/flexible-server/connect-azure-cli.md
+86-68Lines changed: 86 additions & 68 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ description: This quickstart provides several ways to connect with Azure CLI wit
4
4
author: AlicjaKucharczyk
5
5
ms.author: alkuchar
6
6
ms.reviewer: maghan
7
-
ms.date: 04/27/2024
7
+
ms.date: 05/10/2024
8
8
ms.service: postgresql
9
9
ms.subservice: flexible-server
10
10
ms.topic: quickstart
@@ -22,127 +22,145 @@ This quickstart demonstrates how to connect to an Azure Database for PostgreSQL
22
22
23
23
24
24
## Prerequisites
25
-
- An Azure account. If you don't have one, [get a free trial](https://azure.microsoft.com/free/).
26
-
- Install [Azure CLI](/cli/azure/install-azure-cli) latest version (2.20.0 or above)
27
-
-Log in using Azure CLI with `az login` command
28
-
- Turn on parameter persistence with `az config param-persist on`. Parameter persistence will help you use local context without having to repeat numerous arguments like resource group or location.
25
+
- An Azure account with an active subscription. If you don't have one, [get a free trial](https://azure.microsoft.com/free/).
-(optional) Turn on an experimental parameter persistence with `az config param-persist on`. Parameter persistence helps you use local context without having to repeat numerous arguments like resource group or location.
29
29
30
30
## Create Azure Database for PostgreSQL flexible server instance
31
31
32
-
The first thing to create is a managed Azure Database for PostgreSQL flexible server instance. In [Azure Cloud Shell](https://shell.azure.com/), run the following script and make a note of the **server name**, **username** and **password** generated from this command.
32
+
The first thing to create is a managed Azure Database for PostgreSQL flexible server instance. In [Azure Cloud Shell](https://shell.azure.com/), run the following script and make a note of the **server name**, **username, and **password** generated from this command.
33
33
34
-
```azurecli
34
+
```azurecli-interactive
35
35
az postgres flexible-server create --public-access <your-ip-address>
36
36
```
37
37
You can provide more arguments for this command to customize it. See all arguments for [az postgres flexible-server create](/cli/azure/postgres/flexible-server#az-postgres-flexible-server-create).
38
38
39
39
## View all the arguments
40
40
You can view all the arguments for this command with `--help` argument.
41
41
42
-
```azurecli
42
+
```azurecli-interactive
43
43
az postgres flexible-server connect --help
44
44
```
45
45
46
46
## Test database server connection
47
-
You can test and validate the connection to the database from your development environment using the command.
47
+
You can test and validate the connection to the database from your development environment using the [az postgres flexible-server connect](/cli/azure/postgres/flexible-server#az-postgres-flexible-server-connect)command.
You'll see the **psql** shell experience as shown below:
85
+
You see the **psql** shell experience as shown here:
84
86
85
-
```bash
86
-
Command group 'postgres flexible-server' is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus
87
-
Password for earthyTurtle7:
88
-
Server: PostgreSQL 12.5
89
-
Version: 3.0.0
90
-
Chat: https://gitter.im/dbcli/pgcli
87
+
```output
88
+
Password for starchylapwing9:
89
+
Server: PostgreSQL 13.14
90
+
Version: 4.0.1
91
91
Home: http://pgcli.com
92
-
postgres> create database pollsdb;
93
-
CREATE DATABASE
94
-
Time: 0.308s
95
-
postgres>exit
96
-
Goodbye!
97
-
Local context is turned on. Its information is saved in working directory C:\sunitha. You can run `az local-context off` to turn it off.
98
-
Your preference of are now saved to local context. To learn more, typein`az local-context --help`
92
+
postgres> SELECT 1;
93
+
+----------+
94
+
| ?column? |
95
+
|----------|
96
+
| 1 |
97
+
+----------+
98
+
SELECT 1
99
+
Time: 0.167s
100
+
postgres>
101
+
```
102
+
103
+
## Execute single queries
104
+
You can run single queries against Postgres database using [az postgres flexible-server execute](/cli/azure/postgres/flexible-server#az-postgres-flexible-server-execute).
Command group 'postgres flexible-server' is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus
110
-
Successfully connected to postgresdemoserver.
111
-
Ran Database Query: 'select * from table1;'
122
+
Successfully connected to server372060240.
123
+
Ran Database Query: 'SELECT 1'
112
124
Retrieving first 30 rows of query output, if applicable.
113
-
Closed the connection postgresdemoserver.
114
-
Local context is turned on. Its information is saved in working directory C:\mydir. You can run `az local-context off` to turn it off.
115
-
Your preference of are now saved to local context. To learn more, type in `az local-context --help`
116
-
Txt Val
117
-
----- -----
118
-
test 200
119
-
test 200
120
-
test 200
121
-
test 200
122
-
test 200
123
-
test 200
124
-
test 200
125
+
Closed the connection to server372060240
126
+
?column?
127
+
----------
128
+
1
125
129
```
126
130
127
131
## Run SQL File
128
-
You can execute a sql file with the command using `--file-path` argument, `-f`.
132
+
You can execute a sql file with the [az postgres flexible-server execute](/cli/azure/postgres/flexible-server#az-postgres-flexible-server-execute)command using `--file-path` argument, `-f`.
0 commit comments