@@ -5,6 +5,7 @@ param tenantId string
55param subnetId string
66param virtualNetworkId string
77param isProduction bool
8+ param diagnosticStorageAccountId string
89
910resource postgresServer 'Microsoft.DBforPostgreSQL/flexibleServers@2025-08-01' = {
1011 name : name
@@ -103,20 +104,55 @@ resource extensionsConfig 'Microsoft.DBforPostgreSQL/flexibleServers/configurati
103104 name : 'azure.extensions'
104105 dependsOn : [privateDnsZoneGroup ]
105106 properties : {
106- value : 'pg_stat_statements'
107+ value : 'pg_stat_statements,pgaudit'
108+ source : 'user-override'
109+ }
110+ }
111+
112+ resource sharedPreloadLibrariesConfig 'Microsoft.DBforPostgreSQL/flexibleServers/configurations@2025-08-01' = {
113+ parent : postgresServer
114+ name : 'shared_preload_libraries'
115+ dependsOn : [extensionsConfig ]
116+ properties : {
117+ value : 'pgaudit'
118+ source : 'user-override'
119+ }
120+ }
121+
122+ resource pgauditLogConfig 'Microsoft.DBforPostgreSQL/flexibleServers/configurations@2025-08-01' = {
123+ parent : postgresServer
124+ name : 'pgaudit.log'
125+ dependsOn : [sharedPreloadLibrariesConfig ]
126+ properties : {
127+ value : 'WRITE,DDL,ROLE'
107128 source : 'user-override'
108129 }
109130}
110131
111132resource walLevelConfig 'Microsoft.DBforPostgreSQL/flexibleServers/configurations@2025-08-01' = {
112133 parent : postgresServer
113134 name : 'wal_level'
114- dependsOn : [extensionsConfig ]
135+ dependsOn : [pgauditLogConfig ]
115136 properties : {
116137 value : 'logical'
117138 source : 'user-override'
118139 }
119140}
120141
142+ resource diagnosticSettings 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = {
143+ name : '${name }-postgres-diagnostics'
144+ scope : postgresServer
145+ dependsOn : [walLevelConfig ]
146+ properties : {
147+ storageAccountId : diagnosticStorageAccountId
148+ logs : [
149+ {
150+ categoryGroup : 'allLogs'
151+ enabled : true
152+ }
153+ ]
154+ }
155+ }
156+
121157output serverName string = postgresServer .name
122158output serverFqdn string = postgresServer .properties .fullyQualifiedDomainName
0 commit comments