PostgreSQL vs MySQL: which database should your Indian startup choose?
10 min read · 25-Nov-2024
villagehosting.in team
25 November 2024
MySQL ships with most shared hosting. PostgreSQL is preferred for complex applications. If you are starting fresh, here is how to decide — and what to consider before committing to one.
WordPress uses MySQL — this guide is for custom application databases
If you're running WordPress, WooCommerce, or any off-the-shelf CMS, the choice is made for you: MySQL/MariaDB. This guide is for developers building custom applications where you choose the database technology. WordPress is not a consideration here.
The short answer
Choose MySQL/MariaDB if: you're running WordPress, Drupal, or any CMS. You want the broadest shared hosting compatibility. Your team knows MySQL and you're not using advanced database features.
Choose PostgreSQL if: you're building a custom application with complex queries, JSON documents, full-text search, or geospatial data. You need strict ACID compliance. You're using ORMs like SQLAlchemy, ActiveRecord, or Django ORM.
Background
Both are mature, open-source relational databases. MySQL was created in 1995 by a Swedish company, acquired by Sun, then Oracle. PostgreSQL (Postgres) started at UC Berkeley in 1986 and is maintained by an independent open-source community.
In India, MySQL dominates shared hosting because cPanel's default stack is LAMP (Linux, Apache, MySQL, PHP). PostgreSQL is dominant in custom application development, particularly with Python/Django, Ruby on Rails, and Go backends.
Performance comparison
Neither is definitively faster. Performance depends on your workload:
MySQL/MariaDB is faster for:
- Simple SELECT queries on large tables (especially with InnoDB)
- Read-heavy workloads with minimal joins
- WordPress and PHP CMS applications
PostgreSQL is faster for:
- Complex queries with multiple JOINs
- Concurrent writes with row-level locking
- Aggregation queries and analytical workloads
For a typical Indian SaaS application at 10,000–100,000 users, both databases will handle the load comfortably on a ₹1,499/mo VPS. The performance difference matters at much higher scales.
JSON support
PostgreSQL has the clear advantage here.
PostgreSQL JSON/JSONB:
-- Store and query JSON natively
SELECT data->>'name', data->'address'->>'city'
FROM users
WHERE data->>'state' = 'Tamil Nadu';
-- Index on JSON field
CREATE INDEX ON users USING GIN (data jsonb_path_ops);
PostgreSQL's JSONB type stores JSON in binary format — indexed, queryable, and fast.
MySQL JSON: MySQL added JSON support in 5.7 and improved it in 8.0. It works but the query syntax is less elegant and indexing is more limited.
If you're storing flexible or schema-less data, PostgreSQL is the right choice.
Full-text search
Both support full-text search, but with different approaches.
PostgreSQL:
-- Native tsvector support with Indian language support via unaccent
SELECT title FROM articles
WHERE to_tsvector('english', content) @@ to_tsquery('hosting & india');
-- Add GIN index
CREATE INDEX ON articles USING GIN (to_tsvector('english', content));
PostgreSQL full-text search is genuinely usable for moderate search volumes without adding Elasticsearch.
MySQL: MySQL FULLTEXT indexes work well for English text but have more limitations with complex queries and ranking.
For a blog or product catalogue with basic search, MySQL is fine. For complex search requirements, PostgreSQL or Elasticsearch.
Geospatial data
PostgreSQL with PostGIS extension is the industry standard for geospatial applications. If you're building anything involving maps, delivery routing, location-based search, or store locators, PostgreSQL + PostGIS is the answer.
MySQL has spatial support but PostGIS is significantly more capable.
Strict SQL compliance
PostgreSQL enforces SQL standards strictly. MySQL in its default mode is lenient:
-- This works in MySQL (silently truncates text):
INSERT INTO users (name) VALUES ('A very long string that exceeds the column length');
-- PostgreSQL throws an error:
-- ERROR: value too long for type character varying(50)
PostgreSQL's strictness catches bugs early. MySQL's leniency can hide data integrity problems.
Concurrency
PostgreSQL uses MVCC (Multi-Version Concurrency Control) with no read locks — readers and writers don't block each other. This gives PostgreSQL an edge in write-heavy concurrent workloads.
MySQL's InnoDB also uses MVCC, but PostgreSQL's implementation handles high concurrency more gracefully at large scales.
ORM compatibility
Both databases work with every major ORM:
| ORM | MySQL | PostgreSQL |
|---|---|---|
| Django ORM | ✓ | ✓ (default preferred) |
| SQLAlchemy | ✓ | ✓ |
| Prisma | ✓ | ✓ |
| ActiveRecord | ✓ | ✓ |
| Sequelize | ✓ | ✓ |
| TypeORM | ✓ | ✓ |
Django's documentation treats PostgreSQL as the primary database and MySQL as secondary.
Hosting availability in India
MySQL: Available on all Indian shared hosting, all VPS, cPanel by default, RDS MySQL, PlanetScale.
PostgreSQL: Not available on Indian shared hosting (requires VPS or above). Available on VPS (self-managed), managed PostgreSQL services (Supabase, Neon, AWS RDS).
If you're on shared hosting, MySQL is your only practical option.
Migration between databases
Migrating from MySQL to PostgreSQL mid-project is painful. Schema differences (data types, case sensitivity, auto-increment syntax) require manual work. ORMs help but don't fully abstract the differences.
Make your decision before writing code, not after.
The pragmatic recommendation for Indian startups
Shared hosting: MySQL. No choice.
VPS + WordPress: MySQL.
VPS + Django/FastAPI/Rails/Node: PostgreSQL. The JSON support, full-text search, and strict compliance pay off as your application grows.
VPS + Laravel: MySQL. Laravel is built around MySQL and the ecosystem optimizes for it.
Custom analytics or data-heavy app: PostgreSQL. The aggregation performance and analytical query support are substantially better.
Both are excellent databases. The choice depends on your stack, not performance benchmarks at your current scale.