Top Banner
The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding implementation requirements. Creative Commons Attribution License http://momjian.us/presentations Last updated: September, 2018 1 / 22
22

The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

Sep 27, 2018

Download

Documents

vannga
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

The Future of Postgres Sharding

BRUCE MOMJIAN

This presentation will cover the advantages of sharding andfuture Postgres sharding implementation requirements.Creative Commons Attribution License http://momjian.us/presentations

Last updated: September, 2018

1 / 22

Page 2: The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

Outline

1. Scaling

2. Vertical scaling options

3. Non-sharding horizontal scaling

4. Existing sharding options

5. Future sharding

2 / 22

Page 3: The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

Scaling

Database scaling is the ability to increase database throughput byutilizing additional resources such as I/O, memory, CPU, oradditional computers.However, the high concurrency and write requirements ofdatabase servers make scaling a challenge. Sometimes scaling isonly possible with multiple sessions, while other options requiredata model adjustments or server configuration changes.Postgres Scaling Opportunities http://momjian.us/main/presentations/overview.html#scaling

3 / 22

Page 4: The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

Vertical Scaling

Vertical scaling can improve performance on a single server by:

◮ Increasing I/O with

◮ faster storage◮ tablespaces on storage devices◮ striping (RAID 0) across storage devices◮ Moving WAL to separate storage

◮ Adding memory to reduce read I/O requirements

◮ Adding more and faster CPUs

4 / 22

Page 5: The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

Non-sharding Horizontal Scaling

Non-sharding horizontal scaling options include:

◮ Read scaling using Pgpool and streaming replication

◮ CPU/memory scaling with asynchronous multi-master

The entire data set is stored on each server.

5 / 22

Page 6: The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

Why Use Sharding?

◮ Only sharding can reduce I/O, by splitting data across servers

◮ Sharding benefits are only possible with a shardableworkload

◮ The shard key should be one that evenly spreads the data

◮ Changing the sharding layout can cause downtime

◮ Additional hosts reduce reliability; additional standbyservers might be required

6 / 22

Page 7: The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

Typical Sharding Criteria

◮ List

◮ Range

◮ Hash

7 / 22

Page 8: The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

Existing Sharding Solutions

◮ Application-based sharding

◮ PL/Proxy

◮ Postgres-XC/XL

◮ pg_shard

◮ Hadoop

The data set is sharded (striped) across servers.

8 / 22

Page 9: The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

Sharding Using Foreign Data Wrappers (FDW)

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������

SQL Queries

SQL Queries

PG FDW

Foreign Server Foreign Server Foreign Server

https://wiki.postgresql.org/wiki/Built-in_Sharding

9 / 22

Page 10: The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

FDW Sort/Join/Aggregate Pushdown

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������

SQL Queries

PG FDW

Foreign Server Foreign Server Foreign Server

aggregates (10)joins (9.6)

sorts (9.6)aggs on partitions (11)

10 / 22

Page 11: The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

Advantages of FDW Sort/Join/Aggregate Pushdown

◮ Sort pushdown reduces CPU and memory overhead on thecoordinator

◮ Join pushdown reduces coordinator join overhead, andreduces the number of rows transferred

◮ Aggregate pushdown causes summarized values to be passedback from the shards

◮ WHERE clause restrictions are also pushed down

11 / 22

Page 12: The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

FDW DML Pushdown in Postgres 9.6

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������

SQL Queries

PG FDW

Foreign Server Foreign Server Foreign Server

UPDATE, DELETE

12 / 22

Page 13: The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

Pushdown of Static Tables

������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������

SQL Queries

SQL Queries

with joins to static data

PG FDW

and static data restrictions

Foreign S. Foreign S. Foreign S.static static static

13 / 22

Page 14: The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

Implementing Pushdown of Static Tables

Static table pushdown allows join pushdown where the queryrestriction is on the static table and not on the sharded column.Static tables can be pushed to shards usinglogical replication, implemented in Postgres 10. The optimizermust also know which tables are duplicated on the shards for joinpushdown.

14 / 22

Page 15: The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

Shard Management

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������

SQL Queries

DDL Queries

PG FDW

Foreign Server Foreign Server Foreign Server

Shard management will be added to the partitioning syntax,which was added in Postgres 10.

15 / 22

Page 16: The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

Parallel Shard Access

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������

SQL Queries

PG FDW

Foreign Server Foreign Server Foreign Server

Shard Parallel Access

16 / 22

Page 17: The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

Advantages of Parallel Shard Access

◮ Can use libpq’s asynchronous API to issue multiple pendingqueries

◮ Ideal for queries that must run on every shard, e.g.,

◮ restrictions on static tables◮ queries with no sharded-key reference◮ queries with multiple shared-key references

◮ Aggregate across shards

17 / 22

Page 18: The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

Global Snapshot Manager

������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������

SQL Queries

SQL Queries

ManagerGlobal Snapshot

PG FDW

Foreign Server Foreign Server Foreign Server

18 / 22

Page 19: The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

Implementing a Global Snapshot Manager

◮ We already support sharing snapshots among clients withpg_export_snapshot()

◮ We already support exporting snapshots to other serverswith the GUC hot_standby_feedback

19 / 22

Page 20: The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

Global Transaction Manager

������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������������������������������������������������������������������������������

SQL Queries

SQL Queries

Foreign Server

ManagerGlobal Transaction

PG FDW

Foreign Server Foreign Server

20 / 22

Page 21: The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

Implementing a Global Transaction Manager

◮ Can use prepared transactions (two-phase commit)

◮ Transaction manager can be internal or external

◮ Can use an industry-standard protocol like XA

21 / 22

Page 22: The Future of Postgres Sharding - Bruce Momjian · The Future of Postgres Sharding BRUCE MOMJIAN This presentation will cover the advantages of sharding and future Postgres sharding

Conclusion

http://momjian.us/presentations https://www.flickr.com/photos/anotherpintplease/

22 / 22