Learn about databases
Databases hold your application's state. Compare the types and see how to host them, connect to them and protect your data.
Featured
- CostsHow much does database hosting cost?Cloud database hosting costs from zero to hundreds of dollars a month. See what sets the price: instance, disk, traffic, snapshots, and how to estimate yours.
- How-to guidesHow to host a database for your appTo host a database, pick an engine, create the instance, store the connection string in an environment variable and test the connection. Step-by-step guide.
- ConceptsWhat is Redis used for?Redis is an in-memory data store that keeps key-value pairs and rich data structures. Learn how it works, what it is used for and when not to use it.
Concepts6
- What is Redis used for?Redis is an in-memory data store that keeps key-value pairs and rich data structures. Learn how it works, what it is used for and when not to use it.
- What is PostgreSQL?PostgreSQL is an open source relational database that uses SQL and guarantees ACID transactions. Learn how it works, what it is for and when to pick another one.
- What is MongoDB and when to use itMongoDB is a NoSQL document database that stores data in JSON-like documents. Learn how it works, what it is good for, and when another database fits better.
- What is a database index and when to create oneAn index is a sorted structure, usually a B-tree, that finds rows without a full table read. When to add one, composite indexes and EXPLAIN in Postgres and MySQL.
- MongoDB collections, clusters and replica sets explainedA collection groups documents, a replica set is a group of servers holding copies of the same data, and a cluster is the whole set serving your database.
- What is MySQL?MySQL is an open source relational database that stores data in tables and queries it with SQL. See how it works, what it is used for and when to skip it.
How-to guides7
- How to host a database for your appTo host a database, pick an engine, create the instance, store the connection string in an environment variable and test the connection. Step-by-step guide.
- How to back up your databaseBack up MySQL, PostgreSQL and MongoDB with mysqldump, pg_dump and mongodump, then restore the dump. See the commands, how to verify and common mistakes.
- How to connect PostgreSQL to Node.js (pg and Prisma)Connect Node.js to PostgreSQL with pg or Prisma: one pool per process, the URL in an environment variable, and TLS that verifies the server against its CA.
- How to connect PostgreSQL to Python (psycopg and SQLAlchemy)Connect Python to PostgreSQL with psycopg or SQLAlchemy: one pool per process, the URL in an environment variable, TLS with verify-full and %s query parameters.
- How to migrate a database to another server (dump and restore)To migrate a database, stop writes, take a dump on the source, restore it on the new server and check the data before switching the URL. See the commands.
- How to connect MongoDB to Node.js (and to your hosting)To connect MongoDB to Node.js, install the official mongodb driver, create a MongoClient with your connection string and reuse that client. See the steps.
- Database migrations on deployRun database migrations on deploy with Prisma, Drizzle or Alembic: one step before the new code starts, safe against failures. Commands, checks and mistakes.
Problems and errors5
- self signed certificate in certificate chain: TLS errors when connecting to a databaseself signed certificate in certificate chain means your client doesn't trust the database's CA. Fix it in PostgreSQL, MySQL, MongoDB and Redis without disabling TLS.
- MongoServerSelectionError: why MongoDB won't connectMongoServerSelectionError means the driver found no usable MongoDB server in time. Learn the causes, how to diagnose each one and how to fix the connection.
- ECONNREFUSED: database connection refusedECONNREFUSED means nothing is listening on the database host and port. See the causes (server down, localhost, wrong port, bind address) and how to fix each one.
- Redis: ECONNRESET, Socket closed unexpectedly and connection timeoutsRedis ECONNRESET, Socket closed unexpectedly and timeouts come from idle connections closed, the wrong TLS scheme or client limits. Fix them in Node.js and Python.
- 'Too many connections': database connection pooling explained'Too many connections' means your database hit max_connections. Learn why it happens in MySQL and PostgreSQL, how to diagnose it, and how pooling fixes it.
Costs4
- How much does database hosting cost?Cloud database hosting costs from zero to hundreds of dollars a month. See what sets the price: instance, disk, traffic, snapshots, and how to estimate yours.
- How much does PostgreSQL hosting cost?PostgreSQL hosting costs from zero to hundreds of dollars a month. See what sets the price (RAM, disk, replicas, traffic), billing models and how to estimate yours.
- How much does Redis hosting cost?Redis hosting costs from zero to tens of dollars a month for small projects. The price comes from RAM, commands, persistence and replicas. Learn how to estimate it.
- How much does it cost to host MySQL?Hosting MySQL costs RAM, disk, backups and replicas; the Community server is free (GPL). See how RDS, Azure and a VPS bill, and how much disk the binary log takes.
Comparisons6
- PostgreSQL vs MySQLPostgreSQL is the safer default for new projects, and MySQL suits simple apps well. Compare SQL features, JSON, indexes, transactions and ecosystem.
- MongoDB vs PostgreSQL: which should you choose?MongoDB vs PostgreSQL compared: data model, joins, transactions, JSON, indexes and scaling, plus when each database is the better fit for your project.
- Redis as a cache vs as a databaseRedis as a cache holds disposable copies in RAM; as a database it needs persistence (RDB or AOF). See the differences, the config and when to use each mode.
- SQL vs NoSQL: which database to chooseSQL stores data in tables with relations and a fixed schema. NoSQL covers document, key-value and other models. See the differences and when to use each.
- MariaDB vs MySQL: differencesMariaDB vs MySQL? MariaDB is a fork of MySQL, and today the two diverge on JSON, versions, replication and features. See the table and when to use each.
- SQLite vs a database server: when to switchSQLite vs a database server like PostgreSQL or MySQL: how each handles writes, networks and size, with a side-by-side table and clear signs it is time to switch.
Which to choose4
- How to choose a database for your projectFor most projects, PostgreSQL or MySQL is enough. See when to pick MongoDB, Redis or SQLite instead, with clear criteria and a recommendation per scenario.
- Best database for Node.jsFor most Node.js projects, PostgreSQL is the safest choice. See when to use MySQL, MongoDB, Redis or SQLite instead, with drivers and code examples.
- Best database for PythonPostgreSQL is the safest choice for most Python projects, and SQLite is enough for scripts and small apps. See when MySQL, MongoDB or Redis make more sense.
- Prisma, Drizzle, TypeORM or Sequelize: which Node.js ORM to usePrisma and Drizzle are the natural picks for new TypeScript projects; TypeORM and Sequelize are still in use. Compare criteria, code and when raw SQL is enough.