Postgresql vs SQL Server - Concurrent insertion into tables with incremental keys.

Postgresql vs SQL Server - Concurrent insertion into tables with incremental keys.
img Greg Linwood |  16-Apr-2026

Which DBMS inserts faster into tables with incremental keys under high concurrency - Postgresql or SQL Server?

We measured Postgresql v18 (PGSQL) vs SQL Server 2025 (MSSQL) using four concurrent insert tests, with between 1 to 192 threads per test.

PGSQL proved to be faster and sustained more stable performance than MSSQL - by very big margins - even with MSSQL's key optimisations enabled (Optimize For Sequential Key & Optimized Locking).

PGSQL's big advantage lies in a "Fastpath" optimisation - introduced 2018 in PG11 - a game changing feature for concurrent insertion into tables with incremental keys.

We'd love to see Microsoft add a similar feature to MSSQL.

PGSQL's "Fastpath" optimisation occurs when a new value is being inserted which is larger than the largest existing value in an index.

It works by caching a copy of the last block (end page) of the index, then inserts directly into it rather than traversing the index to locate the last block.

MSSQL lacks such a feature and always traverses the index to locate the last / target page for every insertion, adding extra page reads and more latch contention which combine to cause "hot page" contention during highly concurrent inserts.

The PGSQL optimisation was developed by Pavan Deolasee, based upon an idea by Postgres Fellow Simon Riggs, and committed to Postgresql v11 in 2018.

Further details on its mechanism, and its inclusion into PGSQL code is available in this discussion:

https://www.postgresql.org/message-id/flat/CABOikdM9DrupjyKZZFM5k8-0RCDs1wk6JzEkg7UgSW6QzOwMZw%40mail.gmail.com

All four of our tests concurrently insert into a single table named "transacts", with the following general structure.

create table transacts (
   tran_no    bigint not null primary key -- sequence
 , acct_no    bigint not null
 , tran_type  char(1) not null 
 , status     smallint not null
 , amount     numeric(20, 2) not null
);

Sequence definitions differ between PGSQL and MSSQL so are not shown (DBMS specific DDL is available in test scripts below).

In each test, a client driver inserts into the table via a stored procedure, passing randomly generated parameter values for non-sequential columns.

The sequential column / primary key is tran_no, generated by a sequence in each test.

The first three tests insert either a single row, or batches of 1000 rows using looping or set based code. All tests use stored procedures.

The fourth test adds a secondary index on acct_no column to asses impact of secondary index maintenance.

In all four tests, PGSQL out-performed MSSQL - both in raw throughput and performance stability.

Test Results
Test 1 - Singleton SP inserts.
Test Results
Test 2 - SP looping batched inserts.
Test Results
Test 3 - SP set based batch inserts.
Test Results
Test 3 - SP set based batch inserts + additional index.

Test 1 inserts single rows per client calls via a stored procedure.

  • Client time loss dominated this test, producing the lowest results for both PGSQL and MSSQL.

Test 2 inserts 1000 rows per client calls via a stored procedure with looping logic, committing rows individually.

  • PGSQL performance increased steadily up to 64 threads, before degrading due to increased Fastpath cache misses.
  • MSSQL performed best with one or two threads, but degraded significantly as more threads were introduced, due to "hot page" latch contention.

Test 3 inserts 1000 rows per client calls via a stored procedure with set logic, committing rows in sets of 1000.

  • PGSQL performance remained high and steady throughout this test, highlighting effectiveness of its Fastpath optimisation.
  • MSSQL performed best with one thread, before degrading suddenly, due to "hot page" latch contention.

Test 4 repeats Test 3, with an additional index on another column (acct_no) in the table.

  • PGSQL performance degraded with an additional index, but remained consistently higher than MSSQL at all levels of concurrency.
  • MSSQL actually performed better with an additional index which, due to increased time between latch requests whilst the extra index was being maintained.




Use of incremental keys / identity columns is a common design pattern in relational databases, so we think MSSQL would benefit significantly from such a feature.

MSSQL's Optimized Locking and Optimize For Sequential Key features were both enabled during these tests.

We do NOT recommend changing database platforms based only on this data, as PGSQL suffers from other aspects of its very old design which we plan to present similar data on soon.

We present this data as part of a study into the comparative strengths / weaknesses of the PGSQL and MSSQL database platforms, not to guide DBMS selection on narrow criteria.

We also call for contributions from skilled professionals on this topic, including questions or recommendations about our testing approach or system configurations, which are described below.