Home
%3CLINGO-SUB%20id%3D%22lingo-sub-819227%22%20slang%3D%22en-US%22%3EPerformance%20Troubleshooting%20Basics%20on%20Azure%20Database%20for%20PostgreSQL%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-819227%22%20slang%3D%22en-US%22%3E%3CP%3EIf%20you%20are%20facing%20Performance%20issues%20with%20Azure%20Database%20for%20PostgreSQL%2C%20these%20can%20often%20be%20resolved%20by%20doing%20basic%20troubleshooting%20steps%20to%20understand%20the%20cause%20of%20the%20bottleneck%20and%20then%20explore%20options%20to%20fix%20it.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22text-align%3A%20center%3B%22%3E%3CFONT%20size%3D%225%22%3E%3CSTRONG%3EServer%20Level%20Troubleshooting%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CBR%20%2F%3E1-%26nbsp%3BResource%20Utilization%3A%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EIt's%26nbsp%3B%20important%20to%20make%20sure%20that%20you%20are%20not%20maxing%20out%20any%20of%20your%20resource%20limits%2C%20reaching%20high%20levels%20of%20resource%20utilization%20will%20cause%20a%20performance%20issue%20this%20can%20be%20avoided%20by%20monitoring%20server's%20resource%20utilization%20on%20the%20Azure%20Portal.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CP%3EIn%20Azure%20Database%20for%20PostgreSQL%20resource%20limits%20determined%20by%20the%20service%20tier%20that%20you%20are%20using%2C%20number%20of%20vCores%20and%20Storage%20size%20that%20you%20provision.%20All%20this%20information%20is%20documented%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fpostgresql%2Fconcepts-pricing-tiers%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%26nbsp%3B%3C%2FA%3Eand%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fpostgresql%2Fconcepts-limits%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E%2C%20you%20can%20navigate%20to%20your%20Azure%20Database%20for%20PostgreSQL%20and%20use%20the%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fpostgresql%2Fconcepts-monitoring%23metrics%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EMetrics%26nbsp%3B%3C%2FA%3Eblade%20to%20check%20if%20you%20are%20maxing%20out%20any%20of%20your%20resource%20limits.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CP%3EIf%20your%20workload%20is%20maxing%20out%20any%20of%20these%20server%20metrics%20please%20consider%20scaling%20up%20resources%20to%20accommodate%20the%20workload%20and%20review%20top%20queries%20consumers%20and%20tune%20them.%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F128130iD12DD6DA3175970E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Pg%20metrics.jpg%22%20title%3D%22Pg%20metrics.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E2-%26nbsp%3BMake%20sure%20you%20are%20applying%20Application%20side%20best%20practices%3A%3C%2FP%3E%0A%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3Ea)%20Connection%20pooling%3A%26nbsp%3BThis%20significantly%20reduces%20connection%20latency%20by%20reusing%20existing%20connections%20and%20enables%20higher%20database%20throughput%20(transactions%20per%20second)%20on%20the%20server.%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3E%3CBR%20%2F%3ETypically%2C%20application%20side%20pooling%20opens%20a%20bunch%20of%20connections%20which%20sit%20idle%20at%20the%20database.%20Idle%20applications%20consume%2010MB%20of%20memory%20per%20connection%20and%20can%20also%20create%20contention%20for%20establishing%20new%20connections%20and%20slow%20down%20queries.%20You%20can%20learn%20much%20more%20about%20this%20here.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3EEssentially%20if%20you%20see%20a%20high%20number%20of%20idle%20connections%2C%20it%20would%20be%20recommended%20to%20put%20a%20PostgreSQL%20specific%20connection%20pooler%20in%20place%20(server%20side%20connection%20pooler).%20We%20recommend%20leveraging%20pgbouncer%20for%20this.%20You%20can%20find%20steps%20to%20configure%20and%20install%20pgbouncer%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FAzure-Database-for-PostgreSQL%2FSteps-to-install-and-setup-PgBouncer-connection-pooling-proxy%2Fba-p%2F730555%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3Ehere%3C%2FA%3E.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSTRONG%3Eb)%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fvirtual-network%2Fcreate-vm-accelerated-networking-cli%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EAccelerated%20Networking%3C%2FA%3E%3A%26nbsp%3B%3C%2FSTRONG%3Eenables%20single%20root%20I%2FO%20virtualization%20(SR-IOV)%20to%20a%20VM%2C%20greatly%20improving%20its%20networking%20performance.%20This%20high-performance%20path%20bypasses%20the%20host%20from%20the%20datapath%2C%20reducing%20latency%2C%20jitter%2C%20and%20CPU%20utilization%2C%20for%20use%20with%20the%20most%20demanding%20network%20workloads%20on%20supported%20VM%20types.%3C%2FP%3E%0A%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3E%3CSTRONG%3E%26nbsp%3B%3CBR%20%2F%3E%3C%2FSTRONG%3E%3CSTRONG%3Ec)%20Improve%20Performance%20of%20Read%20Intensive%20Workloads%20on%20Azure%20DB%20for%20PostgreSQL%20using%20Query%20Caching%3A%26nbsp%3B%3C%2FSTRONG%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FAzure-Database-for-PostgreSQL%2FSet-up-Pgpool-II-Query-Caching-with-Azure-Database-for%2Fba-p%2F788005%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3EPgpool-II%20Query%20Caching%3C%2FA%3E%2C%20Redis%20cache%20%2C%20Memcached%20are%20the%20popular%20external%20query%20caching%20solutions%20read%20more%20about%20query%20caching%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FAzure-Database-for-PostgreSQL%2FImprove-Performance-of-Read-Intensive-Workloads-on-Azure-DB-for%2Fba-p%2F743860%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3Ehere%3C%2FA%3E.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSTRONG%3Ed)%20Application%20and%20Database%20should%20be%20in%20the%20same%20Data%20Center%3A%3C%2FSTRONG%3Emake%20sure%20your%20application%20is%20in%20the%20same%20data%20center%20as%20your%20database%20server%20to%20avoid%20overhead%20network%20latency.%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSTRONG%3Ee)%20CPU%20exhaustion%3A%20%3C%2FSTRONG%3ESingle-threaded%20applications%20can%20result%20in%20CPU%20exhaustion%20of%20one%20CPU%20while%20the%20other%20CPUs%20are%20under-utilized.%20Consider%20parallelizing%20your%20workload%20to%20take%20advantage%20of%20all%20the%20vCores%20available.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSTRONG%3Ef)%20TCP_NODELAY%3A%3C%2FSTRONG%3ETCP_NODELAY%20is%20a%20client-side%20setting%20that%20should%20be%20considered%20on%20a%20client%20Virtual%20Machine%20(VM).%20Applications%20that%20benefit%20from%20the%20TCP_NODELAY%20option%20typically%20tend%20to%20do%20smaller%20infrequent%20writes%20and%20are%20particularly%20sensitive%20to%20latency.%20As%20an%20example%2C%20latency%20can%20be%20reduced%20from%2015-40%20ms%20to%202-3%20ms%20with%20this%20setting.%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3E%3CSTRONG%3E3-%20Leverage%20ANALYZE%20command%20%3C%2FSTRONG%3E%3CBR%20%2F%3EANALYZE%26nbsp%3Bcollects%20statistics%20about%20the%20contents%20of%20tables%20in%20the%20database%2C%20and%20stores%20the%20results%20in%20the%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fwww.postgresql.org%2Fdocs%2Fcurrent%2Fcatalog-pg-statistic.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Epg_statistic%3C%2FA%3E%26nbsp%3Bsystem%20catalog.%20Subsequently%2C%20the%20query%20planner%20uses%20these%20statistics%20to%20help%20determine%20the%20most%20efficient%20execution%20plans%20for%20queries.%20You%20can%20read%20more%20about%20this%20%3CA%20href%3D%22https%3A%2F%2Fwww.postgresql.org%2Fdocs%2Fcurrent%2Fsql-analyze.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%3CBR%20%2F%3E%3CBR%20%2F%3EWith%20no%20parameter%2C%20ANALYZE%20examines%20every%20table%20in%20the%20current%20database.%20With%20a%20parameter%2C%20ANALYZE%20examines%20only%20that%20table.%20It%20is%20further%20possible%20to%20give%20a%20list%20of%20column%20names%2C%20in%20which%20case%20only%20the%20statistics%20for%20those%20columns%20are%20collected.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CBR%20%2F%3E4-%20Autovacuum%3C%2FSTRONG%3E%3A%20%3CBR%20%2F%3EPostgreSQL%20uses%20multiversion%20concurrency%20control%20(MVCC)%20to%20allow%20greater%20database%20concurrency.%20Every%20update%20results%20in%20an%20insert%20and%20delete%2C%20and%20every%20delete%20results%20in%20rows%20being%20soft-marked%20for%20deletion.%20Soft-marking%20identifies%20dead%20tuples%20that%20will%20be%20purged%20later.%20To%20carry%20out%20these%20tasks%2C%20PostgreSQL%20runs%20a%20vacuum%20job.%20More%20information%20can%20be%20found%20here.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E5-%20Overall%20Slowness%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3Ea)%20Consider%20disabling%20%3CSTRONG%3E%3CEM%3Epg_stat_statements%3C%2FEM%3E%3C%2FSTRONG%3E%2C%20this%20can%20be%20done%20by%20visiting%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fpostgresql%2Fconcepts-server-logs%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Eserver%20parameters%3C%2FA%3E%20blade%20on%20the%20Azure%20Portal%20and%20set%20%22pg_stat_statements.track%22%20to%20NONE.%3CBR%20%2F%3ESome%20customers%20workload%20have%20seen%20up%20to%20a%2050%20percent%20performance%20improvement%20with%20disabling%20this.%20The%20tradeoff%20you%20make%20when%20you%20disable%20pg_stat_statements%20is%20the%20inability%20to%20troubleshoot%20performance%20issues.%3C%2FP%3E%0A%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20style%3D%22padding-left%3A%2030px%3B%22%3Eb)%20Network%20latency%3A%20Check%20the%20network%20latency%20between%20the%20client%20and%20the%20database%20service%20instance.%20You%20can%20check%20the%20network%20latency%20by%20running%20simple%20query%20as%20%E2%80%98SELECT%201%E2%80%99.%3CBR%20%2F%3E%3CBR%20%2F%3Ec)%20Consider%20disabling%20the%20following%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fpostgresql%2Fconcepts-server-logs%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Eserver%20parameters%3C%2FA%3E%20to%20reduce%20the%20overhead%20on%20the%20database%20side.%20Those%20server%20parameters%20are%20helpful%20to%20understand%20your%20workload%20but%20proven%20to%20cause%20performance%20degradation%20when%20enabled.%3CBR%20%2F%3E-%26nbsp%3Blog_duration%20%3D%20OFF%3CBR%20%2F%3E-%26nbsp%3Blog_min_duration_statement%20%3D%20-1%3CBR%20%2F%3E-%20log_statement_stats%20%3D%20OFF%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20style%3D%22text-align%3A%20center%3B%22%3E%3CFONT%20size%3D%225%22%3E%3CSTRONG%3EQuery%20Level%20Troubleshooting%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3E%3CSTRONG%3EUse%20Microsoft%26nbsp%3BIntelligent%20Performance%20tools%20to%20explore%20queries%20that%20are%20considered%20top%20consumers%20and%20also%20learn%20about%20missing%20indexes%20along%20with%20recommendation%26nbsp%3Band%20full%20analysis%20for%20your%20workload.%20Intelligent%20Performance%20for%20Azure%20Database%20for%20PostgreSQL%20includes%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CBR%20%2F%3E%3C%2FSTRONG%3E%3CSTRONG%3E1)%20Query%20Store%3A%20%3CBR%20%2F%3E%3C%2FSTRONG%3EQuery%20Store%20feature%20in%20Azure%20Database%20for%20PostgreSQL%20provides%20a%20way%20to%20track%20query%20performance%20over%20time.%20Query%20Store%20simplifies%20performance%20troubleshooting%20by%20helping%20you%20quickly%20find%20the%20longest%20running%20and%20most%20resource-intensive%20queries.%20Query%20Store%20automatically%20captures%20a%20history%20of%20queries%20and%20runtime%20statistics%2C%20and%20it%20retains%20them%20for%20your%20review.%20It%20separates%20data%20by%20time%20windows%20so%20that%20you%20can%20see%20database%20usage%20patterns.%20Data%20for%20all%20users%2C%20databases%2C%20and%20queries%20is%20stored%20in%20a%20database%20named%20azure_sys%20in%20the%20Azure%20Database%20for%20PostgreSQL%20instance.Learn%20more%20about%20Query%20store%20here.%3C%2FP%3E%0A%3CP%3Eyou%20can%20also%20view%20some%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fpostgresql%2Fconcepts-query-store-scenarios%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Eusage%20scenario%20for%20Query%20Store%26nbsp%3B%3C%2FA%3Eand%20some%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fpostgresql%2Fconcepts-query-store-best-practices%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EBest%20Practices%20for%20Query%20Store.%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E2)%20Query%20Performance%26nbsp%3BInsight%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fpostgresql%2Fconcepts-query-performance-insight%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EQuery%20Performance%20Insight%3C%2FA%3Ehelps%20you%20to%20quickly%20identify%20what%20your%20longest%20running%20queries%20are%2C%20how%20they%20change%20over%20time%2C%20and%20what%20waits%20are%20affecting%20them.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSTRONG%3E3)%20Performance%26nbsp%3Brecommendations%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fpostgresql%2Fconcepts-performance-recommendations%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EPerformance%20Recommendations%20feature%3C%2FA%3Eanalyses%20your%20databases%20to%20create%20customized%20suggestions%20for%20improved%20performance.%20To%20produce%20the%20recommendations%2C%20the%20analysis%20looks%20at%20various%20database%20characteristics%20including%20schema.%20Enable%20Query%20Store%20on%20your%20server%20to%20fully%20utilize%20the%20Performance%20Recommendations%20feature.%20After%20implementing%20any%20performance%20recommendation%2C%20you%20should%20test%20performance%20to%20evaluate%20the%20impact%20of%20those%20changes.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EReferences%3A%26nbsp%3B%3C%2FP%3E%0A%3CP%3E1)%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fblog%2Fperformance-updates-and-tuning-best-practices-for-using-azure-database-for-postgresql%2F%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EPerformance%20updates%20and%20tuning%20best%20practices%20for%20using%20Azure%20Database%20for%20PostgreSQL%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E2)%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fen-us%2Fblog%2Fperformance-best-practices-for-using-azure-database-for-postgresql%2F%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EPerformance%20best%20practices%20for%20using%20Azure%20Database%20for%20PostgreSQL%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E3)%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FAzure-Database-for-PostgreSQL%2FImprove-Performance-of-Read-Intensive-Workloads-on-Azure-DB-for%2Fba-p%2F743860%22%20target%3D%22_self%22%3EImprove%20Performance%20of%20Read%20Intensive%20Workloads%20on%20Azure%20DB%20for%20PostgreSQL%20using%20Query%20Caching%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E4)%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FAzure-Database-for-PostgreSQL%2FSet-up-Pgpool-II-Query-Caching-with-Azure-Database-for%2Fba-p%2F788005%22%20target%3D%22_self%22%3ESet%20up%20Pgpool-II%20Query%20Caching%20with%20Azure%20Database%20for%20PostgreSQL%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E5)%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FAzure-Database-for-PostgreSQL%2FSteps-to-install-and-setup-PgBouncer-connection-pooling-proxy%2Fba-p%2F730555%22%20target%3D%22_self%22%3ESteps%20to%20install%20and%20setup%20PgBouncer%20connection%20pooling%20proxy%20with%20Azure%20DB%20for%20PostgreSQL%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-819227%22%20slang%3D%22en-US%22%3E%3CP%3ELearn%20how%20to%20identify%20bottlenecks%20and%20resolve%20them%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-819227%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Database%20for%20PostgreSQL%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPerformance%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPerformance%20Issues%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Epostgres%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Epostgresql%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

