This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Cache hit ratio. | |
-- Sweet spot here are values close to 100 which also means all necessary data were read from shared buffers. | |
-- values near 90 or lower show that postgres read from disk time to time. | |
SELECT | |
round(100 * sum(blks_hit) / sum(blks_hit + blks_read), 3) as cache_hit_ratio | |
FROM pg_stat_database; | |
-- estimate commit ratio and detect errors | |
-- values that are closer to 100 mean that you database has very few errors. | |
SELECT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- tested with postgres13. Lower versions may need tweaks. | |
-- Top 20 cpu heavy queries | |
SELECT | |
query AS short_query, | |
round((total_plan_time + total_exec_time)::numeric, 2), | |
calls, | |
rows, | |
round((total_plan_time + total_exec_time)::numeric / calls, 2) AS avg_time, | |
round((100 * (total_plan_time + total_exec_time) / sum((total_plan_time + total_exec_time)::numeric) OVER ())::numeric, 2) AS percentage_cpu |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Temporary file usage by database | |
SELECT datname AS "database", temp_files AS "Temporary files", temp_bytes | |
AS "Size of temporary files" | |
FROM pg_stat_database; | |
-- Cache Hit Ratio. Anything greater than 90% is always good | |
SELECT sum(blks_hit)*100/sum(blks_hit+blks_read) AS hit_ratio FROM pg_stat_database; | |
-- Top Queries | |
SELECT substr(query, 0, 250), calls, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example.springboot.config; | |
import javax.annotation.PostConstruct; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.beans.BeansException; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example.springboot.config; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | |
import org.springframework.cloud.context.config.annotation.RefreshScope; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import com.amazonaws.auth.AWSCredentials; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example.springboot.config; | |
import static example.springboot.config.AwsConfigurationProperties.PREFIX; | |
import org.springframework.boot.context.properties.ConfigurationProperties; | |
import org.springframework.stereotype.Component; | |
/** | |
* Sample ConfigurationProperties for AWS STS | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example with a hashmap to demonstrate how we could end up missing hashmap entries | |
// under concurrent modification. | |
package test; | |
import java.util.HashMap; | |
public class MapTestTask implements Runnable { | |
private static HashMap<Object, Object> hashMap; |