Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Tuning PostgreSQL for High Write Throughput

8,413 views

Published on

This presentation covers a number of the way that you can tune PostgreSQL to better handle high write workloads. We will cover both application and database tuning methods as each type can have substantial benefits but can also interact in unexpected ways when you are operating at scale. On the application side we will look at write batching, use of GUID's, general index structure, the cost of additional indexes and impact of working set size. For the database we will see how wal compression, auto vacuum and checkpoint settings as well as a number of other configuration parameters can greatly affect the write performance of your database and application.

Published in: Technology
  • Thanks for the help. I also ordered from www.HelpWriting.net
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THE BOOK INTO AVAILABLE FORMAT (New Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://redirect.is/fyxsb0u } ......................................................................................................................... Download Full EPUB Ebook here { https://redirect.is/fyxsb0u } ......................................................................................................................... Download Full doc Ebook here { https://redirect.is/fyxsb0u } ......................................................................................................................... Download PDF EBOOK here { https://redirect.is/fyxsb0u } ......................................................................................................................... Download EPUB Ebook here { https://redirect.is/fyxsb0u } ......................................................................................................................... Download doc Ebook here { https://redirect.is/fyxsb0u } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THE can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THE is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBOOK .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookBOOK, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, EBOOK, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THE Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THE the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THE Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Check the source ⇒ www.HelpWriting.net ⇐ This site is really helped me out gave me relief from headaches. Good luck!
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • by filling out a short survey? ☺☺☺ https://dwz1.cc/DU3z4dss
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • The Most Effective Natural Breast Enlargement Techniques That Have Already Changed The Lives Of Over 7591 Women From 69 Countries Worldwide! ➜➜➜ https://t.cn/A6Liz7kD
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Tuning PostgreSQL for High Write Throughput

  1. 1. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Grant McAlister – Senior Principal Engineer – Amazon RDS Sept 2017 Tuning PostgreSQL for High Write Workloads
  2. 2. High Write Workloads? CLIENT Database Storage Single Insert/Update
  3. 3. High Write Workloads? CLIENT Database Storage Commit Latency Client Latency Single Insert/Update
  4. 4. High Write Workloads? CLIENT Database Storage Commit Latency Client Latency CLIENT Database Storage Single Insert/Update
  5. 5. High Write Workloads? CLIENT Database Storage Commit Latency Client Latency CLIENT Database Storage Commit Latency Client Latency Single Insert/Update Copy or Multi-Insert
  6. 6. High Write Workloads? CLIENT Database Storage Commit Latency Client Latency CLIENT Database Storage Commit Latency Client Latency Single Insert/Update Copy or Multi-Insert CLIENT Database Storage
  7. 7. High Write Workloads? CLIENT Database Storage Commit Latency Client Latency CLIENT Database Storage Commit Latency Client Latency Single Insert/Update Copy or Multi-Insert CLIENT Database Storage Commit Latency Many Clients T H R O U G H P U T
  8. 8. Insert Test Test Table • UUID PK – Random • ID int – Right Lean Sequence • VARCHAR(100) – Random • VARCHAR(50) – Small Set of Words • INT – Random • INT – Random (smaller set) • BOOLEAN – Random (50/50) • BOOLEAN – Somewhat Random (75/25) • Timestamp – Right Lean
  9. 9. 0 5,000 10,000 15,000 20,000 25,000 30,000 1 31 61 91 121 151 181 211 241 271 InsertsPerSecond Minutes Insert Workload- PostgreSQL 9.6 BASE Non Random GUID WHICH ONE WOULD YOU LIKE
  10. 10. Update Test Test Table • UUID PK – Random • ID int – Right Lean Sequence • VARCHAR(100) – Random • VARCHAR(50) – Small Set of Words • INT – Random • INT – Random (smaller set) • BOOLEAN – Random (50/50) • BOOLEAN – Somewhat Random (75/25) • Timestamp – Right Lean UPDATE #1 UPDATE #2
  11. 11. 3,729 3,949 4,871 4,302 9,177 10,290 17,158 - 5,000 10,000 15,000 20,000 TPS(2UpdatesperTransaction) Update Workload - PostgreSQL 9.6 BASE WAL Compression 16GB Max WAL Async Reduced Indexes Non Random GUID Aurora PostgreSQL WHICH ONE WOULD YOU LIKE
  12. 12. Parameter Tuning
  13. 13. Concurrency and Throughput – Log Buffer Queued Work Log Buffer Most Databases Storage
  14. 14. Concurrency and Throughput – Log Buffer Queued Work Log Buffer Most Databases Storage
  15. 15. Concurrency and Throughput – Log Buffer Queued Work Log Buffer Most Databases Storage
  16. 16. Concurrency and Throughput – Log Buffer Queued Work Log Buffer Most Databases Storage
  17. 17. Concurrency and Throughput – Log Buffer Queued Work Log Buffer Most Databases Storage
  18. 18. Concurrency and Throughput – Log Buffer Queued Work Log Buffer Most Databases Storage
  19. 19. Concurrency and Throughput – Log Buffer Queued Work Log Buffer Most Databases Storage
  20. 20. Full Page Writes Block in Memory PostgreSQL WAL
  21. 21. Full Page Writes Block in Memory PostgreSQL update t set y = 6; WAL
  22. 22. Full Page Writes Block in Memory PostgreSQL update t set y = 6; Full Block WAL
  23. 23. Full Page Writes Block in Memory PostgreSQL update t set y = 6; Full Block WAL
  24. 24. Full Page Writes Block in Memory PostgreSQL update t set y = 6; Checkpoint Datafile Full Block WAL
  25. 25. Full Page Writes Block in Memory PostgreSQL update t set y = 6; Checkpoint Datafile Full Block WAL Archive
  26. 26. Full Page Writes Block in Memory PostgreSQL update t set y = 6; Checkpoint Datafile Full Block WAL Archive 4K 4K 8K
  27. 27. Full Page Writes Block in Memory PostgreSQL update t set y = 6; Checkpoint Datafile Full Block WAL Archive 4K 4K 8K During crash recovery PostgreSQL uses the FPW block in the WAL to replace the bad checkpointed block
  28. 28. Full Page Writes Block in Memory PostgreSQL update t set y = 6; Checkpoint Datafile Full Block WAL Archive 4K 4K 8K During crash recovery PostgreSQL uses the FPW block in the WAL to replace the bad checkpointed block
  29. 29. WAL throughput – Dump of wal Btree d: INSERT_LEAF off 184, blkref #0: rel 1663/32772/32779 blk 300 Btree d: INSERT_LEAF off 110, blkref #0: rel 1663/32772/32784 blk 1092 Btree d: INSERT_LEAF off 41, blkref #0: rel 1663/32772/32782 blk 5752 Btree d: INSERT_LEAF off 40, blkref #0: rel 1663/32772/32782 blk 8000 Btree d: INSERT_LEAF off 89, blkref #0: rel 1663/32772/32779 blk 1757 Btree d: INSERT_LEAF off 363, blkref #0: rel 1663/32772/32781 blk 1355 Btree d: INSERT_LEAF off 77, blkref #0: rel 1663/32772/32783 blk 4 Btree d: INSERT_LEAF off 94, blkref #0: rel 1663/32772/32779 blk 2083 Btree d: INSERT_LEAF off 362, blkref #0: rel 1663/32772/32781 blk 1355 Btree d: INSERT_LEAF off 10, blkref #0: rel 1663/32772/32782 blk 7687 Btree d: INSERT_LEAF off 365, blkref #0: rel 1663/32772/32781 blk 1355 Btree d: INSERT_LEAF off 114, blkref #0: rel 1663/32772/32784 blk 791 Btree d: INSERT_LEAF off 2, blkref #0: rel 1663/32772/32783 blk 2213 Btree d: INSERT_LEAF off 2, blkref #0: rel 1663/32772/32785 blk 1639 Btree d: INSERT_LEAF off 209, blkref #0: rel 1663/32772/32784 blk 1433 Transaction d: COMMIT 2017-09-07 01:08:55.354810 UTC At the beginning of the run
  30. 30. WAL throughput – Dump of wal Btree d: INSERT_LEAF off 184, blkref #0: rel 1663/32772/32779 blk 300 Btree d: INSERT_LEAF off 110, blkref #0: rel 1663/32772/32784 blk 1092 Btree d: INSERT_LEAF off 41, blkref #0: rel 1663/32772/32782 blk 5752 Btree d: INSERT_LEAF off 40, blkref #0: rel 1663/32772/32782 blk 8000 Btree d: INSERT_LEAF off 89, blkref #0: rel 1663/32772/32779 blk 1757 Btree d: INSERT_LEAF off 363, blkref #0: rel 1663/32772/32781 blk 1355 Btree d: INSERT_LEAF off 77, blkref #0: rel 1663/32772/32783 blk 4 Btree d: INSERT_LEAF off 94, blkref #0: rel 1663/32772/32779 blk 2083 Btree d: INSERT_LEAF off 362, blkref #0: rel 1663/32772/32781 blk 1355 Btree d: INSERT_LEAF off 10, blkref #0: rel 1663/32772/32782 blk 7687 Btree d: INSERT_LEAF off 365, blkref #0: rel 1663/32772/32781 blk 1355 Btree d: INSERT_LEAF off 114, blkref #0: rel 1663/32772/32784 blk 791 Btree d: INSERT_LEAF off 2, blkref #0: rel 1663/32772/32783 blk 2213 Btree d: INSERT_LEAF off 2, blkref #0: rel 1663/32772/32785 blk 1639 Btree d: INSERT_LEAF off 209, blkref #0: rel 1663/32772/32784 blk 1433 Transaction d: COMMIT 2017-09-07 01:08:55.354810 UTC Btree d: INSERT_LEAF off 216, blkref #0: rel 1663/16395/16407 blk 14331 FPW Btree d: INSERT_LEAF off 123, blkref #0: rel 1663/16395/16406 blk 5 Btree d: INSERT_LEAF off 139, blkref #0: rel 1663/16395/16404 blk 25954 Btree d: INSERT_LEAF off 59, blkref #0: rel 1663/16395/16407 blk 17944 FPW Btree d: INSERT_LEAF off 45, blkref #0: rel 1663/16395/16408 blk 17 Btree d: INSERT_LEAF off 252, blkref #0: rel 1663/16395/16404 blk 25954 Btree d: INSERT_LEAF off 135, blkref #0: rel 1663/16395/16408 blk 7 Btree d: INSERT_LEAF off 5, blkref #0: rel 1663/16395/16405 blk 131373 FPW Btree d: INSERT_LEAF off 175, blkref #0: rel 1663/16395/16404 blk 25954 Btree d: INSERT_LEAF off 19, blkref #0: rel 1663/16395/16405 blk 40974 FPW Btree d: INSERT_LEAF off 2, blkref #0: rel 1663/16395/16409 blk 1 Btree d: INSERT_LEAF off 19, blkref #0: rel 1663/16395/16405 blk 143873 FPW Btree d: INSERT_LEAF off 123, blkref #0: rel 1663/16395/16406 blk 5 Btree d: INSERT_LEAF off 14, blkref #0: rel 1663/16395/16405 blk 37468 FPW Btree d: INSERT_LEAF off 2, blkref #0: rel 1663/16395/16409 blk 1 Btree d: INSERT_LEAF off 84, blkref #0: rel 1663/16395/16407 blk 2696 Btree d: INSERT_LEAF off 149, blkref #0: rel 1663/16395/16407 blk 1401 FPW Btree d: INSERT_LEAF off 2, blkref #0: rel 1663/16395/16406 blk 39718 Btree d: INSERT_LEAF off 2, blkref #0: rel 1663/16395/16410 blk 29411 Btree d: INSERT_LEAF off 2, blkref #0: rel 1663/16395/16408 blk 29370 Btree d: INSERT_LEAF off 123, blkref #0: rel 1663/16395/16406 blk 5 Btree d: INSERT_LEAF off 2, blkref #0: rel 1663/16395/16409 blk 1 Btree d: INSERT_LEAF off 24, blkref #0: rel 1663/16395/16405 blk 69991 FPW Transaction d: COMMIT 2017-09-07 01:04:32.650362 UTC At the beginning of the run Later in the run 1K vs 48K of data
  31. 31. WAL Compression Block in Memory update t set y = 6; Full Block WAL
  32. 32. WAL Compression Block in Memory update t set y = 6; WAL Compressed Block
  33. 33. WAL Compression Block in Memory update t set y = 6; WAL Compressed BlockCompressed Block
  34. 34. WAL Compression Block in Memory update t set y = 6; WAL Compressed BlockCompressed Block
  35. 35. WAL Compression Block in Memory update t set y = 6; WAL Compressed BlockCompressed Block
  36. 36. WAL Compression Block in Memory update t set y = 6; WAL Compressed BlockCompressed Block
  37. 37. WAL Compression Block in Memory update t set y = 6; WAL Compressed BlockCompressed Block
  38. 38. WAL Compression Block in Memory update t set y = 6; Block on Disk Checkpoint Datafile WAL Archive Compressed BlockCompressed Block Lot of Random Values = Poor Compression
  39. 39. 0 5,000 10,000 15,000 20,000 25,000 30,000 1 31 61 91 121 151 181 211 241 271 InsertsPerSecond Minutes Insert Workload- PostgreSQL 9.6 BASE WAL Compression
  40. 40. 3,729 3,949 4,871 4,302 9,177 10,290 17,158 - 5,000 10,000 15,000 20,000 TPS(2UpdatesperTransaction) Update Workload - PostgreSQL 9.6 BASE WAL Compression 16GB Max WAL Async Reduced Indexes Non Random GUID Aurora PostgreSQL
  41. 41. Why didn’t WAL compression help Regular – Average 5.7KB per FPW
  42. 42. Why didn’t WAL compression help Regular – Average 5.7KB per FPW Compressed – Average 5.2KB per FPW
  43. 43. Why didn’t WAL compression help Regular – Average 5.7KB per FPW Compressed – Average 5.2KB per FPW Random Data does not compress well
  44. 44. 0 5,000 10,000 15,000 20,000 25,000 30,000 1 31 61 91 121 151 181 211 241 271 InsertsPerSecond Minutes Insert Workload- PostgreSQL 9.6 BASE WAL Compression 16GB Max WAL max_wal_size=16GB More Blocks + Random Inserts = More FPW
  45. 45. Randomness and Size of the Data Assume 10K Random Updates per Second Assume checkpoint every 60 second Touch 10K x 60 = 600K blocks between checkpoints 1GB table is ~130K blocks - Touch every block 4 times 100GB table is 13M blocks - Low chance of same block touch
  46. 46. 3,729 3,949 4,871 4,302 9,177 10,290 17,158 - 5,000 10,000 15,000 20,000 TPS(2UpdatesperTransaction) Update Workload - PostgreSQL 9.6 BASE WAL Compression 16GB Max WAL Async Reduced Indexes Non Random GUID Aurora PostgreSQL
  47. 47. 3,729 3,949 4,871 4,302 9,177 10,290 17,158 - 5,000 10,000 15,000 20,000 TPS(2UpdatesperTransaction) Update Workload - PostgreSQL 9.6 BASE WAL Compression 16GB Max WAL Async Reduced Indexes Non Random GUID Aurora PostgreSQL What about ASYNC
  48. 48. Async Commit – Log Buffer Queued Work Log Buffer Most Databases Storage
  49. 49. Async Commit – Log Buffer Queued Work Log Buffer Most Databases StorageThese sessions no longer have to wait
  50. 50. Async Commit – Log Buffer Queued Work Log Buffer Most Databases StorageThese sessions no longer have to wait
  51. 51. Async Commit – Log Buffer Queued Work Log Buffer Most Databases StorageThese sessions no longer have to wait
  52. 52. Longer Checkpoints – Reduce FPW - BUT Default min_wal_size=256MB, max_wal_size=2GB recovery time = 3 seconds New min_wal_size=2GB, max_wal_size=16GB recovery time = 91 seconds
  53. 53. Non Parameter Tuning
  54. 54. 1- 200 1- 100 101- 200 1-50 51- 100 1-25 26- 50 51- 75 76- 100 101- 150 151- 200 101- 125 126- 150 151- 175 176- 200 Insert a Sequence Number into a B-tree
  55. 55. 1- 200 1- 100 101- 200 Insert 201 1-50 51- 100 1-25 26- 50 51- 75 76- 100 101- 150 151- 200 101- 125 126- 150 151- 175 176- 200 1- 201 101- 201 151- 201 176- 201 4 blocks loaded Insert a Sequence Number into a B-tree
  56. 56. 1- 200 1- 100 101- 200 Insert 201 1-50 51- 100 1-25 26- 50 51- 75 76- 100 101- 150 151- 200 101- 125 126- 150 151- 175 176- 200 Insert 202 1- 201 101- 201 151- 201 176- 201 1- 202 101- 202 151- 202 176- 202 4 blocks loaded Insert a Sequence Number into a B-tree 0 blocks loaded
  57. 57. 1- 200 1- 100 101- 200 Insert 201 1-50 51- 100 1-25 26- 50 51- 75 76- 100 101- 150 151- 200 101- 125 126- 150 151- 175 176- 200 Insert 202 1- 201 101- 201 151- 201 176- 201 1- 202 101- 202 151- 202 176- 202 4 blocks loaded Insert a Sequence Number into a B-tree 0 blocks loaded At least 1 FPW
  58. 58. 1- 200 1- 100 101- 200 Insert 124 1-50 51- 100 1-25 26- 50 51- 75 76- 100 101- 150 151- 200 101- 125 126- 150 151- 175 176- 200 1- 200 101- 200 101- 150 101- 125 4 blocks loaded Insert a Random value into a B-tree
  59. 59. 1- 200 1- 100 101- 200 Insert 124 1-50 51- 100 1-25 26- 50 51- 75 76- 100 101- 150 151- 200 101- 125 126- 150 151- 175 176- 200 Insert 99 1- 200 101- 200 101- 150 101- 125 4 blocks loaded 1- 100 51- 100 76- 100 3 blocks loaded Insert a Random value into a B-tree
  60. 60. 1- 200 1- 100 101- 200 Insert 124 1-50 51- 100 1-25 26- 50 51- 75 76- 100 101- 150 151- 200 101- 125 126- 150 151- 175 176- 200 Insert 99 1- 200 101- 200 101- 150 101- 125 4 blocks loaded 1- 100 51- 100 76- 100 3 blocks loaded Insert a Random value into a B-tree 151- 200 151- 200 2 blocks loaded Insert 161 At least 3 FPW
  61. 61. Remember those 9 Indexes – Cut it to 6 Test Table • UUID PK – Random • ID int – Right Lean Sequence • VARCHAR(100) – Random • VARCHAR(50) – Small Set of Words • INT – Random • INT – Random (smaller set) • BOOLEAN – Random (50/50) • BOOLEAN – Somewhat Random (75/25) • Timestamp – Right Lean Remove Index Remove Index Remove Index – Allows HOT Update
  62. 62. HOT (Heap-Only-Tuple) Update Not HOT a b f Indexes Heap a, b, c, d, e, f
  63. 63. HOT (Heap-Only-Tuple) Update Not HOT a b f Indexes Heap a, b, c, d, e, f a, b, c, d, e, f1
  64. 64. HOT (Heap-Only-Tuple) Update Not HOT a b f Indexes Heap a, b, c, d, e, f a, b, c, d, e, f1 a’ b’
  65. 65. HOT (Heap-Only-Tuple) Update Not HOT a b f Indexes Heap a, b, c, d, e, f a, b, c, d, e, f1 a’ b’ f1
  66. 66. HOT (Heap-Only-Tuple) Update Not HOT a b f Indexes Heap a, b, c, d, e, f a, b, c, d, e, f1 a’ b’ f1 a, b, c1, d, e, f
  67. 67. HOT (Heap-Only-Tuple) Update Not HOT a b f Indexes Heap a, b, c, d, e, f a, b, c, d, e, f1 a’ b’ f1 a, b, c1, d, e, f HOT a b f Indexes Heap a, b, c, d, e, f
  68. 68. HOT (Heap-Only-Tuple) Update Not HOT a b f Indexes Heap a, b, c, d, e, f a, b, c, d, e, f1 a’ b’ f1 a, b, c1, d, e, f HOT a b f Indexes Heap a, b, c, d, e, f a, b, c1, d, e, f
  69. 69. HOT (Heap-Only-Tuple) Update Not HOT a b f Indexes Heap a, b, c, d, e, f a, b, c, d, e, f1 a’ b’ f1 a, b, c1, d, e, f HOT a b f Indexes Heap a, b, c, d, e, f a, b, c1, d, e, f
  70. 70. HOT Updates – Looking at FPW in the logs HOT Updated Heap 14/ 68, , d: HOT_UPDATE off 19 xmax 2327993188 ; new off 3 xmax 0, blkref #0: rel 1663/41083/41086 blk 28 XLOG 0/ 3368, , d: FPI_FOR_HINT , blkref #0: rel 1663/41083/41092 blk 1492899 FPW Transaction 8/ 34, , d: COMMIT 2017-09-07 00:07:17.532647 UTC Non HOT Update Heap 14/ 75, , d: UPDATE off 67 xmax 2327993195 ; new off 7 xmax 0, blkref #0: rel 1663/41083/41086 blk 285 XLOG 0/ 2774, , d: FPI_FOR_HINT , blkref #0: rel 1663/41083/41090 blk 7039952 FPW Btree 2/ 120, , d: INSERT_LEAF off 17, blkref #0: rel 1663/41083/41090 blk 7039952 XLOG 0/ 3150, , d: FPI_FOR_HINT , blkref #0: rel 1663/41083/41092 blk 29 FPW Btree 2/ 64, , d: INSERT_LEAF off 205, blkref #0: rel 1663/41083/41092 blk 29 Btree 2/ 2639, , d: INSERT_LEAF off 73, blkref #0: rel 1663/41083/41093 blk 4 FPW Btree 2/ 3148, , d: INSERT_LEAF off 2, blkref #0: rel 1663/41083/41094 blk 1 FPW Btree 2/ 5099, , d: INSERT_LEAF off 364, blkref #0: rel 1663/41083/41095 blk 4237904 FPW Transaction 8/ 34, , d: COMMIT 2017-09-07 00:24:29.427017 UTC 3.4K VS 16.7K
  71. 71. HOT Updates – How to Track sfo=> select n_tup_upd, n_tup_hot_upd from pg_stat_all_tables where relname = 'benchmark_uuid'; n_tup_upd | n_tup_hot_upd -----------+--------------- 0 | 0 sfo=> update benchmark_uuid set e=cast(0 as boolean) where id = 1000; UPDATE 1 sfo=> select n_tup_upd, n_tup_hot_upd from pg_stat_all_tables where relname = 'benchmark_uuid'; n_tup_upd | n_tup_hot_upd -----------+--------------- 1 | 1 sfo=> update benchmark_uuid set last_updated=CURRENT_TIMESTAMP where id=1001; UPDATE 1 sfo=> select n_tup_upd, n_tup_hot_upd from pg_stat_all_tables where relname = 'benchmark_uuid'; n_tup_upd | n_tup_hot_upd -----------+--------------- 2 | 1 HOT UPDATE = !=
  72. 72. 0 5,000 10,000 15,000 20,000 25,000 30,000 1 31 61 91 121 151 181 211 241 271 InsertsPerSecond Minutes Insert Workload- PostgreSQL 9.6 BASE WAL Compression 16GB Max WAL Reduced Indexes
  73. 73. 3,729 3,949 4,871 4,302 9,177 10,290 17,158 - 5,000 10,000 15,000 20,000 TPS(2UpdatesperTransaction) Update Workload - PostgreSQL 9.6 BASE WAL Compression 16GB Max WAL Async Reduced Indexes Non Random GUID Aurora PostgreSQL
  74. 74. Remember those 9 Indexes – Cut it to 6 Test Table • UUID PK – Random • ID int – Right Lean Sequence • VARCHAR(100) – Random • VARCHAR(50) – Small Set of Words • INT – Random • INT – Random (smaller set) • BOOLEAN – Random (50/50) • BOOLEAN – Somewhat Random (75/25) • Timestamp – Right Lean
  75. 75. 1- 200 1- 100 101- 200 1-50 51- 100 1-25 26- 50 51- 75 76- 100 101- 150 151- 200 101- 125 126- 150 151- 175 176- 200 Insert a Constrained Random Value into a B-tree
  76. 76. 1- 200 1- 100 101- 200 1-50 51- 100 1-25 26- 50 51- 75 76- 100 101- 150 151- 200 101- 125 126- 150 151- 175 176- 200 Insert a Constrained Random Value into a B-tree
  77. 77. 1- 200 1- 100 101- 200 Insert 172 1-50 51- 100 1-25 26- 50 51- 75 76- 100 101- 150 151- 200 101- 125 126- 150 151- 175 176- 200 1- 200 101- 200 151- 200 151- 175 4 blocks loaded Insert a Constrained Random Value into a B-tree
  78. 78. 1- 200 1- 100 101- 200 Insert 172 1-50 51- 100 1-25 26- 50 51- 75 76- 100 101- 150 151- 200 101- 125 126- 150 151- 175 176- 200 Insert 199 1- 200 101- 200 151- 200 151- 175 4 blocks loaded 176- 200 1 blocks loaded Insert a Constrained Random Value into a B-tree Insert 161
  79. 79. 1- 200 1- 100 101- 200 Insert 172 1-50 51- 100 1-25 26- 50 51- 75 76- 100 101- 150 151- 200 101- 125 126- 150 151- 175 176- 200 Insert 199 1- 200 101- 200 151- 200 151- 175 4 blocks loaded 176- 200 1 blocks loaded Insert a Constrained Random Value into a B-tree Insert 161 0 blocks loaded
  80. 80. 1- 200 1- 100 101- 200 Insert 172 1-50 51- 100 1-25 26- 50 51- 75 76- 100 101- 150 151- 200 101- 125 126- 150 151- 175 176- 200 Insert 199 1- 200 101- 200 151- 200 151- 175 4 blocks loaded 176- 200 1 blocks loaded Insert a Constrained Random Value into a B-tree Insert 161 0 blocks loaded Insert 168 0 blocks loaded
  81. 81. 1- 200 1- 100 101- 200 Insert 172 1-50 51- 100 1-25 26- 50 51- 75 76- 100 101- 150 151- 200 101- 125 126- 150 151- 175 176- 200 Insert 199 1- 200 101- 200 151- 200 151- 175 4 blocks loaded 176- 200 1 blocks loaded Insert a Constrained Random Value into a B-tree Insert 161 0 blocks loaded Insert 168 0 blocks loaded At least 2 FPW
  82. 82. Constraining Random Values Prefix UUID with a date • 550e8400-e29b-41d4-a716-446655440000 • YYYYMMDDHH24-UUID • Example • 2010022712-550e8400-e29b-41d4-a716-446655440000 • 2010022713-550e8400-e29b-41d4-a716-446655440000 • Balance the number of hot blocks vs contention • More date precision • less random to b-tree = less blocks touched • Possibly more contention on the leaf blocks
  83. 83. Change PK to UUID like and remove 3 indexes Test Table • UUID PK – Random • ID int – Right Lean Sequence • VARCHAR(100) – Random • VARCHAR(50) – Small Set of Words • INT – Random • INT – Random (smaller set) • BOOLEAN – Random (50/50) • BOOLEAN – Somewhat Random (75/25) • Timestamp – Right Lean Remove Index Remove Index Remove Index – Allows HOT Update Remove Index Remove Index Make non random – right lean
  84. 84. 0 5,000 10,000 15,000 20,000 25,000 30,000 1 31 61 91 121 151 181 211 241 271 InsertsPerSecond Minutes Insert Workload- PostgreSQL 9.6 BASE WAL Compression 16GB Max WAL Reduced Indexes Non Random GUID
  85. 85. 3,729 3,949 4,871 4,302 9,177 10,290 17,158 - 5,000 10,000 15,000 20,000 TPS(2UpdatesperTransaction) Update Workload - PostgreSQL 9.6 BASE WAL Compression 16GB Max WAL Async Reduced Indexes Non Random GUID Aurora PostgreSQL
  86. 86. Why Vacuuming Matter tuple1 tuple2 tuple3 tuple4 tuple5 tuple6 tuple1tuple1
  87. 87. Why Vacuuming Matter tuple1 tuple2 tuple3 tuple4 tuple5 tuple6 tuple1tuple1 tuple2 tuple2
  88. 88. Why Vacuuming Matter tuple1 tuple2 tuple3 tuple4 tuple5 tuple6 tuple1tuple1 tuple2 tuple2 tuple7
  89. 89. Why Vacuuming Matter tuple1 tuple2 tuple3 tuple4 tuple5 tuple6 tuple1tuple1 tuple2 tuple2 tuple7 tuple8 tuple9 tuple10
  90. 90. Why Vacuuming Matter tuple1 tuple2 tuple3 tuple4 tuple5 tuple6 tuple1tuple1 tuple2 tuple2 tuple7 tuple8 tuple9 tuple10 Run Vacuum
  91. 91. Why Vacuuming Matter tuple2 tuple3 tuple4 tuple5 tuple6 tuple1tuple1 tuple2 tuple2 tuple7 tuple8 tuple9 tuple10 Run Vacuum
  92. 92. Why Vacuuming Matter tuple3 tuple4 tuple5 tuple6 tuple1 tuple2 tuple7 tuple8 tuple9 tuple10 Run Vacuum
  93. 93. Why Vacuuming Matter tuple3 tuple4 tuple5 tuple6 tuple1 tuple2 tuple7 tuple8 tuple9 tuple10 Run Vacuumtuple3 tuple3
  94. 94. Why Vacuuming Matter tuple3 tuple4 tuple5 tuple6 tuple1 tuple2 tuple7 tuple8 tuple9 tuple10 Run Vacuumtuple3 tuple4 tuple3 tuple4
  95. 95. Why Vacuuming Matter tuple3 tuple4 tuple5 tuple6 tuple1 tuple2 tuple7 tuple8 tuple9 tuple10 Run Vacuumtuple3 tuple4 tuple3 tuple4 tuple1 tuple2 tuple3 tuple4 tuple5 tuple6 tuple1tuple1 tuple2 tuple2 tuple7 tuple8 tuple9 tuple10 No Vacuum
  96. 96. Why Vacuuming Matter tuple3 tuple4 tuple5 tuple6 tuple1 tuple2 tuple7 tuple8 tuple9 tuple10 Run Vacuumtuple3 tuple4 tuple3 tuple4 tuple1 tuple2 tuple3 tuple4 tuple5 tuple6 tuple1tuple1 tuple2 tuple2 tuple7 tuple8 tuple9 tuple10 No Vacuumtuple3 tuple3
  97. 97. Why Vacuuming Matter tuple3 tuple4 tuple5 tuple6 tuple1 tuple2 tuple7 tuple8 tuple9 tuple10 Run Vacuumtuple3 tuple4 tuple3 tuple4 tuple1 tuple2 tuple3 tuple4 tuple5 tuple6 tuple1tuple1 tuple2 tuple2 tuple7 tuple8 tuple9 tuple10 No Vacuumtuple3 tuple4 tuple3 tuple4
  98. 98. Why Vacuuming Matter tuple3 tuple4 tuple5 tuple6 tuple1 tuple2 tuple7 tuple8 tuple9 tuple10 Run Vacuumtuple3 tuple4 tuple3 tuple4 tuple1 tuple2 tuple3 tuple4 tuple5 tuple6 tuple1tuple1 tuple2 tuple2 tuple7 tuple8 tuple9 tuple10 No Vacuumtuple3 tuple4 tuple3 tuple4 More blocks = More Cache Misses,non HOT updates & more FPW
  99. 99. 4,000 5,000 6,000 7,000 8,000 9,000 10,000 1 61 121 181 241 301 361 421 481 541 601 661 721 781 841 901 961 1021 1081 1141 1201 1261 TPS Minutes Updates - No Vacuum Running
  100. 100. Vacuuming in Memory – Insert Only Workload HEAP PAGES
  101. 101. Vacuuming in Memory – Insert Only Workload HEAP PAGES 1- 200 1- 100 101- 200 1-50 51- 100 1-25 26- 50 51- 75 76- 100 101- 150 151- 200 101- 125 126- 150 151- 175 176- 200 1- 201 101- 201 151- 201 176- 201 1- 202 101- 202 151- 202 176- 202 NO LONG RUNNING TRANSACTIONS
  102. 102. Vacuum Freeze in Memory Block in Memory WAL
  103. 103. Vacuum Freeze in Memory Block in Memory WAL
  104. 104. Vacuum Freeze in Memory Block in Memory WAL
  105. 105. Vacuum Freeze in Memory Block in Memory WAL
  106. 106. Vacuum Freeze in Memory Block in Memory WAL
  107. 107. Vacuum Freeze in Memory Block in Memory WAL
  108. 108. Vacuum Freeze in Memory Block in Memory Checkpoint Datafile WAL Archive Not Frozen
  109. 109. Vacuum Freeze in Memory Block in Memory Checkpoint Datafile WAL Archive Not Frozen
  110. 110. Vacuum Freeze in Memory Block in Memory Checkpoint Datafile WAL Archive Not Frozen VACUUM
  111. 111. Vacuum Freeze in Memory Block in Memory Checkpoint Datafile Full Block WAL Archive Not Frozen VACUUM
  112. 112. Vacuum Freeze in Memory Block in Memory WAL
  113. 113. Vacuum Freeze in Memory Block in Memory WAL
  114. 114. Vacuum Freeze in Memory Block in Memory WAL
  115. 115. Vacuum Freeze in Memory Block in Memory Checkpoint Datafile WAL Archive Frozen
  116. 116. Vacuum in Memory Continued • Increase checkpoint_timeout • alter table X set (vacuum settings); • Manual Test • Vacuum in Memory before checkpoint – 3.5 seconds • Vacuum in Memory after checkpoint – 84.5 seconds • Vacuum not in Memory – 165.8 seconds
  117. 117. Aurora PostgreSQL
  118. 118. Aurora PostgreSQL Differences • No Checkpoints • No Full Page Writes (FPW) • No Log Buffer
  119. 119. Concurrency Queued Work Log Buffer PostgreSQL Aurora Storage Queued Work Storage
  120. 120. Concurrency Queued Work Log Buffer PostgreSQL Aurora Storage Queued Work Storage
  121. 121. Concurrency Queued Work Log Buffer PostgreSQL Aurora Storage Queued Work Storage
  122. 122. Concurrency Queued Work Log Buffer PostgreSQL Aurora Storage Queued Work Storage
  123. 123. Concurrency Queued Work Log Buffer PostgreSQL Aurora Storage Queued Work Storage
  124. 124. Concurrency Queued Work Log Buffer PostgreSQL Aurora Storage Queued Work Storage
  125. 125. Concurrency Queued Work Log Buffer PostgreSQL Aurora Storage Queued Work Storage
  126. 126. Concurrency Queued Work Log Buffer PostgreSQL Aurora Storage A Queued Work Storage
  127. 127. Concurrency Queued Work Log Buffer PostgreSQL Aurora Storage A Queued Work Storage B
  128. 128. Concurrency Queued Work Log Buffer PostgreSQL Aurora Storage A Queued Work Storage B
  129. 129. Concurrency Queued Work Log Buffer PostgreSQL Aurora Storage A Queued Work Storage B
  130. 130. Concurrency Queued Work Log Buffer PostgreSQL Aurora Storage A Queued Work Storage B C
  131. 131. Concurrency Queued Work Log Buffer PostgreSQL Aurora Storage A Queued Work Storage B C
  132. 132. Concurrency Queued Work Log Buffer PostgreSQL Aurora Storage A Queued Work Storage B C D
  133. 133. Concurrency Queued Work Log Buffer PostgreSQL Aurora Storage A Queued Work Storage B C D
  134. 134. Concurrency Queued Work Log Buffer PostgreSQL Aurora Storage A Queued Work Storage B C D E
  135. 135. Concurrency Queued Work Log Buffer PostgreSQL Aurora Storage A Queued Work Storage B C D E
  136. 136. Concurrency Queued Work Log Buffer PostgreSQL Aurora Storage A Queued Work Storage B C D E 0 0 0 0 0 A B C D E Durability Tracking
  137. 137. Concurrency Queued Work Log Buffer PostgreSQL Aurora Storage A Queued Work Storage B C D E 0 0 0 0 0 A B C D E 2 2 1 0 1 A B C D E Durability Tracking
  138. 138. Concurrency Queued Work Log Buffer PostgreSQL Aurora Storage A Queued Work Storage B C D E 4 3 4 2 4 A B C D E Durability Tracking
  139. 139. Concurrency Queued Work Log Buffer PostgreSQL Aurora Storage A Queued Work Storage B C D E 4 3 4 2 4 A B C D E Durability Tracking
  140. 140. Concurrency Queued Work Log Buffer PostgreSQL Aurora Storage A Queued Work Storage B C D E 6 5 6 3 5 A B C D E Durability Tracking
  141. 141. Aurora – Writing Less Block in Memory PostgreSQL Aurora WAL Block in Memory Aurora Storage
  142. 142. Aurora – Writing Less Block in Memory PostgreSQL Aurora update t set y = 6; Full Block WAL Block in Memory Aurora Storage
  143. 143. Aurora – Writing Less Block in Memory PostgreSQL Aurora update t set y = 6; Full Block WAL Block in Memory Aurora Storage
  144. 144. Aurora – Writing Less Block in Memory PostgreSQL Aurora update t set y = 6; update t set y = 6; Checkpoint Datafile Full Block WAL Archive Block in Memory Aurora Storage
  145. 145. Aurora – Writing Less Block in Memory PostgreSQL Aurora update t set y = 6; update t set y = 6; Checkpoint Datafile Full Block WAL Archive Block in Memory Aurora Storage
  146. 146. Aurora – Writing Less Block in Memory PostgreSQL Aurora update t set y = 6; update t set y = 6; Checkpoint Datafile Full Block WAL Archive Block in Memory Aurora Storage
  147. 147. Aurora – Writing Less Block in Memory PostgreSQL Aurora update t set y = 6; update t set y = 6; Checkpoint Datafile Full Block WAL Archive Block in Memory Aurora Storage
  148. 148. 0 5,000 10,000 15,000 20,000 25,000 30,000 1 31 61 91 121 151 181 211 241 271 InsertsPerSecond Minutes Insert Workload- PostgreSQL 9.6 BASE WAL Compression 16GB Max WAL Reduced Indexes Non Random GUID Aurora PostgreSQL
  149. 149. 3,729 3,949 4,871 4,302 9,177 10,290 17,158 - 5,000 10,000 15,000 20,000 TPS(2UpdatesperTransaction) Update Workload - PostgreSQL 9.6 BASE WAL Compression 16GB Max WAL Async Reduced Indexes Non Random GUID Aurora PostgreSQL
  150. 150. Thank you! Questions?

×