If you are facing Performance issues with Azure Database for PostgreSQL, these can often be resolved by doing basic troubleshooting steps to understand the cause of the bottleneck and then explore options to fix it.

 

Server Level Troubleshooting


1- Resource Utilization: 

It's  important to make sure that you are not maxing out any of your resource limits, reaching high levels of resource utilization will cause a performance issue this can be avoided by monitoring server's resource utilization on the Azure Portal.

In Azure Database for PostgreSQL resource limits determined by the service tier that you are using, number of vCores and Storage size that you provision. All this information is documented here and here, you can navigate to your Azure Database for PostgreSQL and use the Metrics blade to check if you are maxing out any of your resource limits. 

If your workload is maxing out any of these server metrics please consider scaling up resources to accommodate the workload and review top queries consumers and tune them.Pg metrics.jpg

 


2-
 Make sure you are applying Application side best practices:

a) Connection poolingThis significantly reduces connection latency by reusing existing connections and enables higher database throughput (transactions per second) on the server. 


Typically, application side pooling opens a bunch of connections which sit idle at the database. Idle applications consume 10MB of memory per connection and can also create contention for establishing new connections and slow down queries. You can learn much more about this here.

Essentially if you see a high number of idle connections, it would be recommended to put a PostgreSQL specific connection pooler in place (server side connection pooler). We recommend leveraging pgbouncer for this. You can find steps to configure and install pgbouncer here.

