Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slow uuid_generate performance in postgresql

Tags:

postgresql

We are planning to migrate our project from MySql to Postgres. We need Guid as primary key. Some of our table need to insert bulk data. We have noticed slow performance while using UUID in postgres. Below sql is taking 16 sec. to generate 10K uuids

select uuid_generate_v4() from generate_series(1,10000)

Whereas Mysql is taking 700 ms. to generate 100K GUIDs.

I am missing something ??

Environment :

Postgres11 on Windows 10

like image 376
Biju Soman Avatar asked May 01 '26 15:05

Biju Soman


1 Answers

Could you try using the function provided by pgcrypto as stated in the help page (scroll to the very bottom).

The following query was executed in less than 120 ms on my computer

select gen_random_uuid() from generate_series(1,10000)
like image 148
FXD Avatar answered May 04 '26 18:05

FXD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!