%3CLINGO-SUB%20id%3D%22lingo-sub-1214716%22%20slang%3D%22en-US%22%3EHow%20to%20configure%20Postgres%20log%20settings%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1214716%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20PostgreSQL%20logs%20can%20seem%20like%20a%20mysterious%20landscape%20you%E2%80%99re%20thrown%20into%20when%20something%20goes%20wrong%20with%20your%20app.%20You%20look%20through%20the%20logs%20wondering%2C%20%E2%80%98What%20does%20Postgres%20log%20anyway%3F%20What%20kind%20of%20errors%3F%20Will%20it%20tell%20me%20about%20long-held%20locks%3F%E2%80%99%20etc.%20But%20when%20something%20goes%20wrong%20with%20your%20app%20is%20the%20wrong%20time%20to%20be%20configuring%20Postgres%20logs.%20Set%20your%20logs%20up%20well%20ahead%20of%20time%20to%20get%20the%20most%20out%20of%20them.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20key%20with%20database%20logs%20in%20Postgres%20is%20having%20enough%20to%20help%20you%20be%20aware%20of%20and%20diagnose%20issues%2C%20but%20not%20so%20verbose%20that%20they%20drag%20down%20your%20Postgres%20server%E2%80%99s%20performance.%20To%20achieve%20this%20balance%2C%20it%E2%80%99s%20important%20to%20understand%20the%20Postgres%20%3CA%20href%3D%22https%3A%2F%2Fwww.postgresql.org%2Fdocs%2Fcurrent%2Fruntime-config-logging.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Elog%20parameters%3C%2FA%3E%3CSPAN%3E.%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3EIf%20you%E2%80%99re%20running%20your%20own%20Postgres%20installation%2C%20configure%20the%20logging%20settings%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Fwww.postgresql.org%2Fdocs%2Fcurrent%2Fconfig-setting.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Epostgresql.conf%3C%2FA%3E%20file%20or%20by%20using%20%3CA%20href%3D%22https%3A%2F%2Fwww.postgresql.org%2Fdocs%2Fcurrent%2Fsql-altersystem.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EALTER%20SYSTEM%3C%2FA%3E.%20If%20you%20are%20using%20a%20managed%20Postgres%20database%20service%20(%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fazure-postgres%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Elike%20this%20one%3C%2FA%3E)%2C%20its%20documentation%20will%20provide%20guidance%20on%20how%20to%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fpostgresql%2Fhowto-configure-server-parameters-using-portal%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Econfigure%20parameters%3C%2FA%3E.%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1386787752%22%20id%3D%22toc-hId--1386787752%22%3EDefault%20Postgres%20log%20settings%20that%20can%20help%20you%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--696226278%22%20id%3D%22toc-hId--696226278%22%3Elog_min_messages%20%3D%20WARNING%3C%2FH3%3E%0A%3CP%3EThe%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_min_messages%3C%2FCODE%3E%20setting%20is%20the%20volume%20control%20for%20Postgres%E2%80%99s%20system%20messages.%20The%20default%20means%20you%E2%80%99ll%20see%20logs%20with%20severity%20WARNING%20or%20higher%20(ERROR%2C%20LOG%2C%20FATAL%2C%20PANIC).%20See%20%3CA%20href%3D%22https%3A%2F%2Fwww.postgresql.org%2Fdocs%2Fcurrent%2Fruntime-config-logging.html%23RUNTIME-CONFIG-SEVERITY-LEVELS%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ethis%20table%20in%20the%20PostgreSQL%20docs%3C%2FA%3E%20for%20an%20explanation%20of%20what%20each%20severity%20means.%20Some%20examples%20of%20logs%20generated%20due%20to%20this%20parameter%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EERROR%3A%20out%20of%20memory%0ALOG%3A%20%20parameter%20%22log_lock_waits%22%20changed%20to%20%22ON%22%0AFATAL%3A%20%20terminating%20connection%20due%20to%20conflict%20with%20recovery%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWARNING%20is%20a%20good%20default%20setting%20to%20keep%20for%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_min_messages%3C%2FCODE%3E%20because%20it%20provides%20useful%20information%20that%20isn%E2%80%99t%20costly%20to%20have.%20You%20don%E2%80%99t%20want%20to%20go%20lower%20than%20ERROR%20because%20you%E2%80%99ll%20miss%20(you%20guessed%20it)%20errors.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-1791286555%22%20id%3D%22toc-hId-1791286555%22%3Elog_min_error_statement%20%3D%20ERROR%3C%2FH3%3E%0A%3CP%3E%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_min_error_statement%3C%2FCODE%3E%20is%20the%20SQL%20statement%20version%20of%20log_min_messages.%20That%20means%20it%20controls%20the%20logging%20level%20for%20statements%20associated%20with%20errors.%20In%20the%20example%20below%2C%20the%20first%20log%20line%20is%20emitted%20depending%20on%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_min_messages%3C%2FCODE%3E%2C%20and%20the%20paired%20second%20log%20line%20is%20emitted%20because%20of%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_min_error_statement%3C%2FCODE%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EERROR%3A%20current%20transaction%20is%20aborted%2C%20commands%20ignored%20until%20end%20of%20transaction%20block%0ASTATEMENT%3A%20SELECT%20*%20FROM%20mytable%20WHERE%20id%20%3D%201%20FOR%20UPDATE%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20see%20that%20without%20the%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_min_error_statement%3C%2FCODE%3E%20functionality%2C%20it%20would%20be%20hard%20to%20know%20what%20got%20aborted.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBecause%20the%20logs%20produced%20by%20these%20two%20parameters%20are%20paired%20in%20this%20way%2C%20you%20may%20prefer%20to%20match%20their%20settings.%20For%20example%2C%20setting%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_min_error_statement%3C%2FCODE%3E%20to%20WARNING%20as%20well.%20That%20way%20every%20system%20log%20that%20has%20a%20corresponding%20SQL%20statement%20will%20be%20logged%20with%20the%20statement.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--16167908%22%20id%3D%22toc-hId--16167908%22%3Elog_error_verbosity%20%3D%20DEFAULT%3C%2FH3%3E%0A%3CP%3EIn%20Postgres%2C%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_error_verbosity%3C%2FCODE%3E%20has%20three%20possible%20settings.%20DEFAULT%20is%20a%20good%20middle%20ground%20between%20TERSE%20and%20VERBOSE.%20DEFAULT%20adds%20detail%2C%20hint%2C%20query%2C%20and%20context%20information%20to%20the%20log%20if%20they%20are%20available%20for%20that%20error.%20For%20example%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EERROR%3A%20cannot%20drop%20table%20customers%20because%20other%20objects%20depend%20on%20it%0ADETAIL%3A%20constraint%20orders_fkey%20on%20table%20orders%20depends%20on%20table%20customers%0AHINT%3A%20Use%20DROP%20...%20CASCADE%20to%20drop%20the%20dependent%20objects%20too.%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20general%20use%2C%20stick%20with%20DEFAULT.%20TERSE%20doesn%E2%80%99t%20provide%20guidance%20on%20what%20to%20do%20about%20an%20error.%20Turn%20to%20VERBOSE%20only%20if%20you%20plan%20to%20actually%20look%20up%20the%20Postgres%20source%20code.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20following%20two%20parameters%2C%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_connections%3C%2FCODE%3E%20and%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_checkpoints%3C%2FCODE%3E%20are%20OFF%20by%20default%20in%20standard%20Postgres%20deployments.%20They%20are%20ON%20by%20default%20in%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fazure-postgres%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20Database%20for%20PostgreSQL%3C%2FA%3E%20because%20we%20believe%20it%E2%80%99s%20generally%20helpful%20to%20have%20this%20information.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1823622371%22%20id%3D%22toc-hId--1823622371%22%3Elog_connections%20%3D%20ON%3C%2FH3%3E%0A%3CP%3EAn%20important%20feature%20of%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_connections%3C%2FCODE%3E%20is%20that%20it%20will%20log%20a%20connection%20attempt%20as%20one%20line%20and%20make%20a%20separate%20log%20line%20for%20successful%20connections.%20This%20is%20handy%20for%20identifying%20bad%20connection%20attempts%20and%20where%20they%20originate%3A%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_connections%3C%2FCODE%3E%20will%20show%20you%20the%20IP%20address%20of%20the%20connection%20attempt.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3ELOG%3A%20connection%20received%3A%20host%3D122.220.2.133%20port%3D5432%20pid%3D655912%0ALOG%3A%20connection%20authorized%3A%20user%3Dbob%20database%3Dpostgres%20SSL%20enabled%20(protocol%3DTLSv1.2%2C%20cipher%3DECDHE-RSA-AES256-GCM-SHA384%2C%20compression%3Doff)%0A%20%0ALOG%3A%20connection%20received%3A%20host%3D122.220.2.133%20port%3D5432%20pid%3D655920%0AFATAL%3A%20password%20authentication%20failed%20for%20user%20%22bob%22%0ADETAIL%3A%20Password%20does%20not%20match%20for%20user%20%22bob%22.%0AConnection%20matched%20pg_hba.conf%20line%207%3A%20%22host%20all%20all%20122.220.2.133%2F32%20password%22%0A%20%0ALOG%3A%20connection%20received%3A%20host%3D24.2.2.134%20port%3D5432%20pid%3D655908%0AFATAL%3A%20no%20pg_hba.conf%20entry%20for%20host%20%2224.2.2.134%22%2C%20user%20%22alice%22%2C%20database%20%22postgres%22%2C%20SSL%20on%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3EBy%20the%20way%2C%20%3C%2FEM%3E%3CA%20href%3D%22https%3A%2F%2Fwww.postgresql.org%2Fdocs%2Fcurrent%2Fauth-pg-hba-conf.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%3CEM%3Epg_hba.conf%3C%2FEM%3E%3C%2FA%3E%3CEM%3E%20is%20Postgres%E2%80%99s%20client%20authentication%20control%20file.%20%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-663890462%22%20id%3D%22toc-hId-663890462%22%3Elog_checkpoints%20%3D%20ON%3C%2FH3%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fwww.postgresql.org%2Fdocs%2Fcurrent%2Fwal-configuration.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3ECheckpoints%3C%2FA%3E%20are%20an%20important%20part%20of%20a%20Postgres%20server%E2%80%99s%20lifecycle.%20They%20represent%20the%20moment%20when%20the%20Write%20Ahead%20Log%20(WAL)%20is%20synchronized%20to%20the%20Postgres%20data%20directory.%20Checkpoints%20are%20I%2FO%20intensive%20events%2C%20but%20recent%20checkpoints%20also%20help%20with%20server%20restart%20times.%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_checkpoints%3C%2FCODE%3E%20gives%20you%20insight%20into%20when%20checkpoints%20start%2C%20how%20long%20they%20take%2C%20and%20some%20statistics%20like%20buffers%20written.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3ELOG%3A%20checkpoint%20starting%3A%20time%0ALOG%3A%20checkpoint%20complete%20(108)%3A%20wrote%204122%20buffers%20(1.6%25)%3B%201%20WAL%20file(s)%20added%2C%200%20removed%2C%200%20recycled%3B%20write%3D269.657%20s%2C%20sync%3D0.000%20s%2C%20total%3D269.688%20s%3B%20sync%20files%3D48%2C%20longest%3D0.002%20s%2C%20average%3D0.000%20s%3B%20distance%3D126856%20kB%2C%20estimate%3D126856%20kB%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-653387358%22%20id%3D%22toc-hId-653387358%22%3EPostgres%20log%20settings%20you%20might%20be%20interested%20in%20adjusting%20and%20why%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-1343948832%22%20id%3D%22toc-hId-1343948832%22%3Elog_disconnections%20%3D%20ON%3C%2FH3%3E%0A%3CP%3E(Default%20is%20OFF).%20As%20you%20might%20guess%2C%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_disconnections%3C%2FCODE%3E%20is%20the%20counterpart%20to%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_connections%3C%2FCODE%3E.%20If%20you%20need%20to%20know%20when%20connections%20end%20and%20how%20long%20each%20connection%20lasted%2C%20consider%20turning%20this%20ON.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3ELOG%3A%20disconnection%3A%20session%20time%3A%200%3A05%3A42.621%20user%3Dalice%20database%3Dpostgres%20host%3D122.220.2.133%20port%3D5432%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--463505631%22%20id%3D%22toc-hId--463505631%22%3Elog_lock_waits%20%3D%20ON%3C%2FH3%3E%0A%3CP%3E(Default%20is%20OFF).%20If%20you%20suspect%20that%20%3CA%20href%3D%22https%3A%2F%2Fwww.citusdata.com%2Fblog%2F2018%2F02%2F15%2Fwhen-postgresql-blocks%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Elock%20waits%3C%2FA%3E%20are%20impacting%20the%20performance%20of%20your%20application%20on%20Postgres%2C%20or%20you%E2%80%99ve%20had%20trouble%20with%20locks%20before%20and%20want%20to%20keep%20an%20eye%20on%20them%2C%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_lock_waits%3C%2FCODE%3E%20is%20the%20parameter%20for%20you.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EA%20log%20is%20generated%20if%20a%20session%20waited%20longer%20than%20%3CA%20href%3D%22https%3A%2F%2Fwww.postgresql.org%2Fdocs%2Fcurrent%2Fruntime-config-locks.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Edeadlock_timeout%3C%2FA%3E%20for%20a%20lock.%20The%20two%20parameters%20(%3CCODE%20style%3D%22color%3A%20black%3B%22%3Edeadlock_timeout%3C%2FCODE%3E%20and%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_lock_waits%3C%2FCODE%3E)%20work%20in%20tandem.%20To%20have%20effective%20lock%20logging%2C%20don%E2%80%99t%20set%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Edeadlock_timeout%3C%2FCODE%3E%20too%20low%E2%80%94your%20logs%20will%20start%20getting%20verbose%20and%20the%20important%20waits%20won%E2%80%99t%20stand%20out.%20The%20default%20for%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Edeadlock_timeout%3C%2FCODE%3E%20is%201s.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3ELOG%3A%20process%20667740%20still%20waiting%20for%20ShareLock%20on%20transaction%20599%20after%201000.013%20ms%0ADETAIL%3A%20Process%20holding%20the%20lock%3A%20658912.%20Wait%20queue%3A%20667740.%0ACONTEXT%3A%20while%20locking%20tuple%20(0%2C2)%20in%20relation%20%22mytable%22%0ASTATEMENT%3A%20SELECT%20*%20FROM%20mytable%20WHERE%20id%20%3D%202%20FOR%20UPDATE%3B%0ALOG%3A%20process%20667740%20acquired%20ShareLock%20on%20transaction%20599%20after%2030671.632%20ms%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENote%20that%20actual%20deadlocks%20are%20logged%20independently%20of%20the%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_lock_waits%3C%2FCODE%3E%20parameter%2C%20because%20they%20are%20classified%20as%20a%20database%20error.%20You%E2%80%99ll%20see%20them%20if%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_min_messages%3C%2FCODE%3E%20is%20set%20to%20at%20least%20ERROR.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EERROR%3A%20deadlock%20detected%0ADETAIL%3A%20Process%20658912%20waits%20for%20ShareLock%20on%20transaction%20597%3B%20blocked%20by%20process%20660260.%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Process%20660260%20waits%20for%20ShareLock%20on%20transaction%20596%3B%20blocked%20by%20process%20658912.%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Process%20658912%3A%20SELECT%20*%20FROM%20mytable%20WHERE%20id%20%3D%202%20FOR%20UPDATE%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Process%20660260%3A%20SELECT%20*%20FROM%20mytable%20WHERE%20id%20%3D%201%20FOR%20UPDATE%3B%0AHINT%3A%20See%20server%20log%20for%20query%20details.%0ACONTEXT%3A%20while%20locking%20tuple%20(0%2C2)%20in%20relation%20%22mytable%22%0ASTATEMENT%3A%20SELECT%20*%20FROM%20mytable%20WHERE%20id%20%3D%202%20FOR%20UPDATE%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-2024007202%22%20id%3D%22toc-hId-2024007202%22%3Elog_line_prefix%20%3D%20%25m%20user%3D%25u%20db%3D%25d%20pid%3D%25p%3A%3C%2FH3%3E%0A%3CP%3E(Postgres%20default%20is%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3E%25m%20%5B%25p%5D%20%3C%2FCODE%3E%2C%20time%20and%20process%20ID%3B%20Azure%20Postgres%20default%20is%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3E%25t-%25c-%3C%2FCODE%3E%2C%20time%20and%20session%20ID)%3C%2FP%3E%0A%3CP%3EThis%20is%20one%20of%20my%20favorite%20logging%20parameters%20because%20it%20has%20a%20positive%20impact%20on%20all%20your%20Postgres%20logs.%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_line_prefix%3C%2FCODE%3E%20tells%20Postgres%20to%20add%20some%20standard%20information%20to%20the%20beginning%20of%20each%20log%20line.%20The%20suggested%20value%20of%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3E%25m%20user%3D%25u%20db%3D%25d%20pid%3D%25p%3A%20%3C%2FCODE%3E%20would%20provide%20the%20timestamp%2C%20user%20name%2C%20database%20name%2C%20and%20process%20id%20for%20each%20log.%20That%20way%20when%20you%20see%20a%20log%20you%20can%20quickly%20narrow%20down%20on%20who%20(user)%20and%20where%20(database).%20Logging%20the%20process%20or%20session%20ID%20allows%20you%20to%20correlate%20associated%20events.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E2020-03-05%2023%3A43%3A07.793%20UTC%20user%3Dbob%20db%3Dpostgres%20pid%3D670232%3A%20LOG%3A%20parameter%20%22work_mem%22%20changed%20to%20%228192%22%0A2020-04-05%2002%3A05%3A07.423%20UTC%20user%3Dalice%20db%3Dpostgres%20pid%3D879234%3A%20ERROR%3A%20permission%20denied%20for%20table%20customers%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3EIn%20other%20examples%20throughout%20the%20blog%2C%20the%20log%20line%20is%20showed%20without%20the%20prefix%20for%20brevity.%20%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--607693459%22%20id%3D%22toc-hId--607693459%22%3EBe%20careful%20with%20statement%20logging%3C%2FH2%3E%0A%3CP%3EVerbose%20logging%20tends%20to%20cause%20performance%20issues%2C%20especially%20if%20you%20log%20all%20statements.%20That%E2%80%99s%20your%20server%20doing%20additional%20work%20for%20each%20and%20every%20SQL%20statement.%20The%20extent%20of%20impact%20varies%20depending%20on%20the%20logging%20pipeline%20and%20its%20storage%2FIO%20characteristics.%3C%2FP%3E%0A%3CP%3EIn%20general%2C%20be%20very%20careful%20of%20statement%20log%20settings.%20Most%20of%20them%20are%20Booleans%20(everything%20or%20nothing).%20They%20are%20all%20off%20by%20default.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Elog_statement%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fwww.postgresql.org%2Fdocs%2Fcurrent%2Fruntime-config-statistics.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Elog_statement_stats%3C%2FA%3E%3C%2FP%3E%0A%3CP%3Elog_duration%3C%2FP%3E%0A%3CP%3Edebug_print_parse%2C%20debug_print_plan%2C%20debug_print_rewritten%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E(You%20can%20find%20more%20information%20on%20these%20parameters%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Fwww.postgresql.org%2Fdocs%2Fcurrent%2Fruntime-config-logging.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EPostgres%20documentation%3C%2FA%3E).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3E%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fazure-postgres%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20Database%20for%20PostgreSQL%3C%2FA%3E%20users%2C%20you%20get%20the%20benefit%20of%20%3C%2FEM%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fpostgresql%2Fconcepts-query-store%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%3CEM%3EQuery%20Store%3C%2FEM%3E%3C%2FA%3E%3CEM%3E.%20Query%20Store%20is%20a%20more%20performant%20way%20of%20getting%20a%20comprehensive%20historical%20view%20of%20statistics%20for%20all%20queries.%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%E2%80%99re%20going%20to%20use%20statement%20logging%20because%20you%20need%20historical%20information%20on%20your%20Postgres%20queries%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EUse%20only%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_min_duration_statement%3C%2FCODE%3E%3CBR%20%2F%3EThe%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_min_duration_statement%3C%2FCODE%3E%20setting%20enables%20you%20to%20limit%20the%20volume%20of%20statements%20that%20are%20logged.%20If%20you%20set%20log_min_duration_statement%20to%20900ms%2C%20for%20example%2C%20it%20will%20only%20log%20the%20queries%20that%20exceed%20this%20time.%20Of%20course%2C%20this%20is%20only%20useful%20as%20a%20volume%20control%20if%20the%20value%20you%20pick%20is%20a%20reasonable%20threshold%20for%20what%20a%20%E2%80%98slow%E2%80%99%20query%20is%20in%20your%20workload.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLI%3E%0A%3CLI%3EMeasure%20the%20performance%20impact%20of%20statement%20logging%20at%20different%20verbosity%20levels%2C%20so%20you%E2%80%99re%20clear%20on%20what%E2%80%99s%20an%20acceptable%20tradeoff%20for%20you.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20were%20interested%20in%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_statement%20%3D%20ALL%3C%2FCODE%3E%20for%20auditing%20purposes%2C%20consider%20using%20pgAudit%20instead.%20pgAudit%20provides%20rich%20controls%20for%20configuring%20audit%20logging.%20You%20can%20learn%20more%20about%20pgAudit%20in%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-database-for-postgresql%2Fauditing-know-what-s-going-on-in-your-postgres-database%2Fba-p%2F885243%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3Ethis%20blog%20post%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1879819374%22%20id%3D%22toc-hId-1879819374%22%3EOther%20settings%20of%20note%20to%20Azure%20Database%20for%20PostgreSQL%20users%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-201447630%22%20id%3D%22toc-hId-201447630%22%3Elogging_collector%3C%2FH3%3E%0A%3CP%3E%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elogging_collector%3C%2FCODE%3E%20controls%20whether%20Postgres%20runs%20a%20separate%20process%20for%20writing%20out%20logs%2C%20which%20is%20highly%20recommended%20unless%20you%20use%20syslog.%3C%2FP%3E%0A%3CP%3EFor%20Azure%20Postgres%2C%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elogging_collector%3C%2FCODE%3E%20is%20used%20to%20control%20whether%20logs%20go%20to%20the%20short-term%20storage%20location%20(ON)%2C%20or%20do%20not%20go%20there%20at%20all%20(OFF).%20Note%20that%20this%20is%20independent%20of%20your%20Azure%20diagnostic%20settings%2C%20which%20offer%20longer-term%20retention.%20In%20Azure%20Postgres%2C%20you%20may%20see%20performance%20benefits%20from%20setting%20%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elogging_collector%3C%2FCODE%3E%20to%20OFF%2C%20and%20using%20Azure%20diagnostic%20settings%20alone.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1606006833%22%20id%3D%22toc-hId--1606006833%22%3Elog_retention_days%3C%2FH3%3E%0A%3CP%3E%3CCODE%20style%3D%22color%3A%20black%3B%22%3Elog_retention_days%3C%2FCODE%3E%20is%20an%20Azure%20Postgres%20specific%20parameter%20that%20controls%20the%20number%20of%20days%20(3%20to%207)%20that%20logs%20are%20kept%20for%20in%20our%20Azure%20Postgres%20short-term%20log%20storage.%20The%20default%20is%203%20days%20(but%20retention%20is%20also%20limited%20by%20the%20fixed%20size%20of%20this%20log%20store).%20For%20longer%20term%20retention%20and%20larger%20storage%2C%20consider%20using%20Azure%20diagnostic%20settings.%20Visit%20the%20Azure%20Postgres%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fpostgresql%2Fconcepts-server-logs%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Elogging%20documentation%3C%2FA%3E%20for%20more%20information.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-752423281%22%20id%3D%22toc-hId-752423281%22%3EGo%20forth%20and%20log%3C%2FH2%3E%0A%3CP%3EConfiguring%20good%20database%20logs%20is%20probably%20not%20a%20glamorous%20part%20of%20your%20job%20description.%20Yet%20when%20something%20goes%20wrong%20the%20first%20place%20you%20turn%20to%20is%20your%20logs.%20Setting%20up%20logs%20that%20work%20is%20part%20of%20good%20application%20hygiene.%20It%20may%20not%20always%20spark%20joy%2C%20but%20in%20the%20long%20run%20it%20makes%20your%20apps%20healthier%20and%20easier%20to%20diagnose.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20have%20any%20feedback%20for%20us%20or%20questions%20on%20Postgres%20logs%2C%20drop%20us%20an%20email%20%3CA%3E%40AskAzureDBforPostgreSQL%3C%2FA%3E.%20Till%20then%2C%20go%20forth%20and%20log.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CI%3EFor%20an%20exhaustive%20list%20of%20Postgres%20logging%20parameters%2C%20their%20definitions%2C%20and%20any%20specifics%20for%20the%20Postgres%20version%20you%E2%80%99re%20running%2C%20visit%20%3CA%20href%3D%22https%3A%2F%2Fwww.postgresql.org%2Fdocs%2Fcurrent%2Fruntime-config-logging.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ethe%20PostgreSQL%20documentation%3C%2FA%3E.%3C%2FI%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1214716%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20style%3D%22display%3A%20inline%20!important%3B%20float%3A%20none%3B%20background-color%3A%20%23ffffff%3B%20color%3A%20%23333333%3B%20cursor%3A%20text%3B%20font-family%3A%20inherit%3B%20font-size%3A%2016px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20300%3B%20letter-spacing%3A%20normal%3B%20line-height%3A%201.7142%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%22%3EShould%20you%20stick%20with%20the%20default%20Postgres%20log%20settings%3F%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20style%3D%22display%3A%20inline%20!important%3B%20float%3A%20none%3B%20background-color%3A%20%23ffffff%3B%20color%3A%20%23333333%3B%20cursor%3A%20text%3B%20font-family%3A%20inherit%3B%20font-size%3A%2016px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20300%3B%20letter-spacing%3A%20normal%3B%20line-height%3A%201.7142%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22log%20picture.png%22%20style%3D%22width%3A%20892px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F175889i50C1EDCAD4DBC2CF%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22log%20picture.png%22%20alt%3D%22log%20picture.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1214716%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Elogs%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eparameters%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Epostgres%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Epostgresql%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

