Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use FOR UPDATE SKIP LOCKED to let multiple PostgreSQL workers claim different ready jobs without waiting on one another. It prevents two workers from claiming the same row at the same time, but it does not guarantee strict FIFO, equal shares among workers or tenants, or freedom from starvation. A fair queue needs an explicit ordering and scheduling policy, plus leases and retry rules for recovery.

How do I use FOR UPDATE SKIP LOCKED for a PostgreSQL job queue?

Store each job as a durable row with an explicit state, such as ready, running, done or failed. Give it a stable enqueue time or sequence and a unique identifier. In a short transaction, select a bounded batch of eligible rows in policy order, lock them while skipping rows already locked by another worker, update them to running, and return the claimed rows.

For example, the following statement favors higher priority, then older enqueue time, then lower ID. The five-minute lease is illustrative; choose a duration and renewal strategy appropriate to the work.

WITH picked AS (
    SELECT id
    FROM jobs
    WHERE state = 'ready'
      AND run_at <= now()
    ORDER BY priority DESC, enqueued_at ASC, id ASC
    LIMIT 20
    FOR UPDATE SKIP LOCKED
)
UPDATE jobs AS j
SET state = 'running',
    claimed_by = $1,
    claimed_at = now(),
    lease_until = now() + interval '5 minutes',
    attempts = attempts + 1
FROM picked
WHERE j.id = picked.id
RETURNING j.*;

Run the statement inside a transaction and commit the claim before doing slow work or calling an external service. The selection and state update must be part of the same transaction. The ordered selection expresses your preference; the final unique ID makes ties deterministic. The batch limit bounds how many jobs one worker takes at once and helps apply backpressure. PostgreSQL documents that locking stops once enough rows have been returned to satisfy LIMIT, and that SKIP LOCKED skips rows that cannot be locked immediately. See the [PostgreSQL 16 SELECT documentation](https://www.postgresql.org/docs/16/sql-select.html) and [UPDATE documentation](https://www.postgresql.org/docs/16/sql-update.html).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

This is an application pattern built from PostgreSQL primitives, not a queue workflow guaranteed by the database. If you want oldest-first service, remove priority from the ordering. If you need tenant fairness or weighted scheduling, encode that policy explicitly rather than assuming a row order provides it.

Does SKIP LOCKED guarantee FIFO or fairness?

No. A deterministic ORDER BY defines preference among rows visible and available to a particular worker. But if an earlier row is locked, another worker can skip it and claim a later one. As a result, concurrent claim order—and especially completion order—can differ from global FIFO. PostgreSQL describes the view produced by SKIP LOCKED as inconsistent, and identifies avoiding lock contention among queue-like consumers as its intended use, not general-purpose consistent reads. [PostgreSQL 16 SELECT documentation](https://www.postgresql.org/docs/16/sql-select.html)

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

“Fair” therefore needs a concrete definition for your queue. It might mean older eligible work generally goes first, tenants receive weighted shares, or no eligible job waits beyond an acceptable age. These goals can conflict: strict priority can indefinitely postpone low-priority work, while strict oldest-first service can let one tenant dominate. Choose the policy, implement it in selection or scheduling logic, and measure whether it is being met.

  • For deterministic preference: order by the policy fields and finish with a unique tie-breaker. PostgreSQL says rows tied on every ORDER BY expression have implementation-dependent order.
  • For starvation monitoring: track the age of the oldest ready job, not only queue depth or average claim latency. Add aging, retry limits, or an explicit tenant/priority scheduler if the metric shows work being bypassed too long.
  • For strict ordering requirements: account for PostgreSQL’s documented caveat that a locking SELECT with ORDER BY at READ COMMITTED can return rows out of order if it waits for a lock while an ordering column changes. PostgreSQL describes a subquery-locking workaround, but warns it can lock all rows and materially affect performance. Under REPEATABLE READ or SERIALIZABLE, the described case produces a serialization failure. A queue using SKIP LOCKED normally avoids waiting for conflicting row locks, but ordering columns should still be treated carefully if they can change concurrently or locking behavior differs.

How do I prevent two workers from taking the same job?

The row lock coordinates the claim while the transaction is open; the atomic state change makes the claim durable after commit. A competing worker skips a row locked by the first transaction, and once the first transaction commits, the row is no longer ready, so it no longer matches the claim predicate. Keep the claim transaction short and do not perform the job’s slow or external work while holding the row locks.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

That protection applies to database claims, not arbitrary side effects. If a worker commits a claim, performs an external action, and crashes before recording completion, the action may have happened even though the job appears unfinished. Make side effects idempotent where possible, and define how the system reconciles ambiguous outcomes; a PostgreSQL transaction alone cannot atomically commit an unrelated service’s network-side effect.

How do I retry jobs after a worker crashes?

Use a claim deadline or lease on running rows. A recovery process can find jobs whose lease has expired and return them to ready or move them to a retry state. Specify the retry count, backoff, and terminal-failure path as part of the application state machine. A lease replaces long-held database locks with explicit recovery logic; lease duration and renewal must account for normal job runtime and worker pauses.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
  • On successful work: mark the job done after the effect is confirmed.
  • On a retryable error: schedule a later run_at using backoff, increment or record the attempt, and make the row claimable again.
  • On exhausted retries or a permanent error: move the job to a terminal failure state and preserve enough error detail for diagnosis or manual recovery.
  • On an expired lease: reclaim only according to a defined policy, and guard completion updates with the current claim owner or a claim token so an old worker cannot overwrite a newer claim.

The last safeguard is especially useful when an expired worker resumes after another worker has reclaimed its job. Exactly-once external effects are not provided by row locking; use idempotency keys or a broader protocol where duplicate effects would be harmful.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What should I index and monitor?

Choose indexes to support both the eligibility filter and the ordering policy, then inspect execution plans and benchmark with representative data and concurrency. For a simple queue, a partial index over ordering columns for ready rows may be a candidate, but scheduled-time filters, priority distribution, state changes, and tenant rules can alter the best design. There is no universal throughput figure established here; measure the workload you actually run.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
  • Track claim latency, oldest ready-job age, retry counts, failures, and lock waits.
  • Watch table and index growth, vacuum activity, and the effects of repeated state updates and eventual deletion or archival. PostgreSQL’s [routine vacuuming documentation](https://www.postgresql.org/docs/16/routine-vacuuming.html) explains vacuum’s maintenance role but does not set queue-specific thresholds.
  • Use LISTEN/NOTIFY only as an optional wake-up aid. Workers must still check the durable jobs table: [PostgreSQL NOTIFY documentation](https://www.postgresql.org/docs/16/sql-notify.html) describes notifications, not a durable job queue. Polling is simpler; notifications can reduce idle polling latency but require managing listener connections and lifecycle.

When is a PostgreSQL queue the right fit?

A table-backed queue can be attractive when jobs need transactional coupling with application data and the workload fits the database’s operational model. Compare it with a broker or queue library against the actual requirements rather than a generic scale threshold:

  • Transactional coupling to application data
  • Delivery, retry, and dead-letter semantics
  • Ordering and tenant or priority fairness
  • Measured throughput and latency at expected concurrency
  • Operational burden and crash-recovery behavior
  • Visibility, scheduling, and administrative tooling

Confirm SQL behavior against the PostgreSQL major version you deploy; the links here document PostgreSQL 16. They establish database semantics and maintenance considerations, not a workload-independent point at which every application should switch to a dedicated broker.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.