Dan's Tech (and more) Blog

Very infrequent posts about technology

Previous | Page: 1 of 2 | Next

Postgres Lock Queues, Migrations, and Timeouts

April 19, 2024 | (Last Update : April 19, 2024)
postgres Postgres Lock Queues, Migrations, and Timeouts

When Postgres operations obtain table-level locks, subsequent operations wait in a queue, but if there are any lock contentions in that queue, long-running queries have the potential to back everything up and can sometimes take down entire applications!

Read more...

ActiveRecord take vs first

April 08, 2024 | (Last Update : April 08, 2024)
ruby postgres rails active-record ActiveRecord `take` vs `first`

ActiveRecord has a method called take that returns a single record similar to first, except take doesn’t order the records before selecting one. This can GREATLY increase performance in some circumstances; the latency graph above shows a real-life example of take significantly reducing the duration of an api call by changing a single first to take.

Read more...

Numbered Block Params In Ruby

February 28, 2024 | (Last Update : February 28, 2024)
ruby Numbered Block Params In Ruby

Ruby 2.7 added some syntax sugar that has been making my life easier at work; no longer do I need to use a as my “placeholder” variable in enumerators, instead, we have a built in “numbered” block parameter!

Read more...

Postgres Enums: Don’t Use ‘Em

April 22, 2022 | (Last Update : April 22, 2022)
postgres enums database Postgres Enums: Don't Use 'Em

While Postgres offers an ENUM type, the general recommendation is NOT to use it, here I discuss why and give an alterative solution that I prefer: creating a new table and referencing foreign keys

Read more...

Using NOT in Postgres CHECK constraints

April 16, 2021 | (Last Update : April 16, 2021)
postgres Using `NOT` in Postgres `CHECK` constraints

For some reason I could not find good information on this (maybe because it’s obvious). But you can add NOT into your Postgres CHECK CONSTRAINTs; this is particularly useful when you find a nice succinct way to express the negation of the constraint you want.

Read more...

Ruby’s Partition Method: It Does What You Think.

October 03, 2020 | (Last Update : October 03, 2020)
ruby Ruby's Partition Method: It Does What You Think.

Ruby has a neat function in Enumerable called partition that can split the values in the enumerable into two partitions based arbitrary logic.

Read more...

Cancelling PostgreSQL Queries When HTTP Request Times Out

August 04, 2020 | (Last Update : August 04, 2020)
postgres rails active-record Cancelling PostgreSQL Queries When HTTP Request Times Out

During a recent effort at work to optimize database performance we found a bunch of queries which our Rails application triggered but, since the query took longer than our configured HTTP timeout, the transaction was later abandoned. We had initially thought that PgBouncer might have a setting to cancel queries after a request times-out, but that doesn’t seem to be a feature that PgBouncer Currently supports.

We want to cancel these queries to free-up database resources, especially in case we have db bottlenecks.

Read more...

ufw - Linux Firewall And How To Use It

July 24, 2020 | (Last Update : August 02, 2020)
do-k8s-node ubuntu linux k8s Heroku digital-ocean `ufw` - Linux Firewall And How To Use It

08-02-2020: Updated with how I setup UFW on my home server

I’ve been tinkering a bit with Digital Ocean (use my referral link to get $100 in Digital Ocean credit) and I’ve decided to move a small personal project from Heroku to a droplet running a small Kubernetes (k8s) cluster. I want to do this both to learn about setting up k8s (very useful since I work with it daily) and because Digital Ocean is cheaper than Heroku for my use-case.

This will be the first post in a series about setting up this single-node k8s cluster on a Digital Ocean droplet; check out the do-k8s-node tag to find the other posts in this series; I’ll also be adding links to the next post in the series as I write them.

This first post is about the firewall built into Ubuntu: ufw as well as why I want to move from Heroku to Digital Ocean.

Read more...

ActiveRecord.dup and constantize

July 16, 2020 | (Last Update : July 17, 2020)
active-record ruby Default post image

I’m still unsure how I want to use this blog and wether I intend on creating a separate section for these short “TIL” posts or if I want to keep them here, but for today I’m combining two TILs into a longer post. I’m also using this to experiment with a post not having an image associated with it; we’ll see if that bugs me and I end up changing it or not.

This week I’ve learned a bit about the limitations ActiveRecord’s dup function as well as how constantize works.

Read more...
Previous | Page: 1 of 2 | Next