b) Accelerated Networkingenables single root I/O virtualization (SR-IOV) to a VM, greatly improving its networking performance. This high-performance path bypasses the host from the datapath, reducing latency, jitter, and CPU utilization, for use with the most demanding network workloads on supported VM types.

 
c) Improve Performance of Read Intensive Workloads on Azure DB for PostgreSQL using Query Caching: Pgpool-II Query Caching, Redis cache , Memcached are the popular external query caching solutions read more about query caching here.

d) Application and Database should be in the same Data Center: make sure your application is in the same data center as your database server to avoid overhead network latency.

e) CPU exhaustion: Single-threaded applications can result in CPU exhaustion of one CPU while the other CPUs are under-utilized. Consider parallelizing your workload to take advantage of all the vCores available.

f) TCP_NODELAY: TCP_NODELAY is a client-side setting that should be considered on a client Virtual Machine (VM). Applications that benefit from the TCP_NODELAY option typically tend to do smaller infrequent writes and are particularly sensitive to latency. As an example, latency can be reduced from 15-40 ms to 2-3 ms with this setting.


3- Leverage ANALYZE command
ANALYZE collects statistics about the contents of tables in the database, and stores the results in the pg_statistic system catalog. Subsequently, the query planner uses these statistics to help determine the most efficient execution plans for queries. You can read more about this here.

