%3CLINGO-SUB%20id%3D%22lingo-sub-1411285%22%20slang%3D%22en-US%22%3EHow%20to%20generate%20alerts%20for%20DDL%20statements%20on%20Azure%20PostgreSQL%20using%20Log%20Analytics%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1411285%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20example%20below%20explains%20how%20we%20can%20setup%20alerts%20for%20DDL%20commands%20on%20Azure%20Postgresql.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENote%20that%20on%20the%20example%20below%2C%20if%20you%20setup%20the%20alert%20on%20one%20server%2C%20if%20you%20want%20to%20include%20a%20new%20server%2C%20you%20only%20need%20to%20follow%20steps%201%2C%202%20and%203%20-%20if%20the%20the%20two%20servers%20share%20the%20same%20log%20analytics%20workspace.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAlso%2C%20on%20the%20example%20below%2C%20I%60m%20setting%20up%20the%20alert%20for%20CREATE%20TABLE.%20This%20can%20easily%20be%20adapted%20for%20other%20DDL%20commands%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBasically%20we%20are%20going%20to%20send%20the%20PostgreSql%20logs%20to%20log%20analytics%20and%20build%20the%20alerts%20on%20top%20of%20a%20log%20analytics%20query%2C%20like%20so%20first%20of%20all%20you%20need%20to%20create%20a%20log%20analytics%20workspace%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-monitor%2Flearn%2Fquick-create-workspace%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-monitor%2Flearn%2Fquick-create-workspace%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E1%20%E2%80%93%20make%20sure%20that%20on%20the%20server%20parameters%20you%20are%20logging%20DDL%20statements%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Ricardo_NS_Marques_0-1590140217356.png%22%20style%3D%22width%3A%20612px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193844iF1CFF11D639C95C8%2Fimage-dimensions%2F612x26%3Fv%3D1.0%22%20width%3D%22612%22%20height%3D%2226%22%20title%3D%22Ricardo_NS_Marques_0-1590140217356.png%22%20alt%3D%22Ricardo_NS_Marques_0-1590140217356.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E2%20%E2%80%93%20on%20the%20server%20diagnostic%20settings%2C%20add%20a%20new%20diagnostic%20setting%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Ricardo_NS_Marques_1-1590140217365.png%22%20style%3D%22width%3A%20580px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193845iBF44086F40047654%2Fimage-dimensions%2F580x187%3Fv%3D1.0%22%20width%3D%22580%22%20height%3D%22187%22%20title%3D%22Ricardo_NS_Marques_1-1590140217365.png%22%20alt%3D%22Ricardo_NS_Marques_1-1590140217365.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E3%20%E2%80%93%20send%20the%20PostgreSQLLogs%20to%20the%20log%20analytics%20workspace%20and%20click%20on%20Save%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Ricardo_NS_Marques_2-1590140217374.png%22%20style%3D%22width%3A%20583px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193846i6B184AA42F1C6FE2%2Fimage-dimensions%2F583x280%3Fv%3D1.0%22%20width%3D%22583%22%20height%3D%22280%22%20title%3D%22Ricardo_NS_Marques_2-1590140217374.png%22%20alt%3D%22Ricardo_NS_Marques_2-1590140217374.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E4%20%E2%80%93%20Navigate%20to%20your%20Log%20Analytics%20workspace.%20On%20Logs%20section.%20A%20table%20named%20AzureDiagnostics%20should%20be%20visible%20(it%20should%20take%20some%20minutes%20to%20be%20available%20after%20the%20first%20setup)%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Ricardo_NS_Marques_3-1590140217384.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193847i289A383366862D6E%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22Ricardo_NS_Marques_3-1590140217384.png%22%20alt%3D%22Ricardo_NS_Marques_3-1590140217384.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E5%20%E2%80%93%20Copy%20and%20paste%20the%20query%20below%20into%20the%20query%20window%20and%20Run%20(even%20if%20doesn%60t%20return%20any%20results).%20Then%20click%20on%20%E2%80%9CNew%20alert%20rule%E2%80%9D%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3E%3CSTRONG%3EAzureDiagnostics%20%7C%20where%20Message%20contains%20%22CREATE%20TABLE%22%20%7C%20where%20Message%20!contains%20%22CREATE%20TABLE%20msftpgbackupprobe%22%20%7C%20where%20Category%20%3D%3D%20%22PostgreSQLLogs%22%20%7C%20where%20TimeGenerated%20%26gt%3B%20ago(1h)%20%7C%20project%20TimeGenerated%2CLogicalServerName_s%2C%20Message%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENote%20%E2%80%93%20if%20you%20notice%2C%20I%60m%20not%20specifying%20any%20server%20name.%20I%60m%20only%20looking%20for%20create%20tables%20executed%20by%20users%20in%20the%20last%20hour%2C%20inside%20postgresql%20logs.%20I%20will%20explain%20this%20below.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Ricardo_NS_Marques_4-1590140217391.png%22%20style%3D%22width%3A%20662px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193848i34250C3E40F8D05F%2Fimage-dimensions%2F662x154%3Fv%3D1.0%22%20width%3D%22662%22%20height%3D%22154%22%20title%3D%22Ricardo_NS_Marques_4-1590140217391.png%22%20alt%3D%22Ricardo_NS_Marques_4-1590140217391.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E6%20%E2%80%93%20on%20the%20Alert%20configuration%2C%20click%20on%20the%20Condition%20name%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Ricardo_NS_Marques_5-1590140217396.png%22%20style%3D%22width%3A%20637px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193849iF98C58114E5DDBF0%2Fimage-dimensions%2F637x231%3Fv%3D1.0%22%20width%3D%22637%22%20height%3D%22231%22%20title%3D%22Ricardo_NS_Marques_5-1590140217396.png%22%20alt%3D%22Ricardo_NS_Marques_5-1590140217396.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E7%20%E2%80%93%20set%20the%20condition%20logic%20(specify%20according%20with%20your%20needs)%20%E2%80%93%20I%60m%20setting%20to%20trigger%20an%20alert%20every%20time%20I%20have%20a%20row%20for%20the%20query%20output.%20Then%20click%20on%20%E2%80%9CDone%E2%80%9D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Ricardo_NS_Marques_6-1590140217402.png%22%20style%3D%22width%3A%20631px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193851iB8DB83709ABE5FDD%2Fimage-dimensions%2F631x268%3Fv%3D1.0%22%20width%3D%22631%22%20height%3D%22268%22%20title%3D%22Ricardo_NS_Marques_6-1590140217402.png%22%20alt%3D%22Ricardo_NS_Marques_6-1590140217402.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E8%20%E2%80%93%20create%20an%20Action%20group%20(if%20you%20don%60t%20have%20one)%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Ricardo_NS_Marques_7-1590140217409.png%22%20style%3D%22width%3A%20611px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193850i44B3F242F296A21D%2Fimage-dimensions%2F611x246%3Fv%3D1.0%22%20width%3D%22611%22%20height%3D%22246%22%20title%3D%22Ricardo_NS_Marques_7-1590140217409.png%22%20alt%3D%22Ricardo_NS_Marques_7-1590140217409.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%60m%20creating%20one%20based%20on%20emails%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Ricardo_NS_Marques_8-1590140217415.png%22%20style%3D%22width%3A%20646px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193852i5D0B5258E177DB1A%2Fimage-dimensions%2F646x189%3Fv%3D1.0%22%20width%3D%22646%22%20height%3D%22189%22%20title%3D%22Ricardo_NS_Marques_8-1590140217415.png%22%20alt%3D%22Ricardo_NS_Marques_8-1590140217415.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E9%20%E2%80%93%20configure%20the%20new%20alert%20details%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Ricardo_NS_Marques_9-1590140217420.png%22%20style%3D%22width%3A%20647px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193855i91362BD756C4623C%2Fimage-dimensions%2F647x304%3Fv%3D1.0%22%20width%3D%22647%22%20height%3D%22304%22%20title%3D%22Ricardo_NS_Marques_9-1590140217420.png%22%20alt%3D%22Ricardo_NS_Marques_9-1590140217420.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E10%20%E2%80%93%20check%20the%20rule%20created.%20Type%20rules%20on%20the%20search%20box%3A%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Ricardo_NS_Marques_10-1590140217422.png%22%20style%3D%22width%3A%20613px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193853i698E300A31C2BB63%2Fimage-dimensions%2F613x144%3Fv%3D1.0%22%20width%3D%22613%22%20height%3D%22144%22%20title%3D%22Ricardo_NS_Marques_10-1590140217422.png%22%20alt%3D%22Ricardo_NS_Marques_10-1590140217422.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EClick%20on%20Manage%20alert%20rules%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Ricardo_NS_Marques_11-1590140217424.png%22%20style%3D%22width%3A%20543px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193854iDE320BEB0F54965F%2Fimage-dimensions%2F543x91%3Fv%3D1.0%22%20width%3D%22543%22%20height%3D%2291%22%20title%3D%22Ricardo_NS_Marques_11-1590140217424.png%22%20alt%3D%22Ricardo_NS_Marques_11-1590140217424.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20alert%20appears%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Ricardo_NS_Marques_12-1590140217426.png%22%20style%3D%22width%3A%20586px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193856i0120EFF9B7FE7B93%2Fimage-dimensions%2F586x41%3Fv%3D1.0%22%20width%3D%22586%22%20height%3D%2241%22%20title%3D%22Ricardo_NS_Marques_12-1590140217426.png%22%20alt%3D%22Ricardo_NS_Marques_12-1590140217426.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENote%20that%20the%20alert%20doesn%60t%20use%20postgresql%20specifically.%20We%20are%20pointing%20to%20a%20Log%20analytics%20workspace.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ENow%2C%20like%20mentioned%20previously%2C%20if%20I%20want%20to%20add%20the%20same%20alert%20for%20another%20PostgreSql%20server%20I%20just%20need%20to%20steps%201%2C%202%20and%203%2C%20if%20I%20use%20the%20same%20log%20analytics%20workspace%20%E2%80%93%20in%20other%20words%2C%20the%20alert%20is%20already%20setup%20on%20the%20log%20analytics%20workspace.%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAn%20example%20of%20an%20alert%20email%20triggered%20after%20creating%20one%20table%20on%20two%20different%20servers%2C%20sharing%20the%20same%20alert%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Ricardo_NS_Marques_13-1590140217444.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193857iC56E438A826E69BB%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22Ricardo_NS_Marques_13-1590140217444.png%22%20alt%3D%22Ricardo_NS_Marques_13-1590140217444.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%2C%20with%20the%20alert%20setup%2C%20you%20can%20always%20correlate%20with%20the%20server%20logs%20(inside%20the%20Postgresql%20server%2C%20on%20the%20Server%20Logs%20blade)%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Ricardo_NS_Marques_14-1590140217449.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193858i9EF3CDEA4C1A57EA%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22Ricardo_NS_Marques_14-1590140217449.png%22%20alt%3D%22Ricardo_NS_Marques_14-1590140217449.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20text%20file%20will%20contain%20the%20exact%20statement%20(for%20example%2C%20if%20on%20the%20alert%20email%20the%20query%20text%20is%20truncated)%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Ricardo_NS_Marques_15-1590140217464.png%22%20style%3D%22width%3A%20559px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F193859i1367333D01863512%2Fimage-dimensions%2F559x95%3Fv%3D1.0%22%20width%3D%22559%22%20height%3D%2295%22%20title%3D%22Ricardo_NS_Marques_15-1590140217464.png%22%20alt%3D%22Ricardo_NS_Marques_15-1590140217464.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1411285%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20example%20below%20will%20show%20you%20how%20you%20can%20setup%20alerts%20for%20DDL%20commands%2C%20like%20CREATE%20TABLE%2C%20on%20Azure%20PostgreSql%3C%2FP%3E%3C%2FLINGO-TEASER%3E

