Skip to content

pg_net

pg_net : Async HTTP Requests

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
4080
pg_net
pg_net
0.20.3
UTIL
Apache-2.0
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--sLd--
No
Yes
Yes
Yes
no
no
Relationships
Schemasnet
See Also
http
pg_curl
pgjwt
pg_smtp_client
gzip
bzip
zstd
pgjq

0.20.3 on d12/d13/el10/u24/u26; el8/el9/u22 remain on 0.9.2 due older libcurl.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PIGSTY
0.20.3
18
17
16
15
14
pg_net-
RPM
PIGSTY
0.20.3
18
17
16
15
14
pg_net_$v-
DEB
PIGSTY
0.20.3
18
17
16
15
14
postgresql-$v-pg-net-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 0.9.2
PIGSTY 0.9.2
PIGSTY 0.9.2
PIGSTY 0.9.2
PIGSTY 0.9.2
el8.aarch64
PIGSTY 0.9.2
PIGSTY 0.9.2
PIGSTY 0.9.2
PIGSTY 0.9.2
PIGSTY 0.9.2
el9.x86_64
PIGSTY 0.9.2
PIGSTY 0.9.2
PIGSTY 0.9.2
PIGSTY 0.9.2
PIGSTY 0.9.2
el9.aarch64
PIGSTY 0.9.2
PIGSTY 0.9.2
PIGSTY 0.9.2
PIGSTY 0.9.2
PIGSTY 0.9.2
el10.x86_64
PGDG 0.20.4
PGDG 0.20.4
PGDG 0.20.4
PGDG 0.20.4
PGDG 0.20.4
el10.aarch64
PGDG 0.20.4
PGDG 0.20.4
PGDG 0.20.4
PGDG 0.20.4
PGDG 0.20.4
d12.x86_64
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
d12.aarch64
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
d13.x86_64
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
d13.aarch64
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
u22.x86_64
PIGSTY 0.9.2
PIGSTY 0.9.2
PIGSTY 0.9.2
PIGSTY 0.9.2
PIGSTY 0.9.2
u22.aarch64
PIGSTY 0.9.2
PIGSTY 0.9.2
PIGSTY 0.9.2
PIGSTY 0.9.2
PIGSTY 0.9.2
u24.x86_64
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
u24.aarch64
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
u26.x86_64
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
u26.aarch64
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
PIGSTY 0.20.3
PackageVersionOSORGSIZEFile URL
pg_net_180.9.2el8.x86_64pigsty27.1 KiBpg_net_18-0.9.2-2PIGSTY.el8.x86_64.rpm
pg_net_180.9.2el8.aarch64pigsty26.9 KiBpg_net_18-0.9.2-2PIGSTY.el8.aarch64.rpm
pg_net_180.9.2el9.x86_64pigsty26.8 KiBpg_net_18-0.9.2-2PIGSTY.el9.x86_64.rpm
pg_net_180.9.2el9.aarch64pigsty26.5 KiBpg_net_18-0.9.2-2PIGSTY.el9.aarch64.rpm
pg_net_180.20.4el10.x86_64pgdg34.8 KiBpg_net_18-0.20.4-1PGDG.rhel10.2.x86_64.rpm
pg_net_180.20.3el10.x86_64pigsty36.4 KiBpg_net_18-0.20.3-1PIGSTY.el10.x86_64.rpm
pg_net_180.20.3el10.x86_64pgdg34.2 KiBpg_net_18-0.20.3-1PGDG.rhel10.2.x86_64.rpm
pg_net_180.20.3el10.x86_64pgdg34.2 KiBpg_net_18-0.20.3-1PGDG.rhel10.1.x86_64.rpm
pg_net_180.20.3el10.x86_64pgdg34.6 KiBpg_net_18-0.20.3-1PGDG.rhel10.0.x86_64.rpm
pg_net_180.20.0el10.x86_64pgdg33.9 KiBpg_net_18-0.20.0-1PGDG.rhel10.x86_64.rpm
pg_net_180.19.7el10.x86_64pgdg33.0 KiBpg_net_18-0.19.7-1PGDG.rhel10.x86_64.rpm
pg_net_180.20.4el10.aarch64pgdg34.3 KiBpg_net_18-0.20.4-1PGDG.rhel10.2.aarch64.rpm
pg_net_180.20.3el10.aarch64pigsty36.7 KiBpg_net_18-0.20.3-1PIGSTY.el10.aarch64.rpm
pg_net_180.20.3el10.aarch64pgdg33.8 KiBpg_net_18-0.20.3-1PGDG.rhel10.1.aarch64.rpm
pg_net_180.20.3el10.aarch64pgdg33.8 KiBpg_net_18-0.20.3-1PGDG.rhel10.0.aarch64.rpm
pg_net_180.20.0el10.aarch64pgdg33.4 KiBpg_net_18-0.20.0-1PGDG.rhel10.aarch64.rpm
pg_net_180.19.7el10.aarch64pgdg32.5 KiBpg_net_18-0.19.7-1PGDG.rhel10.aarch64.rpm
postgresql-18-pg-net0.20.3d12.x86_64pigsty60.3 KiBpostgresql-18-pg-net_0.20.3-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-net0.20.3d12.aarch64pigsty58.8 KiBpostgresql-18-pg-net_0.20.3-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-net0.20.3d13.x86_64pigsty60.5 KiBpostgresql-18-pg-net_0.20.3-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-net0.20.3d13.aarch64pigsty59.0 KiBpostgresql-18-pg-net_0.20.3-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-net0.9.2u22.x86_64pigsty41.5 KiBpostgresql-18-pg-net_0.9.2-2PIGSTY~jammy_amd64.deb
postgresql-18-pg-net0.9.2u22.aarch64pigsty40.9 KiBpostgresql-18-pg-net_0.9.2-2PIGSTY~jammy_arm64.deb
postgresql-18-pg-net0.20.3u24.x86_64pigsty62.4 KiBpostgresql-18-pg-net_0.20.3-1PIGSTY~noble_amd64.deb
postgresql-18-pg-net0.20.3u24.aarch64pigsty61.2 KiBpostgresql-18-pg-net_0.20.3-1PIGSTY~noble_arm64.deb
postgresql-18-pg-net0.20.3u26.x86_64pigsty62.1 KiBpostgresql-18-pg-net_0.20.3-1PIGSTY~resolute_amd64.deb
postgresql-18-pg-net0.20.3u26.aarch64pigsty61.0 KiBpostgresql-18-pg-net_0.20.3-1PIGSTY~resolute_arm64.deb