The PostgreSQL logs can seem like a mysterious landscape you’re thrown into when something goes wrong with your app. You look through the logs wondering, ‘What does Postgres log anyway? What kind of errors? Will it tell me about long-held locks?’ etc. But when something goes wrong with your app is the wrong time to be configuring Postgres logs. Set your logs up well ahead of time to get the most out of them.

 

The key with database logs in Postgres is having enough to help you be aware of and diagnose issues, but not so verbose that they drag down your Postgres server’s performance. To achieve this balance, it’s important to understand the Postgres log parameters.

 

If you’re running your own Postgres installation, configure the logging settings in the postgresql.conf file or by using ALTER SYSTEM. If you are using a managed Postgres database service (like this one), its documentation will provide guidance on how to configure parameters.

 

Default Postgres log settings that can help you

 

log_min_messages = WARNING

The log_min_messages setting is the volume control for Postgres’s system messages. The default means you’ll see logs with severity WARNING or higher (ERROR, LOG, FATAL, PANIC). See this table in the PostgreSQL docs for an explanation of what each severity means. Some examples of logs generated due to this parameter:

 

ERROR: out of memory
LOG:  parameter "log_lock_waits" changed to "ON"
FATAL:  terminating connection due to conflict with recovery

 

WARNING is a good default setting to keep for log_min_messages because it provides useful information that isn’t costly to have. You don’t want to go lower than ERROR because you’ll miss (you guessed it) errors.

 