The example below explains how we can setup alerts for DDL commands on Azure Postgresql.

 

Note that on the example below, if you setup the alert on one server, if you want to include a new server, you only need to follow steps 1, 2 and 3 - if the the two servers share the same log analytics workspace.

 

Also, on the example below, I`m setting up the alert for CREATE TABLE. This can easily be adapted for other DDL commands

 

Basically we are going to send the PostgreSql logs to log analytics and build the alerts on top of a log analytics query, like so first of all you need to create a log analytics workspace: https://docs.microsoft.com/en-us/azure/azure-monitor/learn/quick-create-workspace 

 

1 – make sure that on the server parameters you are logging DDL statements

Ricardo_NS_Marques_0-1590140217356.png

 

2 – on the server diagnostic settings, add a new diagnostic setting

Ricardo_NS_Marques_1-1590140217365.png

 

3 – send the PostgreSQLLogs to the log analytics workspace and click on Save:

Ricardo_NS_Marques_2-1590140217374.png

 

4 – Navigate to your Log Analytics workspace. On Logs section. A table named AzureDiagnostics should be visible (it should take some minutes to be available after the first setup):

Ricardo_NS_Marques_3-1590140217384.png

 

 

5 – Copy and paste the query below into the query window and Run (even if doesn`t return any results). Then click on “New alert rule” 

 

