Skip to content
ArticleBeginner

Connect to a PostgreSQL database with Cloudflare Workers

Connect a Cloudflare Worker to a PostgreSQL database with TCP Sockets and Hyperdrive, and query and insert rows in a products table.

Last updated
Oct 12, 2026
Read the original

Create a Workers application that talks to an existing PostgreSQL database using TCP Sockets, then speed up connections with Hyperdrive. The Worker reads from and writes to a products table.

What you’ll learn

  • Add a PostgreSQL client library to a Worker
  • Configure and open the database connection
  • Query and insert rows
  • Deploy, then add Hyperdrive for pooled, faster connections

Cloudflare products used

Workers, Hyperdrive.

Follow the full, step-by-step tutorial in Cloudflare’s documentation.

Keep learning