Source

pig build pkg pg_net;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pg_net;		# install via package name, for the active PG version

pig install pg_net -v 18;   # install for PG 18
pig install pg_net -v 17;   # install for PG 17
pig install pg_net -v 16;   # install for PG 16
pig install pg_net -v 15;   # install for PG 15
pig install pg_net -v 14;   # install for PG 14

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pg_net';

Create this extension with:

CREATE EXTENSION pg_net;

Usage

Sources: official README, v0.20.3 release notes.

pg_net queues asynchronous HTTP and HTTPS requests from SQL. It creates the net schema, stores pending work in net.http_request_queue, and stores responses in net._http_response. A background worker uses libcurl to process queued requests.

The extension requires shared_preload_libraries = 'pg_net' and libcurl >= 7.83.

GET Request

CREATE EXTENSION pg_net;

SELECT net.http_get(
  'https://postman-echo.com/get',
  params := '{"foo": "bar"}'::jsonb,
  headers := '{"API-KEY": "<key>"}'::jsonb,
  timeout_milliseconds := 1000
) AS request_id;

net.http_get(url, params, headers, timeout_milliseconds) returns a bigint request id.

POST Request

SELECT net.http_post(
  'https://postman-echo.com/post',
  body := '{"key": "value"}'::jsonb,
  headers := '{"Content-Type": "application/json"}'::jsonb,
  timeout_milliseconds := 1000
) AS request_id;

Send one table row as JSON:

WITH selected_row AS (
  SELECT * FROM my_table LIMIT 1
)
SELECT net.http_post(
  'https://api.example.com/data',
  to_jsonb(selected_row.*)
) AS request_id
FROM selected_row;

DELETE Request

SELECT net.http_delete(
  'https://api.example.com/resource/42',
  timeout_milliseconds := 2000
) AS request_id;

net.http_delete(url, params, headers, timeout_milliseconds) is SECURITY DEFINER and returns a bigint request id.

Checking Responses

SELECT id, status_code, content, error_msg, created
FROM net._http_response
ORDER BY created DESC;

Failed requests can be identified from status_code and error_msg. The response table does not preserve every original request argument, so store request metadata separately if you need retry workflows.

Configuration

SHOW pg_net.batch_size;
SHOW pg_net.ttl;
SHOW pg_net.database_name;
SHOW pg_net.username;
  • pg_net.batch_size, default 200, limits how many queued requests the worker processes per cycle.
  • pg_net.ttl, default 6 hours, controls response retention.
  • pg_net.database_name, default postgres, selects the database where the worker runs.
  • pg_net.username, default NULL, selects the worker connection user; NULL uses the bootstrap user.

Settings can be changed in postgresql.conf or with ALTER SYSTEM:

ALTER SYSTEM SET pg_net.ttl TO '1 hour';
ALTER SYSTEM SET pg_net.batch_size TO 500;
SELECT pg_reload_conf();

Changing pg_net.database_name or pg_net.username requires restarting the worker:

SELECT net.worker_restart();

Caveats

  • Pigsty metadata carries pg_net 0.20.3 for PostgreSQL 14-18, but local package notes say 0.20.3 is available only on d12, d13, el10, u24, and u26; el8, el9, and u22 remain on 0.9.2 because of older libcurl.
  • Upstream documents PostgreSQL 12+ compatibility, but this catalog row is packaged for PostgreSQL 14-18.
  • pg_net supports only one database per cluster through pg_net.database_name.
  • v0.20.3 is a worker/maintenance release: it flushes pgstat counters for autovacuum visibility and reports worker activity to pg_stat_activity; no new SQL request API was documented.
Last updated on