Migrating from Postgres to Workers KV

Does anybody have experience migrating? Am I correct that using Workers KV is WAY cheaper than any cloud provider could offer, by way of a Postgres instance?

Might be a little tough migrating.

KV is a purely key-value database with only functions like get, put, and list. You can’t run SQL, do any [powerful] searches, it’s not relational, etc. Unless you’re using postgres purely as a key-value database (most likely not), you’ll lose most everything SQL is good for; Once more, the average db-based application would need to overhaul its architecture to work with Workers KV and other KV-type stores.


Judge is right, however, it may be worth doing depending on your use case.

If you can get by without unpredictable queries, it’s possible to build a kv based database. You may want to add index-keys instead of using queries. The only other challenge is the writing model. Because it’s eventual consistency, you could potentially have race conditions if you are doing two writes at the same time from different Cloudflare pops. If you are doing mostly reads and controlled writes, it could work for you.

As for cost comparison, that is hard and depends much on scale. I think it may be a cost saver potentially, but I wouldn’t use that as a motivation for a change like this. Instead the motivation should be speed. Does your app live in a worker, and you need your database available at the edge to shave off some ms on database reads? Then this might work for you.

1 Like