AzureDiagnostics | where Message contains "CREATE TABLE" | where Message !contains "CREATE TABLE msftpgbackupprobe" | where Category == "PostgreSQLLogs" | where TimeGenerated > ago(1h) | project TimeGenerated,LogicalServerName_s, Message

 

Note – if you notice, I`m not specifying any server name. I`m only looking for create tables executed by users in the last hour, inside postgresql logs. I will explain this below.

 

Ricardo_NS_Marques_4-1590140217391.png

 

 

 

6 – on the Alert configuration, click on the Condition name:

 

Ricardo_NS_Marques_5-1590140217396.png

 

7 – set the condition logic (specify according with your needs) – I`m setting to trigger an alert every time I have a row for the query output. Then click on “Done”

 

Ricardo_NS_Marques_6-1590140217402.png

 

8 – create an Action group (if you don`t have one):

Ricardo_NS_Marques_7-1590140217409.png

 

I`m creating one based on emails

Ricardo_NS_Marques_8-1590140217415.png

 

9 – configure the new alert details:

Ricardo_NS_Marques_9-1590140217420.png

 

10 – check the rule created. Type rules on the search box: 

Ricardo_NS_Marques_10-1590140217422.png

 

Click on Manage alert rules:

Ricardo_NS_Marques_11-1590140217424.png

 

The alert appears:

 

Ricardo_NS_Marques_12-1590140217426.png

 

Note that the alert doesn`t use postgresql specifically. We are pointing to a Log analytics workspace.

 

Now, like mentioned previously, if I want to add the same alert for another PostgreSql server I just need to steps 1, 2 and 3, if I use the same log analytics workspace – in other words, the alert is already setup on the log analytics workspace.

 

An example of an alert email triggered after creating one table on two different servers, sharing the same alert:

 

Ricardo_NS_Marques_13-1590140217444.png

 

Now, with the alert setup, you can always correlate with the server logs (inside the Postgresql server, on the Server Logs blade):

 

Ricardo_NS_Marques_14-1590140217449.png

 

The text file will contain the exact statement (for example, if on the alert email the query text is truncated):

Ricardo_NS_Marques_15-1590140217464.png