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
description: Use Go to create a program that connects to a database in Azure SQL Database or Azure SQL Managed Instance, and runs queries.
4
+
description: "Quickstart: Use Go to create a program that connects to a database in Azure SQL Database or Azure SQL Managed Instance, and runs queries."
In this quickstart, you'll use the Golang programming language to connect to an Azure SQL Database or a database in Azure SQL Managed Instance with the [go-mssqldb](https://github.com/microsoft/go-mssqldb) driver. The sample queries and modifies data with explicit Transact-SQL statements. [Golang](https://go.dev/) is an open-source programming language that makes it easy to build simple, reliable, and efficient software.
In this quickstart, you'll use the Golang programming language to connect to an Azure SQL database, or a database in [!INCLUDE [ssazuremi_md](../../docs/includes/ssazuremi_md.md)], with the [go-mssqldb](https://github.com/microsoft/go-mssqldb) driver. The sample queries and modifies data with explicit Transact-SQL (T-SQL) statements. [Golang](https://go.dev/) is an open-source programming language that makes it easy to build simple, reliable, and efficient software.
22
23
23
24
## Prerequisites
24
25
25
26
To complete this quickstart, you need:
26
27
27
-
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio).
28
-
- An Azure SQL Database or a database in Azure SQL Managed Instance. You can use one of these quickstarts to create a database:
28
+
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/).
29
+
- An Azure SQL database or a database in [!INCLUDE [ssazuremi_md](../../docs/includes/ssazuremi_md.md)]. You can use one of these quickstarts to create a database:
29
30
30
-
|| SQL Database | SQL Managed Instance | SQL Server on Azure VM |
|**Configure**|[Server-level IP firewall rule](firewall-create-server-level-portal-quickstart.md)|[Connectivity from a VM](../managed-instance/connect-vm-instance-configure.md)|
36
-
| **Configure** ||[Connectivity from on-premises](../managed-instance/point-to-site-p2s-configure.md) | [Connect to a SQL Server instance](../virtual-machines/windows/sql-vm-create-portal-quickstart.md)
37
-
|**Load data**|AdventureWorks loaded per quickstart|[Restore WideWorldImporters](../managed-instance/restore-sample-database-quickstart.md)|[Restore WideWorldImporters](../managed-instance/restore-sample-database-quickstart.md)|
38
-
|**Load data**||Restore or import AdventureWorks from a [BACPAC](database-import.md) file from [GitHub](https://github.com/Microsoft/sql-server-samples/tree/master/samples/databases/adventure-works)| Restore or import AdventureWorks from a [BACPAC](database-import.md) file from [GitHub](https://github.com/Microsoft/sql-server-samples/tree/master/samples/databases/adventure-works)|
39
-
40
-
> [!IMPORTANT]
41
-
> The scripts in this article are written to use the AdventureWorks database. With a SQL Managed Instance, you must either import the AdventureWorks database into an instance database or modify the scripts in this article to use the Wide World Importers database.
|**Configure**|[Server-level IP firewall rule](firewall-create-server-level-portal-quickstart.md)|[Connectivity from a VM](../managed-instance/connect-vm-instance-configure.md)|
37
+
|**Configure**||[Connectivity from on-premises](../managed-instance/point-to-site-p2s-configure.md)|[Connect to a SQL Server instance](../virtual-machines/windows/sql-vm-create-portal-quickstart.md)|
38
+
|**Load data**|[!INCLUDE [sssampledbobject-md](../../docs/includes/sssampledbobject-md.md)] loaded per quickstart |[Restore WideWorldImporters](../managed-instance/restore-sample-database-quickstart.md)|[Restore WideWorldImporters](../managed-instance/restore-sample-database-quickstart.md)|
39
+
|**Load data**|| Restore or import [!INCLUDE [sssampledbobject-md](../../docs/includes/sssampledbobject-md.md)] from a [BACPAC](database-import.md) file from [GitHub](https://github.com/Microsoft/sql-server-samples/tree/master/samples/databases/adventure-works)| Restore or import [!INCLUDE [sssampledbobject-md](../../docs/includes/sssampledbobject-md.md)] from a [BACPAC](database-import.md) file from [GitHub](https://github.com/Microsoft/sql-server-samples/tree/master/samples/databases/adventure-works)|
42
40
43
-
- Golang and related software for your operating system installed:
41
+
> [!IMPORTANT]
42
+
> The scripts in this article are written to use the [!INCLUDE [sssampledbobject-md](../../docs/includes/sssampledbobject-md.md)] database. With a SQL managed instance, you must either import the [!INCLUDE [sssampledbobject-md](../../docs/includes/sssampledbobject-md.md)] database into an instance database or modify the scripts in this article to use the Wide World Importers database.
44
43
45
-
-**macOS**: Install Homebrew and Golang. See [Step 1.2](https://www.microsoft.com/sql-server/developer-get-started/go/mac/).
46
-
-**Ubuntu**: Install Golang. See [Step 1.2](https://www.microsoft.com/sql-server/developer-get-started/go/ubuntu/).
47
-
-**Windows**: Install Golang. See [Step 1.2](https://www.microsoft.com/sql-server/developer-get-started/go/windows/).
44
+
-[Go](https://go.dev/doc/install) and related software for your operating system installed.
48
45
49
46
- The [Azure PowerShell Az module](/powershell/azure/install-azure-powershell) for your operating system installed.
50
-
47
+
51
48
## Get server connection information
52
49
53
50
Get the connection information you need to connect to the database. You'll need the fully qualified server name or host name, database name, and login information for the upcoming procedures.
54
51
55
52
1. Sign in to the [Azure portal](https://portal.azure.com/).
56
53
57
-
2. Navigate to the **SQL Databases** or **SQL Managed Instances** page.
54
+
1. Navigate to the **SQL Databases** or **SQL Managed Instances** page.
58
55
59
-
3. On the **Overview** page, review the fully qualified server name next to **Server name** for a database in Azure SQL Database or the fully qualified server name (or IP address) next to **Host** for an Azure SQL Managed Instance or SQL Server on Azure VM. To copy the server name or host name, hover over it and select the **Copy** icon.
56
+
1. On the **Overview** page, review the fully qualified server name next to **Server name** for a database in Azure SQL Database or the fully qualified server name (or IP address) next to **Host** for an Azure SQL Managed Instance or SQL Server on Azure VM. To copy the server name or host name, hover over it and select the **Copy** icon.
60
57
61
-
> [!NOTE]
58
+
> [!NOTE]
62
59
> For connection information for SQL Server on Azure VM, see [Connect to a SQL Server instance](../virtual-machines/windows/sql-vm-create-portal-quickstart.md#connect-to-sql-server).
63
60
64
61
## Create a new folder for the Golang project and dependencies
65
62
66
-
1. From the terminal, create a new project folder called **SqlServerSample**.
63
+
1. From the terminal, create a new project folder called `SqlServerSample`.
67
64
68
65
```bash
69
66
mkdir SqlServerSample
70
67
```
71
68
72
69
## Create sample data
73
70
74
-
1. In a text editor, create a file called **CreateTestData.sql** in the **SqlServerSample** folder. In the file, paste this T-SQL code, which creates a schema, table, and inserts a few rows.
71
+
1. In a text editor, create a file called `CreateTestData.sql` in the `SqlServerSample` folder. In the file, paste this T-SQL code, which creates a schema, table, and inserts a few rows.
75
72
76
73
```sql
77
74
CREATESCHEMATestSchema;
@@ -94,7 +91,7 @@ Get the connection information you need to connect to the database. You'll need
94
91
GO
95
92
```
96
93
97
-
2. At the command prompt, navigate to **SqlServerSample** and use `sqlcmd` to connect to the database and run your newly created Azure SQL script. Replace the appropriate values for your server and database.
94
+
1. At the command prompt, navigate to `SqlServerSample` and use `sqlcmd` to connect to the database and run your newly created Azure SQL script. Replace the appropriate values for your server and database.
98
95
99
96
```bash
100
97
az login
@@ -103,9 +100,9 @@ Get the connection information you need to connect to the database. You'll need
103
100
104
101
## Insert code to query the database
105
102
106
-
1. Create a file named **sample.go** in the **SqlServerSample** folder.
103
+
1. Create a file named `sample.go` in the `SqlServerSample` folder.
107
104
108
-
2. In the file, paste this code. Add the values for your server and database. This example uses the Golang [context methods](https://go.dev/pkg/context/) to make sure there's an active connection.
105
+
1. In the file, paste this code. Add the values for your server and database. This example uses the Golang [context methods](https://go.dev/pkg/context/) to make sure there's an active connection.
109
106
110
107
```go
111
108
package main
@@ -301,23 +298,23 @@ Get the connection information you need to connect to the database. You'll need
301
298
302
299
## Get Golang project dependencies and run the code
303
300
304
-
1. At the command prompt, navigate to **SqlServerSample** and install the SQL Server driver for Go by running the following commands.
301
+
1. At the command prompt, navigate to `SqlServerSample` and install the SQL Server driver for Go by running the following commands.
305
302
306
303
```bash
307
304
go mod init SqlServerSample
308
305
go mod tidy
309
306
```
310
307
311
-
2. At the command prompt, run the following command.
308
+
1. At the command prompt, run the following command.
Copy file name to clipboardExpand all lines: azure-sql/database/geo-distributed-application-configure-tutorial.md
-2Lines changed: 0 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,8 +44,6 @@ To complete the tutorial, make sure you've installed the following items:
44
44
> [!NOTE]
45
45
> The tutorial uses the *AdventureWorksLT* sample database.
46
46
47
-
- Java and Maven, see [Build an app using SQL Server](https://www.microsoft.com/sql-server/developer-get-started/), highlight **Java** and select your environment, then follow the steps.
48
-
49
47
> [!IMPORTANT]
50
48
> Be sure to set up firewall rules to use the public IP address of the computer on which you're performing the steps in this tutorial. Database-level firewall rules will replicate automatically to the secondary server.
Copy file name to clipboardExpand all lines: azure-sql/database/resource-limits-logical-server.md
+10-4Lines changed: 10 additions & 4 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 article provides an overview of resource management in Azure S
4
4
author: dimitri-furman
5
5
ms.author: dfurman
6
6
ms.reviewer: wiassaf, mathoma, randolphwest
7
-
ms.date: 08/30/2023
7
+
ms.date: 09/12/2023
8
8
ms.service: sql-database
9
9
ms.subservice: service-overview
10
10
ms.topic: reference
@@ -146,7 +146,7 @@ If you get out-of-memory errors, mitigation options include:
146
146
147
147
## Resource consumption by user workloads and internal processes
148
148
149
-
Azure SQL Database requires compute resources to implement core service features such as high availability and disaster recovery, database backup and restore, monitoring, Query Store, Automatic tuning, etc. The system sets aside a certain limited portion of the overall resources for these internal processes using [resource governance](#resource-governance) mechanisms, making the remainder of resources available for user workloads. When internal processes aren't using compute resources, the system makes them available to user workloads.
149
+
Azure SQL Database requires compute resources to implement core service features such as high availability and disaster recovery, database backup and restore, monitoring, Query Store, Automatic tuning, etc. The system sets aside a limited portion of the overall resources for these internal processes using [resource governance](#resource-governance) mechanisms, making the remainder of resources available for user workloads. At times when internal processes aren't using compute resources, the system makes them available to user workloads.
150
150
151
151
Total CPU and memory consumption by user workloads and internal processes is reported in the [sys.dm_db_resource_stats](/sql/relational-databases/system-dynamic-management-views/sys-dm-db-resource-stats-azure-sql-database) and [sys.resource_stats](/sql/relational-databases/system-catalog-views/sys-resource-stats-azure-sql-database) views, in `avg_instance_cpu_percent` and `avg_instance_memory_percent` columns. This data is also reported via the `sql_instance_cpu_percent` and `sql_instance_memory_percent` Azure Monitor metrics, for [single databases](/azure/azure-monitor/essentials/metrics-supported#microsoftsqlserversdatabases) and [elastic pools](/azure/azure-monitor/essentials/metrics-supported#microsoftsqlserverselasticpools) at the pool level.
152
152
@@ -160,9 +160,15 @@ A more detailed breakdown of recent resource consumption by user workloads and i
160
160
> [!TIP]
161
161
> When monitoring or troubleshooting workload performance, it's important to consider both **user CPU consumption** (`avg_cpu_percent`, `cpu_percent`), and **total CPU consumption** by user workloads and internal processes (`avg_instance_cpu_percent`,`sql_instance_cpu_percent`). Performance may be noticeably impacted if *either* of these metrics is in the 70-100% range.
162
162
163
-
**User CPU consumption** is calculated as a percentage of the user workload limits in each service objective. **User CPU utilization**in the 70-100% range indicates that the user workload is reaching the limit of the service objective. However, when **total CPU consumption** reaches the 70-100% range, it's possible to see user workload throughput flattening out and query latency increasing, even if reported **user CPU consumption** remains significantly below 100%. This is more likely to occur when using smaller service objectives with a moderate allocation of compute resources, but relatively intense user workloads, such as in [dense elastic pools](elastic-pool-resource-management.md). This can also occur with smaller service objectives when internal processes temporarily require more resources, for example when creating a new replica of the database, or backing up the database.
163
+
**User CPU consumption** is defined as a percentage toward the user workload CPU limit in each service objective. Likewise, **total CPU consumption**is defined as a percentage toward the CPU limit for all workloads. Because the two limits are different, the user and total CPU consumption are measured on different scales, and are not directly comparable with each other.
164
164
165
-
When **total CPU consumption** is high, mitigation options are the same as noted in the [Compute CPU](#compute-cpu) section, and include service objective increase and/or user workload optimization.
165
+
When either **user CPU utilization** or **total CPU consumption** is the 70-100% range, a service objective limit is being reached.
166
+
167
+
When **total CPU consumption** reaches the 70-100% range, it's possible to see user workload throughput flattening and query latency increasing, even if **user CPU consumption** remains significantly below 100%. This is more likely to occur when using smaller service objectives with a moderate allocation of compute resources, but relatively intense user workloads, such as in [dense elastic pools](elastic-pool-resource-management.md). This can also occur with smaller service objectives when internal processes temporarily require additional resources, for example when creating a new replica of the database, or backing up the database.
168
+
169
+
Likewise, when **user CPU consumption** reaches the 70-100% range, user workload throughput will flatten and query latency will increase, even though **total CPU consumption** may be well below its limit.
170
+
171
+
When either **user CPU consumption** or **total CPU consumption** is high, mitigation options are the same as noted in the [Compute CPU](#compute-cpu) section, and include service objective increase and/or user workload optimization.
166
172
167
173
> [!NOTE]
168
174
> Even on a completely idle database or elastic pool, **total CPU consumption** is never at zero because of background database engine activities. It can fluctuate in a wide range depending on the specific background activities, compute size, and previous user workload.
0 commit comments