r/Database • u/Minimum_Hour519 • 1h ago
r/Database • u/Zardotab • 12h ago
Advice on dealing with similar column patterns in schema design
When there is a similar sets of columns to include in a schema design, I see two issues that come up often, and disagreement on how to handle them. The first I'll call the "sub-type issue" and the second the "nesting issue". I wonder how different shops deal with each.
A recent example I encountered for the sub-type issue is an event tracking system where participants and witnesses are logged. Let's say there's a scuffle at the local mall and the mall cops have to document it. (Not actual domain, but close.) What you might call "key people" have many more columns associated with them, but "incidental people" just need a name and optional phone number.
My feeling is to make one table, "Participants" with with a Participant Type column (FK). But the primary DB architect decided on two tables: "Key Participants" and "Incidental Participants". In practice a person won't need to be switched between categories often; the few times it happens app users just delete the old record and create a new one. The architect's reasoning was this allows the schema to enforce required columns (not null), whereas a single table has to enforce such algorithmically, based on the Participant Type column. To me that seems kind of a weak reason because it complicates the schema. Your view? (If participants did hop categories often, then a single table would clearly be better.)
The second type, the "nesting issue" is that there is a primary location and potential secondary locations. An Event record is to have one and only one primary location, but can have many secondary. There's about 10 columns associated with a location. My feeling was to put both types in a Location table with a location-type column, but the architect instead decided to include those 10 columns in the Event table, to record the primary location. The others go into the Secondary Locations table. The architect claims it makes application programming easier because writing an event would only have to write or change one record instead of two, at least for the general Event form. Agree or disagree? What factors drive you toward one approach versus another? Thanks!
r/Database • u/AndreiLeIttu • 12h ago
I made a free tool for designing databases with friends in real time, would love some feedback
Hey everyone!
A few months ago my friends and I started building a project together, and the first thing we needed was the database. We wanted one diagram we could all edit at the same time, like a Google Doc, but everything we tried was either paid for collaboration or just annoying to use. I know there are already many similar tools. What I couldn't find was one where our whole group could edit the same diagram live, so I focused on that.
It's called Comodel → comodel.app
You draw your tables, keys and relationships on a canvas, and everyone you share it with can edit it live. You see each other's cursors and who's working on which table, so it actually feels like working on it together instead of passing screenshots around, which is also what we were looking for.
Some stuff it can do:
Share it like a Google Doc: send a link, or invite people as viewers or editors. Friends with the link don't even need an account
Leave comments on tables or columns ("should this be nullable?"), reply, and resolve them
All the usual database things: new tables, attribute defining, keys
Import an existing database from SQL (Postgres, MySQL, SQLite, SQL Server) or DBML, so you don't start from zero
Export to PostgreSQL, DBML, or a PNG/SVG image for docs and slides
Save versions and compare them, or see the migration SQL between two versions for you
A code view if you'd rather type than drag boxes around
You can also hook it up to an agent using MCP if you want an AI to read or edit your diagram
I'm building this pretty much on my own, so any feedback means a lot, whether something's confusing, missing or just broken. Thanks for checking it out! 🙂
r/Database • u/Pale_Ferret_8241 • 14h ago
Testing Row-Level Security and check-then-act race conditions under connection pooling in PostgreSQL 18
One limitation of standard per-test rolled-back transactions is that they can't catch concurrency bugs across separate pooled connections—uncommitted writes aren't visible to parallel workers, and session-level SET leaks across pooled checkouts.
In our multi-tenant Postgres 18 test suite, we separated sequential unit/CRUD tests from a dedicated set of 19 parallel integration checks that fire simultaneous queries across a constrained pool (max: 5) using Promise.allSettled:
- Interleaved tenant contexts: Firing parallel transactions with
SELECT set_config('app.current_tenant_id', $1, true)across different tenants on a small pool to verifySET LOCALresets cleanly on commit/rollback with zero cross-tenant leakage. - Parent-row locking vs. check-then-act: Comparing unguarded
SELECT count(*)checks againstSELECT ... FROM organizations WHERE id = $1 FOR UPDATEwhen concurrent requests try to claim the final seat or quota slot. - Webhook idempotency under duplicate delivery: Firing identical billing event IDs concurrently to confirm
23505unique-constraint handling cleanly short-circuits duplicate state transitions.
For those running multi-tenant Postgres in production with PgBouncer or transaction pooling, are you relying strictly on set_config(..., true) + RLS policies, or pairing it with separate database roles per service tier?
Context: Built this into B2B SaaS OS 2.0.0 (Next.js 16 + Postgres 18 multi-tenant starter with 131 tests & 19 concurrency checks for solo founders and dev agencies). If you want to click through the live workspace without signing up, the demo is here:https://www.andrady.co/demo(architecture & source athttps://www.andrady.co).
r/Database • u/Fun-Chicken6946 • 14h ago
Advent of SQL and NoSQL – 24 challenges leading up to Christmas
Happy Holidays, r/Database!
I've noticed that most Advent of SQL events are exclusively SQL-based, and NoSQL databases are usually left out.
This project was originally supposed to be SQL-only, but after roughly 2 years of working on VisuaLeaf, I managed to build an embeddable, MongoDB-compatible database that runs entirely on the frontend, allowing you to execute MongoDB queries and aggregation pipelines directly in your browser without a database server.
Somebody tampered with Santa's Nice List, and you're the North Pole's first-ever data elf.
That's the story behind Advent of SQL & NoSQL: 24 puzzles, one a day from December 1 to 24. Every day, you get a bit more of the story and a question to answer with a query: which toys to build first, which children flipped from nice to naughty overnight, whose badge was used on the night shift, who walked through which door and when. By Christmas Eve, you'll have worked out who did it and fixed the list.
You can solve the whole thing in one of four databases, following the same story and working with the same underlying data:
- SQLite
- DuckDB
- PostgreSQL
- MongoDB (mongosh, aggregation pipelines)
More details:
- Everything runs entirely in your browser. There's nothing to install, no backend database server, and nothing to connect to.
- Your answer gets checked instantly, against the data you see and against hidden datasets with different values. Reading the answer off the screen and hard-coding it won't pass.
- It gets harder as it goes. Early days cover basic filtering, grouping and joins. Later ones require window functions, recursive CTEs, relational division, advanced MongoDB aggregation pipelines and running totals.
- Database-specific data modeling. The MongoDB version isn't just SQL tables converted into collections. It uses embedded documents, arrays and aggregation patterns that you'd actually encounter when working with MongoDB.
- Hints and traps for each day, if you get stuck, plus a short "did you know" tip about your chosen database.
A new puzzle unlocks every day until Christmas Eve!
Pick your database here: https://visualeaf.com/advent-of-sql-and-nosql/
Completely free. No account, no installation, no database server needed.
I hope you all enjoy it, and happy holidays!
r/Database • u/Such_Badger9750 • 1d ago
Semantic Database applications
Hey all, relative newbie here, what might be some good applications for a large-scale, fast processing semantic database system? I've heard quant and military mentioned, but am unsure of where exactly it might fit into those fields. Any help/suggested use cases would be greatly appreciated.
r/Database • u/Fantastic_Wave1982 • 3d ago
Designing Data Intensive Applications in a Nutshell
sushantdhiman.devr/Database • u/ahmedshahid786 • 4d ago
Is migrating from MongoDB to PostgreSQL worth it?
TL;DR: Running an EdTech platform with 600K+ users on MongoDB. Our data is heavily relational, and while regular API queries perform well, complex analytical queries are becoming painful to write and execute. Considering migrating to PostgreSQL and looking for advice on migration and production hosting.
Current setup:
\- Node.js, MongoDB, and Mongoose.
\- MongoDB Atlas (fully managed).
\- 600K+ registered users and around 15K daily active users.
\- An EdTech platform somewhat similar to Udemy or Coursera.
When the backend's foundations were laid, I was a junior working primarily on the frontend, so I wasn't involved in the database decision. It's been 1 year since we've been building this product.
Something that has been bothering me for a while is that we're essentially treating MongoDB like a relational database.
\- Strict schemas and validations across collections.
\- Heavily relational data with references between collections.
\- Extensive use of aggregation pipelines and "$lookup".
\- Very little reliance on MongoDB's schema flexibility.
To be fair, MongoDB has served us well. Our indexes are in place, most endpoints perform well, and we haven't faced any critical performance issues.
However, complex analytical queries for internal dashboards are a different story. Some involve joining up to 10 collections, take over 60 seconds, or occasionally time out despite optimization. Writing and maintaining these aggregation pipelines is also becoming increasingly painful.
I've experimented with MongoDB's transactions but didn't particularly enjoy the experience. I'd also like stronger database level relational integrity and better transaction management.
I feel PostgreSQL would have been a more natural fit for our data model from the beginning.
What I'd like advice on:
- Is migration justified? Given that MongoDB works well for most of our workloads, would migrating to PostgreSQL be worth the effort, or should I address the analytical workload separately?
- Migration strategy: If I proceed, how should I approach migrating a live production database at this scale? Any articles, case studies, or resources would be appreciated.
- PostgreSQL hosting: One thing I genuinely appreciate about MongoDB Atlas is how little I have to worry about infrastructure, backups, updates, and maintenance. What's the equivalent experience for PostgreSQL?
- Self-hosted vs. managed: How do you guys run PostgreSQL in production? Do you self-host it on a private EC2 instance or use something like AWS RDS, Neon, or another managed provider?
I've worked with relational databases on smaller projects, but never operated PostgreSQL in production at this scale.
I don't want to migrate just because I prefer PostgreSQL, but I also don't want to ignore what might be a fundamental architectural mismatch simply because things work today.
Would love to your thoughts and suggestions on this!
r/Database • u/invalidpath • 4d ago
I needed a distributed DB solution, found Pigsty
reddit.comr/Database • u/boganmax666 • 5d ago
be honest how many tools sit between your agent and a safe copy of prod?
so where does it break for you: test environments, agent state, or branching? and what would a single Postgres platform have to prove before you'd consolidate onto it?
r/Database • u/AtmosphereOk8390 • 5d ago
What are the best spreadsheet-style databases for our team who run 40 excel files?
I work at a logistics company, and our ops team runs on about 40 Excel files that link to each other. For additional context, around 150 people touch them every week.
Based on our experience, permissions are what drive us crazy. You either see the whole file or nothing. Last month, someone in the sales department saw salary data by accident.
From your observation, which tools keep the spreadsheet feel but use real linked tables? And can they see their own region's and nothing else?
r/Database • u/vlavrynovych • 6d ago
How does your team get database migrations from a code change to production - and what still goes wrong?
I’m interested in how database migrations work in real production workflows, beyond which tool a team uses. I’d like to compare how teams handle testing, deployment, compatibility, and recovery.
For a typical application database change:
- Where do migration scripts live, and are they handwritten, generated, or a mix?
- When do they run: as a CI/CD job, during deployment, at application startup, or manually?
- How are they tested before production, especially when they change or backfill existing data?
- How do you handle old and new application versions running during the same deployment?
- If a migration fails part-way through, how do you recover and reconcile the migration’s recorded status?
Which part causes the most trouble in your experience? If useful, mention the database, stack, and migration tool.
r/Database • u/scotterockaroo • 7d ago
PITR a 5 TB Postgres database in 5 seconds.
reddit.comr/Database • u/Spiritual_Ganache453 • 7d ago
Will ERDs survive in the age of AI?
It was my belief in the beginning of 2025 that ERDs are helpful for writing code. If you look at the picture you can see that visuals are rendered specifically for ppl.
Given AI development advances with the same pace how likely will projects as this survive in the next couple of years?
r/Database • u/thisismugisha • 8d ago
Text column is storing accented text weirdly
reddit.comr/Database • u/dothebackstab • 8d ago
How Neo4j built a graph database in 20 years and 10 weeks
r/Database • u/Ok-Motor-9812 • 10d ago
Our permissions migration passed its own checks. A full row compare still found 1 role seeing too much in prod
A migration rewrote the permission matrix of a multi-tenant app. It applied clean and its own probes passed.
Then we compared every row of the permissions table in prod against the local database where the matrix had been proven. One cell was off. A restricted role already had a grant to see its peers' records, live, from before this task even started. The migration never touched that row, so its checks never looked at it.
Since then the check after deploy compares the whole table against the proven copy, not only the rows the migration wrote.
r/Database • u/VIqbang • 10d ago
My static site has a database. It’s ClickHouse’s
I had to rebuild my site. And then search was necessary...working out how to do this using ClickHouse playground was a fun little exercise.
r/Database • u/aksgolu • 11d ago
A free browser playground for running real database queries, no setup
For anyone starting out, or teaching someone who is: DBA Genesis Playground lets you write and run queries in your browser against a real database.
It opens with a small sample table, so you can go straight to SELECT, INSERT, UPDATE and ALTER TABLE without configuring anything. SQL and NoSQL databases are both available.
We're running a free 21-day challenge on it right now (#21DaysOfSQL).
Try it: dbagenesis.com/playground
r/Database • u/dubvoyage • 12d ago
DigitalOcean, this is not how you launch an "Advanced" Postgres database...
Hey guys, for those of you using DigitalOcean: you may or may not know they're phasing out the Standard-tier Postgres plans in favour of a new Advanced tier on November 30.
Naturally, I benchmarked both to see if there was a difference. The results were so atrocious they defied my belief.
- Up to 436% higher p99 write latency (6.7 ms → 35.9 ms).
- ~50%-70% fewer write and read throughput
the new tier tops out at ~54k reads/s & 6.9k writes/s, versus the old Standard tier's 204k reads/s & 26.5k writes/s max.
- 5x slower startup times: 3m 19s → 16m 06s, averaged across 15 regions.
The results were averaged over 3 runs per DB, for all possible DB sizes (2->32vCPU).
This was done over two weeks of testing, running around 60 hours of wall-clock time and going through 100+ databases. It cost me a few hundred dollars to run.
If interested, I posted the full results & methodology on my blog post.
I believe the bottleneck is a fixed-process PgBouncer deployment. But I don't consider myself an expert in databases so would really appreciate if you could double-check my logic.
r/Database • u/Constant_Guidance_47 • 13d ago
Python/SQLite on Windows: slow local checks, a failure before HTTP, and a multiprocessing startup hang
reddit.comr/Database • u/shrapknife • 13d ago
Our AI worker retried a subscription limit 900 times. Here's what we learned.
reddit.comr/Database • u/SpaceHomeless69 • 13d ago
Secondary data warehouse
We are looking for a simple secondary data warehouse...
We are not IT professionals, and we do not want to hire an external expert for every single task.
We need an application designed for individuals with a general understanding of IT.
We intend to use this secondary data store to cross-reference data from various sources, perform simple calculations, and send cleaned data to secondary applications.
Requirements:
- 90% of our data is in MS SQL.
- We need simple, direct integration with MS SQL (IP, port, password), the ability to select tables to transfer to the secondary data store, and the option to set a refresh frequency...
The secondary data warehouse must include:
- The ability to create simple queries, apply filters, and establish relationships between tables...
- The ability to easily integrate with external applications (CRM, BI, AI agents, reporting, etc.)...
What do you recommend?