log_min_error_statement = ERROR

log_min_error_statement is the SQL statement version of log_min_messages. That means it controls the logging level for statements associated with errors. In the example below, the first log line is emitted depending on log_min_messages, and the paired second log line is emitted because of log_min_error_statement.

 

ERROR: current transaction is aborted, commands ignored until end of transaction block
STATEMENT: SELECT * FROM mytable WHERE id = 1 FOR UPDATE;

 

You can see that without the log_min_error_statement functionality, it would be hard to know what got aborted.

 

Because the logs produced by these two parameters are paired in this way, you may prefer to match their settings. For example, setting log_min_error_statement to WARNING as well. That way every system log that has a corresponding SQL statement will be logged with the statement.

 

log_error_verbosity = DEFAULT

In Postgres, log_error_verbosity has three possible settings. DEFAULT is a good middle ground between TERSE and VERBOSE. DEFAULT adds detail, hint, query, and context information to the log if they are available for that error. For example,

 

ERROR: cannot drop table customers because other objects depend on it
DETAIL: constraint orders_fkey on table orders depends on table customers
HINT: Use DROP ... CASCADE to drop the dependent objects too.

 

For general use, stick with DEFAULT. TERSE doesn’t provide guidance on what to do about an error. Turn to VERBOSE only if you plan to actually look up the Postgres source code.

 

