Skip to content

Commit 6d16fa0

Browse files
StefanStefan
authored andcommitted
cli update
1 parent 9f7a372 commit 6d16fa0

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

articles/postgresql/flexible-server/connect-azure-cli.md

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,42 @@ This quickstart demonstrates how to connect to an Azure Database for PostgreSQL
2222

2323

2424
## 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/).
26+
- Install [Azure CLI](/cli/azure/install-azure-cli) latest version.
27+
- Log in using Azure CLI with `az login` command.
28+
- (optional) Turn on an experimental 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.
2929

3030
## Create Azure Database for PostgreSQL flexible server instance
3131

3232
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.
3333

34-
```azurecli
34+
```azurecli-interactive
3535
az postgres flexible-server create --public-access <your-ip-address>
3636
```
3737
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).
3838

3939
## View all the arguments
4040
You can view all the arguments for this command with `--help` argument.
4141

42-
```azurecli
42+
```azurecli-interactive
4343
az postgres flexible-server connect --help
4444
```
4545

4646
## Test database server connection
4747
You can test and validate the connection to the database from your development environment using the command.
4848

49-
```azurecli
50-
az postgres flexible-server connect -n <servername> -u <username> -p "<password>" -d <databasename>
49+
```azurecli-interactive
50+
az postgres flexible-server connect \
51+
-n <servername> -u <username> -p "<password>" -d <databasename>
5152
```
5253
**Example:**
53-
```azurecli
54-
az postgres flexible-server connect -n postgresdemoserver -u dbuser -p "dbpassword" -d postgres
54+
```azurecli-interactive
55+
az postgres flexible-server connect \
56+
-n postgresdemoserver -u dbuser -p "dbpassword" -d postgres
5557
```
5658
You'll see the output if the connection was successful.
5759
```output
58-
Command group 'postgres flexible-server' is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus
59-
Successfully connected to postgresdemoserver.
60-
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.
61-
Your preference of are now saved to local context. To learn more, type in `az local-context --help`
60+
Successfully connected to <servername>.
6261
```
6362

6463
If the connection failed, try these solutions:
@@ -70,14 +69,17 @@ If the connection failed, try these solutions:
7069
## Run multiple queries using interactive mode
7170
You can run multiple queries using the **interactive** mode. To enable interactive mode, run the following command
7271

73-
```azurecli
74-
az postgres flexible-server connect -n <servername> -u <username> -p "<password>" -d <databasename>
72+
```azurecli-interactive
73+
az postgres flexible-server connect \
74+
-n <servername> -u <username> -p "<password>" -d <databasename> \
75+
--interactive
7576
```
7677

7778
**Example:**
7879

79-
```azurecli
80-
az postgres flexible-server connect -n postgresdemoserver -u dbuser -p "dbpassword" -d flexibleserverdb --interactive
80+
```azurecli-interactive
81+
az postgres flexible-server connect \
82+
-n postgresdemoserver -u dbuser -p "dbpassword" -d flexibleserverdb --interactive
8183
```
8284

8385
You'll see the **psql** shell experience as shown below:
@@ -99,8 +101,10 @@ Your preference of are now saved to local context. To learn more, type in `az l
99101
```
100102

101103
**Example:**
102-
```azurecli
103-
az postgres flexible-server execute -n postgresdemoserver -u dbuser -p "dbpassword" -d flexibleserverdb -q "select * from table1;" --output table
104+
```azurecli-interactive
105+
az postgres flexible-server execute \
106+
-n postgresdemoserver -u dbuser -p "dbpassword" -d flexibleserverdb \
107+
-q "select * from table1;" --output table
104108
```
105109

106110
You'll see an output as shown below:
@@ -127,13 +131,17 @@ test 200
127131
## Run SQL File
128132
You can execute a sql file with the command using `--file-path` argument, `-f`.
129133

130-
```azurecli
131-
az postgres flexible-server execute -n <server-name> -u <username> -p "<password>" -d <database-name> --file-path "<file-path>"
134+
```azurecli-interactive
135+
az postgres flexible-server execute \
136+
-n <server-name> -u <username> -p "<password>" -d <database-name> \
137+
--file-path "<file-path>"
132138
```
133139

134140
**Example:**
135-
```azurecli
136-
az postgres flexible-server execute -n postgresdemoserver -u dbuser -p "dbpassword" -d flexibleserverdb -f "./test.sql"
141+
```azureazurecli-interactivecli
142+
az postgres flexible-server execute \
143+
-n postgresdemoserver -u dbuser -p "dbpassword" -d flexibleserverdb \
144+
-f "./test.sql"
137145
```
138146

139147
You'll see an output as shown below:

0 commit comments

Comments
 (0)