Postgresql – Can sharding speed up insertion performance in postgresql

postgresqlsharding

Referenced from this question, the most popular answer does not mention sharding. As far as I know, postgresql will acquire auto-inc lock every time it inserts, so I think sharding can improve insertion performance. Am I right? If sharding can really improve performance, how does it benefit and cost compared other methods?

Best Answer

As has been clarified in the comments, accessing a sequence will not be a bottleneck in PostgreSQL.

If you are faster inserting into a sharded database depends on where the bottleneck is.

If it is disk I/O or CPU on the database, you will probably be faster spreading the workload across several databases (sharding), as long as they have independent storage and network bandwidth is not a bottleneck.

If the bottleneck is on the client side, you probably won't gain much.