The following two parameters, log_connections and log_checkpoints are OFF by default in standard Postgres deployments. They are ON by default in Azure Database for PostgreSQL because we believe it’s generally helpful to have this information.

 

log_connections = ON

An important feature of log_connections is that it will log a connection attempt as one line and make a separate log line for successful connections. This is handy for identifying bad connection attempts and where they originate: log_connections will show you the IP address of the connection attempt.

 

LOG: connection received: host=122.220.2.133 port=5432 pid=655912
LOG: connection authorized: user=bob database=postgres SSL enabled (protocol=TLSv1.2, cipher=ECDHE-RSA-AES256-GCM-SHA384, compression=off)
 
LOG: connection received: host=122.220.2.133 port=5432 pid=655920
FATAL: password authentication failed for user "bob"
DETAIL: Password does not match for user "bob".
Connection matched pg_hba.conf line 7: "host all all 122.220.2.133/32 password"
 
LOG: connection received: host=24.2.2.134 port=5432 pid=655908
FATAL: no pg_hba.conf entry for host "24.2.2.134", user "alice", database "postgres", SSL on

 

By the way, pg_hba.conf is Postgres’s client authentication control file.

 

log_checkpoints = ON

Checkpoints are an important part of a Postgres server’s lifecycle. They represent the moment when the Write Ahead Log (WAL) is synchronized to the Postgres data directory. Checkpoints are I/O intensive events, but recent checkpoints also help with server restart times. log_checkpoints gives you insight into when checkpoints start, how long they take, and some statistics like buffers written.

 

