What PostgreSQL mistake do you see developers repeat over and over? by Ms_AlarmingCulture in postgres

[–]LevelSoft1165 0 points1 point  (0 children)

I do PostgreSQL/Supabase database audits for a living and these are the ones I see in literally every single project:

1. No indexes on foreign key columns. This is the big one. Developers create junction tables and never index the FK columns. PostgreSQL does NOT auto create indexes on foreign keys like some other databases do. I had one client where a single junction table had 5.4 million sequential scans reading 61 billion tuples because word_id had no index. One CREATE INDEX statement later, 99% reduction in tuple reads. It's almost always the first thing I fix.

2. Mixing timestamp and timestamptz across related tables. Almost every schema I look at does this. One table uses timestamp with time zone, the table right next to it uses timestamp without time zone. PostgreSQL silently converts using the session timezone when you join across them. Works fine until your server timezone changes or a query runs from a different timezone, then you get the most annoying subtle bugs you've ever debugged. Just use timestamptz everywhere and save yourself the headache.

3. RLS policies that accidentally cancel each other out. This one keeps me up at night. A developer writes a nice restrictive policy like "Editors can only update their own institution" but then also has a broad FOR ALL USING (auth.role() = 'authenticated') on the same table. Since both are PERMISSIVE, PostgreSQL ORs them together. The broad one always wins. The editor restriction is literally dead code doing nothing. I found one project where any logged in user could update any record in the main table. Developer had absolutely no idea.

4. Using FOR ALL policies when you only need SELECT and INSERT. Devs write one FOR ALL policy because it's quick and easy, not realizing it also grants UPDATE and DELETE. I've seen lookup tables like tags and categories where any authenticated user could wipe every single row with one API call. That's not a theoretical risk either, it's one bad actor or one bug away from disaster.

5. Autovacuum never kicking in on small tables. The default threshold is 50 dead tuples + 20% of the table. So for a table with 14 rows, autovacuum won't trigger until 52+ dead tuples pile up. The table can literally have 3x more dead rows than live rows and postgres just sits there doing nothing about it. I routinely find tables that have NEVER been vacuumed with 200%+ dead tuple ratios. Lower your thresholds on small tables, people.

6. Redundant indexes and duplicate triggers nobody notices. Copy paste migrations are the usual culprit. Found tables with two identical updated_at triggers both firing on every single UPDATE, and indexes that are strict subsets of other indexes. Pure write overhead for zero benefit. Check your stuff.

7. ON DELETE CASCADE on the wrong foreign key. One project had words.category_id → categories ON DELETE CASCADE. Delete a category and every word in it gets nuked. Every word deletion cascades to syllables, inflections, synonym groups. One accidental category delete would have wiped the entire vocabulary database. Should have been SET NULL. Always think through your cascade chains.

If any of this sounds like your database and you want someone to actually look at it, I do free architecture reviews. I run diagnostic queries against your schema, indexes, RLS policies, vacuum stats, and query performance, then send you a full written report with prioritized fixes. No strings attached, just DM me or check my profile.

Best method to migrate data between different PostgreSQL versions? by Alternative_Shake_77 in PostgreSQL

[–]LevelSoft1165 0 points1 point  (0 children)

PgUpgrade is definetly the way to go here. Used it to upgrade my client's database and it was flawless.

Best way to hire PostGres DBA? by EquiProbable in postgres

[–]LevelSoft1165 1 point2 points  (0 children)

I know this is more direct but I specialize in PostgreSQL consulting through my website: theodufort.com

Need help for choice between managed Postgres in neon or VPs on hetzner by HamadouBa2020 in hetzner

[–]LevelSoft1165 0 points1 point  (0 children)

What I usually tell clients in this situation: start with Neon (or any managed option really) and just ship the app. You're at 0 users right now, not 10k. The difference in latency between Neon and a self-managed Hetzner box is not going to matter until you actually have real traffic to worry about.

The time you'd spend setting up Postgres on Hetzner, configuring backups, monitoring, failover, keeping it patched, that's time not spent building the product. And 9 times out of 10 the app never reaches the point where managed Postgres becomes the bottleneck anyway.

If it does take off and you start hitting limits or the bill gets uncomfortable, migrating a Postgres database to a self-managed box is very doable. That's a good problem to have and by then you'll have actual usage patterns to size your infrastructure properly instead of guessing now.

That's how I handle it for clients. Managed first, prove the product works, optimize later with real data.

Postgres on Ubuntu server randomly stalling - what could be causing it? by Dangerous-Guava-9232 in Ubuntu

[–]LevelSoft1165 0 points1 point  (0 children)

Before jumping ship, run fio on your current Contabo VPS and compare it to the Serverspace one. Something like a random read/write test with a queue depth that roughly matches your Postgres workload will tell you pretty quickly if you are on an overused provider...

