Postgres Performance Cheatsheet

Simple steps to improve performance in a Postgres database. Identify your problem queries SELECT query, round(total_time::numeric, 2) AS total_time, calls, round(mean_time::numeric, 2) AS mean, round((100 * total_time / sum(total_time::numeric) OVER ())::numeric, 2) AS percentage_cpu FROM pg_stat_statements where query != ” ORDER BY total_time DESC LIMIT 20; Enable the pg_stat_statements module if it isn’t already. Try […]

Manage your npm dependencies using VS Code and Version Lens

Once you have installed a dependency and its doing its job you can forget it exists. Apart from a line in your package.json there isn’t much to remind you that its even there. Its easy to never update it meaning you miss out on bug and security fixes. Version Lens is a thoroughly brilliant extension […]

An ‘order by’ tweak for better/worse query performance

Imagine this if the query used to retrieve a listing of books for your website. select id, date_published from books order by date_published desc If there happen to be multiple books with precisely the same date_published their order is clearly defined. They will tend to come out of the database in the same order but […]

Restore a database backup into a Postgres Docker container

Lets say you have a Postgres database running in a Docker container and you want to restore an sql database backup into it. If you have Postgres installed locally you will have psql available on your machine. If you don’t have Postgres locally installed its a little more tricky. cat databaseBackup.sql | docker exec -i […]

React Error Boundaries and Javascript Scope

React 16 introduced the concept of an error boundary. Official docs about error boundaries Any React component becomes an error boundary by defining a componentDidCatch(error, info) method. componentDidCatch() will be called if any of the component’s children throw an error. It is the declarative equivalent of a try catch in imperative code. I’m a big […]