LOG: checkpoint starting: time
LOG: checkpoint complete (108): wrote 4122 buffers (1.6%); 1 WAL file(s) added, 0 removed, 0 recycled; write=269.657 s, sync=0.000 s, total=269.688 s; sync files=48, longest=0.002 s, average=0.000 s; distance=126856 kB, estimate=126856 kB

 

 

Postgres log settings you might be interested in adjusting and why

 

log_disconnections = ON

(Default is OFF). As you might guess, log_disconnections is the counterpart to log_connections. If you need to know when connections end and how long each connection lasted, consider turning this ON.

 

LOG: disconnection: session time: 0:05:42.621 user=alice database=postgres host=122.220.2.133 port=5432

 

 

log_lock_waits = ON

(Default is OFF). If you suspect that lock waits are impacting the performance of your application on Postgres, or you’ve had trouble with locks before and want to keep an eye on them, log_lock_waits is the parameter for you.

 

A log is generated if a session waited longer than deadlock_timeout for a lock. The two parameters (deadlock_timeout and log_lock_waits) work in tandem. To have effective lock logging, don’t set deadlock_timeout too low—your logs will start getting verbose and the important waits won’t stand out. The default for deadlock_timeout is 1s.

 

LOG: process 667740 still waiting for ShareLock on transaction 599 after 1000.013 ms
DETAIL: Process holding the lock: 658912. Wait queue: 667740.
CONTEXT: while locking tuple (0,2) in relation "mytable"
STATEMENT: SELECT * FROM mytable WHERE id = 2 FOR UPDATE;
LOG: process 667740 acquired ShareLock on transaction 599 after 30671.632 ms

 