With no parameter, ANALYZE examines every table in the current database. With a parameter, ANALYZE examines only that table. It is further possible to give a list of column names, in which case only the statistics for those columns are collected.


4- Autovacuum
:
PostgreSQL uses multiversion concurrency control (MVCC) to allow greater database concurrency. Every update results in an insert and delete, and every delete results in rows being soft-marked for deletion. Soft-marking identifies dead tuples that will be purged later. To carry out these tasks, PostgreSQL runs a vacuum job. More information can be found here.

 

5- Overall Slowness

a) Consider disabling pg_stat_statements, this can be done by visiting the server parameters blade on the Azure Portal and set "pg_stat_statements.track" to NONE.
Some customers workload have seen up to a 50 percent performance improvement with disabling this. The tradeoff you make when you disable pg_stat_statements is the inability to troubleshoot performance issues.

 

b) Network latency: Check the network latency between the client and the database service instance. You can check the network latency by running simple query as ‘SELECT 1’.

c) Consider disabling the following server parameters to reduce the overhead on the database side. Those server parameters are helpful to understand your workload but proven to cause performance degradation when enabled.
- log_duration = OFF
- log_min_duration_statement = -1
- log_statement_stats = OFF

 

Query Level Troubleshooting


Use Microsoft Intelligent Performance tools to explore queries that are considered top consumers and also learn about missing indexes along with recommendation and full analysis for your workload. Intelligent Performance for Azure Database for PostgreSQL includes:


1) Query Store:
Query Store feature in Azure Database for PostgreSQL provides a way to track query performance over time. Query Store simplifies performance troubleshooting by helping you quickly find the longest running and most resource-intensive queries. Query Store automatically captures a history of queries and runtime statistics, and it retains them for your review. It separates data by time windows so that you can see database usage patterns. Data for all users, databases, and queries is stored in a database named azure_sys in the Azure Database for PostgreSQL instance.
Learn more about Query store here.

you can also view some usage scenario for Query Store and some Best Practices for Query Store.

 

2) Query Performance Insight
Query Performance Insight helps you to quickly identify what your longest running queries are, how they change over time, and what waits are affecting them.

3) Performance recommendations
Performance Recommendations feature analyses your databases to create customized suggestions for improved performance. To produce the recommendations, the analysis looks at various database characteristics including schema. Enable Query Store on your server to fully utilize the Performance Recommendations feature. After implementing any performance recommendation, you should test performance to evaluate the impact of those changes.

 

References: 

1) Performance updates and tuning best practices for using Azure Database for PostgreSQL

2) Performance best practices for using Azure Database for PostgreSQL

3) Improve Performance of Read Intensive Workloads on Azure DB for PostgreSQL using Query Caching

4) Set up Pgpool-II Query Caching with Azure Database for PostgreSQL

5) Steps to install and setup PgBouncer connection pooling proxy with Azure DB for PostgreSQL