Skip to content

Commit 9ca61e8

Browse files
authored
Merge pull request #88860 from rachel-msft/auditedits1
Auditedits1
2 parents 7e11fba + 84f56ce commit 9ca61e8

File tree

4 files changed

+110
-4
lines changed

4 files changed

+110
-4
lines changed

articles/postgresql/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@
104104
href: concepts-monitoring.md
105105
- name: Server logs
106106
href: concepts-server-logs.md
107+
- name: Audit logs
108+
href: concepts-audit.md
107109
- name: Query Store
108110
items:
109111
- name: Query Store

articles/postgresql/concepts-audit.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
title: Audit logging using pgAudit in Azure Database for PostgreSQL - Single Server
3+
description: Concepts for pgAudit audit logging in Azure Database for PostgreSQL - Single Server.
4+
author: rachel-msft
5+
ms.author: raagyema
6+
ms.service: postgresql
7+
ms.topic: conceptual
8+
ms.date: 09/18/2019
9+
---
10+
11+
# Audit logging in Azure Database for PostgreSQL - Single Server
12+
13+
Audit logging of database activities in Azure Database for PostgreSQL - Single Server is available through the PostgreSQL Audit Extension: [pgAudit](https://www.pgaudit.org/). pgAudit provides detailed session and/or object audit logging.
14+
15+
> [!NOTE]
16+
> pgAudit can be enabled on General Purpose and Memory Optimized servers only.
17+
18+
## Usage considerations
19+
By default, pgAudit log statements are emitted along with your regular log statements by using Postgres's standard logging facility. In Azure Database for PostgreSQL, these .log files can be downloaded through the Azure portal or the CLI. The maximum storage for the collection of files is 1 GB, and each file is available for a maximum of seven days (the default is three days). This service is a short-term storage option.
20+
21+
Alternatively, you can configure all logs to be emitted to Azure Monitor's diagnostic log service. If you enable Azure Monitor diagnostic logging, your logs will be automatically sent (in JSON format) to Azure Storage, Event Hubs, and/or Azure Monitor logs, depending on your choice.
22+
23+
Enabling pgAudit generates a large volume of logging on a server, which has an impact on performance and log storage. We recommend that you use the Azure diagnostic log service, which offers longer-term storage options, as well as analysis and alerting features. We recommend that you turn off standard logging to reduce the performance impact of additional logging:
24+
25+
1. Set the parameter `logging_collector` to OFF.
26+
2. Restart the server to apply this change.
27+
28+
To learn how to set up logging to Azure Storage, Event Hubs, or Azure Monitor logs, visit the diagnostic logs section of the [server logs article](concepts-server-logs.md).
29+
30+
## Installing pgAudit
31+
32+
To install pgAudit, you need to include it in the server's shared preload libraries. A change to Postgres's `shared_preload_libraries` parameter requires a server restart to take effect. You can change parameters using the [Azure portal](howto-configure-server-parameters-using-portal.md), [Azure CLI](howto-configure-server-parameters-using-cli.md), or [REST API](/rest/api/postgresql/configurations/createorupdate).
33+
34+
Using the [Azure portal](https://portal.azure.com):
35+
36+
1. Select your Azure Database for PostgreSQL server.
37+
2. On the sidebar, select **Server Parameters**.
38+
3. Search for the `shared_preload_libraries` parameter.
39+
4. Select **pgaudit**.
40+
5. Restart the server to apply the change.
41+
42+
6. Connect to your server using a client (like psql) and enable the pgAudit extension
43+
```SQL
44+
CREATE EXTENSION pgaudit;
45+
```
46+
47+
> [!TIP]
48+
> If you see an error, confirm that you restarted your server after saving `shared_preload_libraries`.
49+
50+
## pgAudit settings
51+
52+
pgAudit allows you to configure session or object audit logging. [Session audit logging](https://github.com/pgaudit/pgaudit/blob/master/README.md#session-audit-logging) emits detailed logs of executed statements. [Object audit logging](https://github.com/pgaudit/pgaudit/blob/master/README.md#object-audit-logging) is audit scoped to specific relations. You can choose to set up one or both types of logging.
53+
54+
> [!NOTE]
55+
> pgAudit settings are specified gloabally and cannot be specified at a database or role level.
56+
57+
Once you have [installed pgAudit](#installing-pgaudit), you can configure its parameters to start logging. The [pgAudit documentation](https://github.com/pgaudit/pgaudit/blob/master/README.md#settings) provides the definition of each parameter. Test the parameters first and confirm that you are getting the expected behavior.
58+
59+
> [!NOTE]
60+
> Setting `pgaudit.log_client` to ON will redirect logs to a client process (like psql) instead of being written to file. This setting should generally be left disabled.
61+
62+
> [!NOTE]
63+
> `pgaudit.log_level` is only enabled when `pgaudit.log_client` is on. Also, in the Azure portal, there is currently a bug with `pgaudit.log_level`: a combo box is shown, implying that multiple levels can be selected. However, only one level should be selected.
64+
65+
> [!NOTE]
66+
> In Azure Database for PostgreSQL, `pgaudit.log` cannot be set using a `-` (minus) sign shortcut as described in the pgAudit documentation. All required statement classes (READ, WRITE etc) should be individually specified.
67+
68+
### Audit log format
69+
Each audit entry is indicated by `AUDIT:` near the beginning of the log line. The format of the rest of the entry is detailed in the [pgAudit documentation](https://github.com/pgaudit/pgaudit/blob/master/README.md#format).
70+
71+
If you need any other fields to satisfy your audit requirements, use the Postgres parameter `log_line_prefix`. `log_line_prefix` is a string that is output at the beginning of every Postgres log line. For example, the following `log_line_prefix` setting provides timestamp, username, database name, and process ID:
72+
73+
```
74+
t=%m u=%u db=%d pid=[%p]:
75+
```
76+
77+
To learn more about `log_line_prefix`, visit the [PostgreSQL documentation](https://www.postgresql.org/docs/current/runtime-config-logging.html#GUC-LOG-LINE-PREFIX).
78+
79+
### Getting started
80+
To quickly get started, set `pgaudit.log` to `WRITE`, and open your logs to review the output.
81+
82+
83+
## Next steps
84+
- [Learn about logging in Azure Database for PostgreSQL](concepts-server-logs.md)
85+
- Learn how to set parameters using the [Azure portal](howto-configure-server-parameters-using-portal.md), [Azure CLI](howto-configure-server-parameters-using-cli.md), or [REST API](/rest/api/postgresql/configurations/createorupdate).

articles/postgresql/concepts-extensions.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: rachel-msft
55
ms.author: raagyema
66
ms.service: postgresql
77
ms.topic: conceptual
8-
ms.date: 08/23/2019
8+
ms.date: 09/10/2019
99
---
1010
# PostgreSQL extensions in Azure Database for PostgreSQL - Single Server
1111
PostgreSQL provides the ability to extend the functionality of your database using extensions. Extensions bundle multiple related SQL objects together in a single package that can be loaded or removed from your database with a single command. After being loaded in the database, extensions function like built-in features.
@@ -38,6 +38,7 @@ The following extensions are available in Azure Database for PostgreSQL servers
3838
> |[isn](https://www.postgresql.org/docs/11/isn.html) | 1.2 | data types for international product numbering standards|
3939
> |[ltree](https://www.postgresql.org/docs/11/ltree.html) | 1.1 | data type for hierarchical tree-like structures|
4040
> |[orafce](https://github.com/orafce/orafce) | 3.7 | Functions and operators that emulate a subset of functions and packages from commercial RDBMS|
41+
> |[pgaudit](https://www.pgaudit.org/) | 1.3 | provides auditing functionality|
4142
> |[pgcrypto](https://www.postgresql.org/docs/11/pgcrypto.html) | 1.3 | cryptographic functions|
4243
> |[pgrouting](https://pgrouting.org/) | 2.6.2 | pgRouting Extension|
4344
> |[pgrowlocks](https://www.postgresql.org/docs/11/pgrowlocks.html) | 1.2 | show row-level locking information|
@@ -82,6 +83,7 @@ The following extensions are available in Azure Database for PostgreSQL servers
8283
> |[isn](https://www.postgresql.org/docs/10/isn.html) | 1.1 | data types for international product numbering standards|
8384
> |[ltree](https://www.postgresql.org/docs/10/ltree.html) | 1.1 | data type for hierarchical tree-like structures|
8485
> |[orafce](https://github.com/orafce/orafce) | 3.7 | Functions and operators that emulate a subset of functions and packages from commercial RDBMS|
86+
> |[pgaudit](https://www.pgaudit.org/) | 1.3 | provides auditing functionality|
8587
> |[pgcrypto](https://www.postgresql.org/docs/10/pgcrypto.html) | 1.3 | cryptographic functions|
8688
> |[pgrouting](https://pgrouting.org/) | 2.5.2 | pgRouting Extension|
8789
> |[pgrowlocks](https://www.postgresql.org/docs/10/pgrowlocks.html) | 1.2 | show row-level locking information|
@@ -127,6 +129,7 @@ The following extensions are available in Azure Database for PostgreSQL servers
127129
> |[isn](https://www.postgresql.org/docs/9.6/isn.html) | 1.1 | data types for international product numbering standards|
128130
> |[ltree](https://www.postgresql.org/docs/9.6/ltree.html) | 1.1 | data type for hierarchical tree-like structures|
129131
> |[orafce](https://github.com/orafce/orafce) | 3.7 | Functions and operators that emulate a subset of functions and packages from commercial RDBMS|
132+
> |[pgaudit](https://www.pgaudit.org/) | 1.3 | provides auditing functionality|
130133
> |[pgcrypto](https://www.postgresql.org/docs/9.6/pgcrypto.html) | 1.3 | cryptographic functions|
131134
> |[pgrouting](https://pgrouting.org/) | 2.3.2 | pgRouting Extension|
132135
> |[pgrowlocks](https://www.postgresql.org/docs/9.6/pgrowlocks.html) | 1.2 | show row-level locking information|
@@ -172,6 +175,7 @@ The following extensions are available in Azure Database for PostgreSQL servers
172175
> |[isn](https://www.postgresql.org/docs/9.5/isn.html) | 1.0 | data types for international product numbering standards|
173176
> |[ltree](https://www.postgresql.org/docs/9.5/ltree.html) | 1.0 | data type for hierarchical tree-like structures|
174177
> |[orafce](https://github.com/orafce/orafce) | 3.7 | Functions and operators that emulate a subset of functions and packages from commercial RDBMS|
178+
> |[pgaudit](https://www.pgaudit.org/) | 1.3 | provides auditing functionality|
175179
> |[pgcrypto](https://www.postgresql.org/docs/9.5/pgcrypto.html) | 1.2 | cryptographic functions|
176180
> |[pgrouting](https://pgrouting.org/) | 2.3.0 | pgRouting Extension|
177181
> |[pgrowlocks](https://www.postgresql.org/docs/9.5/pgrowlocks.html) | 1.1 | show row-level locking information|
@@ -207,6 +211,9 @@ Currently, outbound connections from Azure Database for PostgreSQL are not suppo
207211
If you are planning to use `uuid_generate_v4()` from the uuid-ossp extension, consider comparing with `gen_random_uuid()` from the pgcrypto extension for performance benefits.
208212

209213

214+
## pgAudit
215+
The pgAudit extension provides session and object audit logging. To learn how to use this extension in Azure Database for PostgreSQL, visit the [auditing concepts article](concepts-audit.md).
216+
210217
## TimescaleDB
211218
TimescaleDB is a time-series database that is packaged as an extension for PostgreSQL. TimescaleDB provides time-oriented analytical functions, optimizations, and scales Postgres for time-series workloads.
212219

articles/postgresql/concepts-server-logs.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: rachel-msft
55
ms.author: raagyema
66
ms.service: postgresql
77
ms.topic: conceptual
8-
ms.date: 5/6/2019
8+
ms.date: 09/18/2019
99
---
1010
# Server logs in Azure Database for PostgreSQL - Single Server
1111
Azure Database for PostgreSQL generates query and error logs. Query and error logs can be used to identify, troubleshoot, and repair configuration errors and suboptimal performance. (Access to transaction logs is not included).
@@ -22,12 +22,21 @@ If you've enabled logs, you can access them from the Azure Database for PostgreS
2222

2323

2424
## Diagnostic logs
25-
Azure Database for PostgreSQL is integrated with Azure Monitor Diagnostic Logs. Once you have enabled logs on your PostgreSQL server, you can choose to have them emitted to [Azure Monitor logs](../azure-monitor/log-query/log-query-overview.md), Event Hubs, or Azure Storage. To learn more about how to enable diagnostic logs, see the how-to section of the [diagnostic logs documentation](../azure-monitor/platform/diagnostic-logs-overview.md).
25+
Azure Database for PostgreSQL is integrated with Azure Monitor Diagnostic Logs. Once you have enabled logs on your PostgreSQL server, you can choose to have them emitted to [Azure Monitor logs](../azure-monitor/log-query/log-query-overview.md), Event Hubs, or Azure Storage.
2626

2727
> [!IMPORTANT]
2828
> This diagnostic feature for server logs is only available in the General Purpose and Memory Optimized [pricing tiers](concepts-pricing-tiers.md).
2929
30-
The following table describes what's in each log. Depending on the output endpoint you choose, the fields included and the order in which they appear may vary.
30+
To enable Diagnostic logs using the Azure portal:
31+
32+
1. In the portal, go to *Diagnostic Settings* in the navigation menu of your Postgres server.
33+
2. Select *Add Diagnostic Setting*.
34+
3. Name this setting.
35+
4. Select your preferred downstream location (storage account, event hub, log analytics).
36+
5. Select the data types you want.
37+
6. Save your setting.
38+
39+
The following table describes what is in each log. Depending on the output endpoint you choose, the fields included and the order in which they appear may vary.
3140

3241
|**Field** | **Description** |
3342
|---|---|
@@ -52,6 +61,9 @@ The following table describes what's in each log. Depending on the output endpoi
5261
| DatatypeName | Name of the datatype (if applicable) |
5362
| LogicalServerName | Name of the server |
5463
| _ResourceId | Resource URI |
64+
| Prefix | Log line's prefix |
65+
66+
5567

5668
## Next steps
5769
- Learn more about accessing logs from the [Azure portal](howto-configure-server-logs-in-portal.md) or [Azure CLI](howto-configure-server-logs-using-cli.md).

0 commit comments

Comments
 (0)