Note that actual deadlocks are logged independently of the log_lock_waits parameter, because they are classified as a database error. You’ll see them if log_min_messages is set to at least ERROR.

 

ERROR: deadlock detected
DETAIL: Process 658912 waits for ShareLock on transaction 597; blocked by process 660260.
               Process 660260 waits for ShareLock on transaction 596; blocked by process 658912.
               Process 658912: SELECT * FROM mytable WHERE id = 2 FOR UPDATE;
               Process 660260: SELECT * FROM mytable WHERE id = 1 FOR UPDATE;
HINT: See server log for query details.
CONTEXT: while locking tuple (0,2) in relation "mytable"
STATEMENT: SELECT * FROM mytable WHERE id = 2 FOR UPDATE;

 

 

log_line_prefix = %m user=%u db=%d pid=%p:

(Postgres default is %m [%p] , time and process ID; Azure Postgres default is %t-%c-, time and session ID)

This is one of my favorite logging parameters because it has a positive impact on all your Postgres logs. log_line_prefix tells Postgres to add some standard information to the beginning of each log line. The suggested value of %m user=%u db=%d pid=%p: would provide the timestamp, user name, database name, and process id for each log. That way when you see a log you can quickly narrow down on who (user) and where (database). Logging the process or session ID allows you to correlate associated events.

 

