Friday, January 31, 2025

Database Performance Benchmarks: PostgreSQL 17 vs. PostgreSQL MySQL 9 vs. MongoDB 8

 

Database Performance Benchmarks: PostgreSQL 17 vs. PostgreSQL MySQL 9 vs. MongoDB 8

Hello readers, I'm a passionate fan of WEB full-stack development and Rust programming. If you also have a soft spot for Rust, welcome to follow my official account "Dream Beast Programming" and join our technical exchange group to discuss cutting-edge technologies.





In the database space in 2024, PostgreSQL 17, MySQL 9, and MongoDB 8 are the main contenders. Each database has its own unique features and performance optimizations, and understanding their pros and cons is essential to choosing the right tool.


Benchmark settings

For performance comparison, I used the Docker environment to build the latest versions of these three databases. The benchmark covers the following common operations:

  • • Single Insertion: Inserts data one by one.
  • • Batch Insertion: Insert multiple pieces of data at once.
  • • Query operation: Retrieve all data from the table.
  • • Delete Operation: Deletes all data in the table.

The test results are all 1,000 pieces of data to ensure fair comparisons across databases.

Test environment

Testing is conducted in the following environments to ensure consistent performance testing across databases:

  • • Operating System: Ubuntu 24.04.1 LTS (WSL)
  • • Hardware: Ryzen 5 5500U, 16GB RAM

Dockerfile and test code: Start PostgreSQL 17, MySQL 9.0, and MongoDB 8.0 with a Docker container and test the performance.


Single strip insertion



  1. 1. PostgreSQL 17:2317.83 ms
  2. 2. MySQL 9.0:5060.12 ms
  3. 3. MongoDB 8.0:1759.43 ms

Analysis: MongoDB performs best in single insert operations, probably due to its schemaless nature and optimized document model. PostgreSQL, while slightly slower, is still faster than MySQL.


Batch insertion



  1. 1. PostgreSQL 17:60.06 ms
  2. 2. MySQL 9.0:29.35 ms
  3. 3. MongoDB 8.0:28.99 ms

Analysis: MySQL and MongoDB are almost identical in terms of batch insert performance, with MySQL slightly ahead. PostgreSQL is relatively weak in this regard, but still provides decent performance.


Query operations



  1. 1. PostgreSQL 17:9.11 ms
  2. 2. MySQL 9.0:11.25 ms
  3. 3. MongoDB 8.0:52.63 ms

Analysis: PostgreSQL performs best in query operations thanks to its excellent query optimization and indexing capabilities. MySQL is also relatively fast to query, while MongoDB's document model is slower in this regard.

Delete the action



  1. 1. PostgreSQL 17:4.70 ms
  2. 2. MySQL 9.0:23.96 ms
  3. 3. MongoDB 8.0:23.52 ms

Analysis: PostgreSQL performed well in the deletion operation with a time of only 4.70 ms. MySQL and MongoDB behave similarly, indicating that PostgreSQL is more optimized for deletion tasks.

Key Summary:

  • • PostgreSQL 17: Excellent performance in query and delete operations, suitable for applications that require high data retrieval and cleanup speeds.
  • • MySQL 9.0: Excellent performance in batch insertion, suitable for scenarios that need to process large amounts of data quickly.
  • • MongoDB 8.0: Leads in single-insert performance, but lags behind MySQL in queries and bulk inserts.

conclusion

Each database has its own unique advantages, and choosing the right one depends on the specific use case:

  • • If fast reads and data consistency are important to you, PostgreSQL 17 is the best choice.
  • • If efficient data ingestion and batch processing are required, MySQL 9.0 will be a good choice.
  • • For flexible schema design and quick insertion, MongoDB 8.0 may be more suitable.

Understanding the unique strengths and weaknesses of these databases will help you make informed decisions based on your application's performance needs.


No comments:

Post a Comment