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.

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.