2020-03-05 23:43:07.793 UTC user=bob db=postgres pid=670232: LOG: parameter "work_mem" changed to "8192"
2020-04-05 02:05:07.423 UTC user=alice db=postgres pid=879234: ERROR: permission denied for table customers

 

In other examples throughout the blog, the log line is showed without the prefix for brevity.

 

Be careful with statement logging

Verbose logging tends to cause performance issues, especially if you log all statements. That’s your server doing additional work for each and every SQL statement. The extent of impact varies depending on the logging pipeline and its storage/IO characteristics.

In general, be very careful of statement log settings. Most of them are Booleans (everything or nothing). They are all off by default.

 

log_statement

log_statement_stats

log_duration

debug_print_parse, debug_print_plan, debug_print_rewritten

 

(You can find more information on these parameters in the Postgres documentation).

 

Azure Database for PostgreSQL users, you get the benefit of Query Store. Query Store is a more performant way of getting a comprehensive historical view of statistics for all queries.

 

If you’re going to use statement logging because you need historical information on your Postgres queries:

  1. Use only log_min_duration_statement
    The log_min_duration_statement setting enables you to limit the volume of statements that are logged. If you set log_min_duration_statement to 900ms, for example, it will only log the queries that exceed this time. Of course, this is only useful as a volume control if the value you pick is a reasonable threshold for what a ‘slow’ query is in your workload.

  2. Measure the performance impact of statement logging at different verbosity levels, so you’re clear on what’s an acceptable tradeoff for you.

 