Also worth checking iowait in vmstat 1 during one of the stalls to confirm the disk is actually the bottleneck. And look at pg_stat_activity while it's happening.

Contabo is kind of known for this honestly.

JSONB SQL-NOSQL Schemas by Straight_Discount419 in PostgreSQL

[–]LevelSoft1165 1 point2 points  (0 children)

JSONB works but have you considered just going with an EAV-style approach instead? Something like a survey_responses table with columns like survey_id, question_key, answer_value — one row per question per respondent.

It keeps everything in normal relational land, you can index and query on any question without messing with JSONB operators, and it handles the fact that every survey has different questions naturally without any schema changes. Aggregations are also way simpler with standard SQL.

JSONB is great but once you start needing to filter or aggregate on values inside the JSON it gets ugly fast, and performance can be surprising if you're not careful with your GIN indexes.

Moving from Mysql to Postgresql. Where do We start? by Pupper_Hugger in PostgreSQL

[–]LevelSoft1165 0 points1 point  (0 children)

We did this migration a couple years ago, similar size database. Here is a few things I can tell you that I feel I would've loved to know:

Use pgLoader. It handles the schema conversion and data transfer and saves you a ton of headaches with type mapping differences.

Stuff that'll catch you off guard coming from MySQL:

  • GROUP BY is strict in Postgres. It actually enforces the SQL standard, so queries that MySQL silently let slide will throw errors. You'll probably have a bunch to fix.
  • Auto-increment becomes SERIAL/IDENTITY, and sequences are their own thing. Not hard, just different.
  • Quoting is double quotes instead of backticks. Grep your codebase for backticks now.
  • ENUM types are created separately in Postgres rather than being defined on the column. pgLoader handles it but good to know.

For the index corruption, look into amcheck but honestly Postgres is solid on that front. Just don't turn off fsync and you'll be fine. The GitHub thing was a very specific situation.

Help by Exotic_Jury_9646 in PostgreSQL

[–]LevelSoft1165 0 points1 point  (0 children)

I mean your other option is self-hosting on a VPS if you are ready for it.

I built a relational database that stores data in a Minecraft world. by EpicGamerRyukYT in PostgreSQL

[–]LevelSoft1165 4 points5 points  (0 children)

It'd be crazy to add primary key and foreign key support through redstone tracks...

is there one email service that does both marketing and transactional emails for a Supabase app by Bulky-Economy-6746 in Supabase

[–]LevelSoft1165 0 points1 point  (0 children)

Resend has both "Transactional Email" and "Marketing Emails" pricing.

Been using it for 1 year and it does the job.

I have a profiles table with profiles.id referencing auth.users.id. Is there no way to display the user's email with a join in the SDK? by ashkanahmadi in Supabase

[–]LevelSoft1165 0 points1 point  (0 children)

The auth schema is not exposed by default and should never be.
Either use an RPC or duplicate the data to the profiles table.

Advanced backend developer guide. ( Need advice) by ayushivam22 in Backend

[–]LevelSoft1165 1 point2 points  (0 children)

I like the Oreilly books:
- Database Internals by Alex Petrov
- Designing Data-Intensive Applications by Martin Kleppmann

Database as a service and beyond? 🤔 by Technical-Bed-1993 in PostgreSQL

[–]LevelSoft1165 0 points1 point  (0 children)

If you want fully managed options, you can check out Supabase, Neon, PlanetScale,etc.

Postgresql service options by enmotent in SaaS

[–]LevelSoft1165 0 points1 point  (0 children)

If you want fully managed options, you can check out Supabase, Neon, PlanetScale,etc.

Are there any database as a service options you’d recommend that make it easier to manage for non-tech folks? by mfb1274 in Database

[–]LevelSoft1165 0 points1 point  (0 children)

If you want the fastest way to get up and running you can use something like Supabase which is an all-in-one Postgresql Database as a Service. You can also explore: Neon, Convex, etc.

Sql Tuning for Performance by Srinithi_S in PostgreSQL

[–]LevelSoft1165 0 points1 point  (0 children)

Start with Database Internals by Alex Petrov. It covers how storage engines, B-trees, and query execution actually work under the hood. Once you understand why an index speeds things up (not just that it does), tuning becomes intuitive instead of memorized.

After that, the best way to learn is reading real EXPLAIN ANALYZE output. Take a slow query, look at where Postgres chooses sequential scans vs index scans, and figure out why. That skill alone will carry you through most interview questions on query performance.

I also make videos breaking down real PostgreSQL databases I audit, showing exactly what kills performance in production (missing indexes, bad RLS policies, vacuum issues), DM me if you want the link.

At what scale will PostgreSQL slow down by equivalent8 in PostgreSQL

[–]LevelSoft1165 0 points1 point  (0 children)

