Skip to main content

For the complete documentation index, see llms.txt

Reference

Every SQL function pg_grpc exposes, with signatures and defaults. For prose-style explanation, see Guides.

grpc_call

grpc_call(
endpoint TEXT,
method TEXT,
request JSONB,
metadata JSONB DEFAULT NULL,
options JSONB DEFAULT NULL
) RETURNS JSONB
ParameterRequiredDescription
endpointyeshost:port. Never include a scheme - the scheme is chosen by options.tls.
methodyesFully-qualified pkg.Service/Method.
requestyesJSON request body. Encoded against the input message descriptor.
metadatanogRPC headers (see below). NULL is no headers.
optionsnoPer-call transport / runtime config (see below). NULL takes all defaults.

Returns the decoded response message as JSONB. Any failure raises a Postgres ERROR and aborts the statement.

options blob

Strict-parsed JSONB object. Unknown keys raise Connection error listing the accepted set.

KeyTypeValidationDefault
timeout_msinteger>= 130000
use_reflectionboolean-true
tlsobjectsee belowNULL → plaintext
max_decode_message_size_bytesinteger[1, 4294967295]tonic default (4 MiB)
max_encode_message_size_bytesinteger[1, 4294967295]tonic default (unbounded)

options.tls (when set) accepts:

FieldTypeNotes
ca_certstringPEM. Layered onto the OS trust store.
client_certstringPEM. Required together with client_key.
client_keystringPEM. Required together with client_cert.
domain_namestringSNI / cert-verification override.

A bare '{"tls": {}}' enables TLS using the OS trust store.

metadata blob

JSONB object. Keys are silently lowercased. Values may be a string or an array of strings (repeated headers).

SELECT grpc_call(
'host:port', 'pkg.S/M', '{}'::jsonb,
metadata => '{"authorization": "Bearer abc", "x-trace-id": ["t1", "t2"]}'::jsonb
);

Keys ending in -bin (binary metadata) are rejected in v1.

grpc_call_async

grpc_call_async(
endpoint TEXT,
method TEXT,
request JSONB,
metadata JSONB DEFAULT NULL,
options JSONB DEFAULT NULL
) RETURNS BIGINT

Enqueues a gRPC call for the background worker and returns the call id immediately. The calling transaction does not block on the network. Options are validated at enqueue time using the same rules as grpc_call.

See Async calls for setup, fan-out patterns and configuration.

grpc_call_result

grpc_call_result(
id BIGINT,
async BOOLEAN DEFAULT TRUE
) RETURNS TABLE (
id BIGINT,
status TEXT,
message TEXT,
response JSONB
)

Fetches the result for a previously enqueued call.

ColumnNotes
idThe call id.
statusPENDING (not yet finished), SUCCESS, or ERROR.
messageError string on ERROR. NULL otherwise.
responseDecoded response JSONB on SUCCESS. NULL otherwise.

When async = false the function polls at 50 ms intervals until the result is no longer PENDING. When async = true (the default) it returns immediately with whatever status exists at call time.

Async GUCs

Configured in postgresql.conf. Identity GUCs require a server restart; operational GUCs take effect on SIGHUP / SELECT pg_reload_conf().

GUCTypeDefaultReloadDescription
pg_grpc.database_namestringpostgresrestartDatabase the background worker connects to.
pg_grpc.usernamestring(superuser)restartRole the worker runs as. NULL = bootstrap superuser.
pg_grpc.batch_sizeinteger200SIGHUPMax rows dequeued per worker cycle.
pg_grpc.ttlstring6 hoursSIGHUPHow long completed results are retained before TTL cleanup.

Proto management

User-supplied proto compilation surface. See User-supplied protos for the lifecycle and worked examples.

grpc_proto_stage(filename text, source text)

Stages one .proto file's source under the given filename. Re-staging the same filename overwrites.

grpc_proto_unstage(filename text) returns boolean

Removes one staged file. Returns true if it was present.

grpc_proto_unstage_all()

Clears every staged file. Registry untouched.

grpc_proto_compile()

Compiles every staged file together. On success, every service is inserted into the registry and staging is cleared. On failure, both areas are left as they were.

grpc_proto_unregister(service_name text) returns boolean

Removes one fully-qualified service from the registry. Returns true if it was present.

grpc_proto_unregister_all()

Drops every registered service. Staging untouched.

grpc_proto_list_staged() returns table(filename text, source text)

One row per currently-staged file.

grpc_proto_list_registered() returns table(service_name text, origin text, filename text, source text, endpoint text)

One row per registered service. origin is 'user' (registered via stage+compile) or 'reflection' (auto-registered on a grpc_call cache miss).

Errors

Every failure raises a Postgres ERROR with a stable prefix. Match on the prefix in caller code.

PrefixCause
Connection error: …Could not reach the endpoint or invalid options / tls config.
Proto error: …Reflection failed, symbol not found or JSON ↔ protobuf encode/decode error.
Proto compile error: …grpc_proto_compile failed to parse or resolve staged files.
gRPC call failed: …Server returned a non-OK gRPC status.
Request timeout: …msThe call (connect + reflection + unary) did not finish within timeout_ms.