If you were interested in log_statement = ALL for auditing purposes, consider using pgAudit instead. pgAudit provides rich controls for configuring audit logging. You can learn more about pgAudit in this blog post.

 

Other settings of note to Azure Database for PostgreSQL users

 

logging_collector

logging_collector controls whether Postgres runs a separate process for writing out logs, which is highly recommended unless you use syslog.

For Azure Postgres, logging_collector is used to control whether logs go to the short-term storage location (ON), or do not go there at all (OFF). Note that this is independent of your Azure diagnostic settings, which offer longer-term retention. In Azure Postgres, you may see performance benefits from setting logging_collector to OFF, and using Azure diagnostic settings alone.

 

log_retention_days

log_retention_days is an Azure Postgres specific parameter that controls the number of days (3 to 7) that logs are kept for in our Azure Postgres short-term log storage. The default is 3 days (but retention is also limited by the fixed size of this log store). For longer term retention and larger storage, consider using Azure diagnostic settings. Visit the Azure Postgres logging documentation for more information.

 

Go forth and log

Configuring good database logs is probably not a glamorous part of your job description. Yet when something goes wrong the first place you turn to is your logs. Setting up logs that work is part of good application hygiene. It may not always spark joy, but in the long run it makes your apps healthier and easier to diagnose.

 

If you have any feedback for us or questions on Postgres logs, drop us an email @AskAzureDBforPostgreSQL. Till then, go forth and log.

 

For an exhaustive list of Postgres logging parameters, their definitions, and any specifics for the Postgres version you’re running, visit the PostgreSQL documentation.