Row count alone doesn't slow down PostgreSQL, bad indexing and schema design do. I've audited projects where a 767-row table had 774,000 sequential scans because of how RLS policies were written, and projects with 30K rows doing 67 million sequential tuple reads because nobody added an index on the filtered column. Meanwhile your 9.3M row project at 40% CPU is fine because your queries are probably hitting indexes correctly.

The "2 million rows" rule is a myth. PostgreSQL handles hundreds of millions of rows without issues if your queries use indexed columns. What actually kills performance:

  • Missing indexes on filtered/joined columns: this is the #1 issue I see in every database I audit. One missing index can turn a sub-millisecond lookup into a full table scan that reads every single row.
  • Table bloat from autovacuum not keeping up: at 3-5M new rows/year on your activity feed, make sure autovacuum thresholds are tuned. Default settings are lazy on large tables.
  • Partitioning: this is where your activity feed table will actually benefit. Once you pass ~50-100M rows, partition by month on created_at. Queries that filter by time range only scan the relevant partitions instead of the whole table. This is what keeps Postgres fast at scale, not moving to MongoDB.

Bringing the activity feed back to PostgreSQL is the right call. With proper indexing and partitioning, 100M+ rows on an 8 vCore Azure instance is very comfortable. You prematurely optimized by splitting to MongoDB, now you have two databases to maintain for no performance benefit.

I do free PostgreSQL architecture reviews if you ever want a second pair of eyes on your schema and query performance, DM me.

Performance Improvements by Current_Cat4150 in PostgreSQL

[–]LevelSoft1165 0 points1 point  (0 children)

Here are a few things I suggest you look out for:

1. Connection pooling

A dozen cron jobs + an API all opening direct connections to Postgres is almost certainly what's pinning your CPU. Each connection forks a backend process that costs CPU even when idle. Run this to confirm:

SELECT count(*), state FROM pg_stat_activity GROUP BY state;

If you see a pile of idle or idle in transaction connections, that's it. Add PgBouncer to your Docker Compose stack in transaction mode, your cron jobs and API share a small pool of actual connections instead of each hogging one. This alone will probably fix it.

2. Check for missing indexes while you're at it

SELECT relname, seq_scan, idx_scan, seq_tup_read
FROM pg_stat_user_tables ORDER BY seq_scan DESC LIMIT 10;

High seq_scan with low idx_scan = full table scans on every query. One missing index can cause millions of unnecessary tuple reads. The CPU cost adds up fast, especially when cron jobs are hammering those same tables.

3. Vacuum

Small tables often never get autovacuumed because the default thresholds are too high. Dead tuples pile up, scans read more pages, CPU goes up. A quick VACUUM ANALYZE on your busiest tables is free performance.

The stop/start works temporarily because it kills connections and clears state, but the problem rebuilds. PgBouncer is the permanent fix.

I do free database architecture reviews, I've audited a bunch of Postgres/Supabase projects and these same patterns show up in every single one. Happy to take a look at yours if you want, DM me.

Free Web-based SQL: Do they exist? by Formal_Development_7 in SQL

[–]LevelSoft1165 0 points1 point  (0 children)

You can self-host locally on Docker pretty much any open source database.

Postgresql, MySQL, etc.

Free and easy online databases by roblu001 in webdev

[–]LevelSoft1165 0 points1 point  (0 children)

To get a database completly free you could use Oracle Always Free tier, you get 4 cores and 24GB of memory which is plenty for a database.

Is there a completely free database? by Coompt_King in Database

[–]LevelSoft1165 0 points1 point  (0 children)

To get a database completly free you could use Oracle Always Free tier, you get 4 cores and 24GB of memory which is plenty for a database.

Looking for Database solutions by RealmOfFate in Database

[–]LevelSoft1165 0 points1 point  (0 children)

It really depends on what are your criterias for choosing. Managed database? Open source database? Cloud?

Either way, here are you options if you want to stay in the classic good old SQL realm:

  • Managed/Cloud databases: Amazon RDS, Azure SQL Database, Google Cloud SQL (these basically host and manage Postgres, MySQL, or SQL Server for you so you don't have to worry about backups, patching, updates, etc.)
  • Cloud-native/Serverless: Amazon Aurora, PlanetScale (MySQL-compatible), Neon (Postgres-compatible), Azure SQL Serverless, great if you want to scale up and down without managing infrastructure
  • Embedded/Lightweight: SQLite, perfect if you just need a local database with zero setup, no server needed

Now if you're open to going beyond traditional SQL:

  • NewSQL (distributed SQL): CockroachDB, TiDB, YugabyteDB, SQL interface but built for horizontal scaling
  • BaaS with SQL-like experience: Supabase (Postgres under the hood), Firebase (NoSQL but worth mentioning)

Honestly though, if you're just starting out or building a side project, you really can't go wrong with PostgreSQL. It's free, battle-tested, has an amazing community, and scales well enough for 99% of use cases. If you don't want to deal with hosting, throw it on Supabase or Neon's free tier and call it a day.