Skip to content

Google Pub/Sub

Topics, subscriptions, schemas, IAM, backlog metrics and opt-in message replay from Google Cloud Pub/Sub

Connector software
Free and open source
Service credentials
Required
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/pubsub/index.md to help me query Google Pub/Sub with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Find subscriptions falling behind

Uses your connected account. Set up the connector and credentials to run it with your data.

SELECT subscription, undelivered_messages,
  oldest_unacked_age_seconds / 60 AS lag_minutes
FROM pubsub.main.subscription_backlog()
ORDER BY oldest_unacked_age_seconds DESC NULLS LAST

Quick start

Choose where to run Google Pub/Sub, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach the release directly

Downloads the latest release for your platform and caches it locally.

ATTACH 'pubsub' AS pubsub (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/vgi-pubsub'
);

3. Add service credentials

After attaching, create the secret for the service you want to query in the same SQL session. Replace the placeholders with your service settings.

gcp_pubsub credentials

Google Cloud Pub/Sub connection: project, credentials (service account key JSON or OAuth access token) and optional endpoint overrides (emulator).

Get these credentials →
secret.sql
CREATE SECRET gcp_pubsub (
    TYPE gcp_pubsub,
    project_id           '<project_id>',
    service_account_json '<GCP_PUBSUB_SERVICE_ACCOUNT_JSON>',  -- secret
    access_token         '<ACCESS_TOKEN>',  -- secret
    endpoint             '<endpoint>',
    monitoring_endpoint  '<monitoring_endpoint>',
    quota_project_id     '<quota_project_id>'
);
Credential fields and requirements →

4. Run a query

query.sql
SELECT subscription, undelivered_messages,
  oldest_unacked_age_seconds / 60 AS lag_minutes
FROM pubsub.main.subscription_backlog()
ORDER BY oldest_unacked_age_seconds DESC NULLS LAST
More example queries →
Technical details
Verified connector release
v0.2.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach the release directly

Uses the verified release each time you attach the connector.

ATTACH 'pubsub' AS pubsub (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/[email protected]'
);

Overview

Google Cloud Pub/Sub as SQL: topics, subscriptions, snapshots, schemas and IAM policies, backlog and throughput metrics from Cloud Monitoring, and opt-in replay of retained messages. Works with the Pub/Sub emulator.

ATTACH options

use_application_default_credentials
Opt in to Google Application Default Credentials (GOOGLE_APPLICATION_CREDENTIALS, gcloud user credentials, or the GCE/GKE metadata server) when the gcp_pubsub secret has no SERVICE_ACCOUNT_JSON or ACCESS_TOKEN. Off by default: the worker never reads local credentials unless this is true.BOOLEAN

Catalog

Everything pubsub exposes once attached — read straight from the worker's released build.

pubsub 1 schema
main 13 functions

Read-only SQL over one Google Cloud project's Pub/Sub resources, IAM, backlog metrics and opt-in message replay.

Schema examples (20)
Examples (20)

Every topic with its retention, schema and owning team label

SELECT topic, message_retention_seconds / 86400 AS retention_days, schema,
  labels['team'] AS team
FROM pubsub.main.topics()
ORDER BY topic;

Topics with neither CMEK nor retention (cannot be replayed)

SELECT topic
FROM pubsub.main.topics()
WHERE kms_key_name IS NULL AND message_retention_seconds IS NULL
ORDER BY topic;

Every subscription with its delivery type, ack deadline and dead-letter topic

SELECT subscription, type, ack_deadline_seconds, dead_letter_topic,
  enable_exactly_once_delivery
FROM pubsub.main.subscriptions()
ORDER BY subscription;

Subscriptions per topic: topics with zero subscriptions drop every message

SELECT t.topic, count(s.name) AS subscriptions
FROM pubsub.main.topics() t
LEFT JOIN pubsub.main.subscriptions() s ON s.topic = t.name
GROUP BY t.topic
ORDER BY subscriptions, t.topic;
16 more examples

Snapshots by expiry (the soonest to disappear first)

SELECT snapshot, topic, expire_time
FROM pubsub.main.snapshots()
ORDER BY expire_time;

Schemas with their type and current revision

SELECT schema, type, revision_id, length(definition) AS definition_chars
FROM pubsub.main.schemas()
ORDER BY schema;

How many topics use each schema

SELECT s.schema, count(t.name) AS topics
FROM pubsub.main.schemas() s
LEFT JOIN pubsub.main.topics() t ON t.schema = s.name
GROUP BY s.schema
ORDER BY topics DESC, s.schema;

The revision history of a schema, newest first

SELECT revision_id, revision_create_time, definition
FROM pubsub.main.schema_revisions('order-avro')
ORDER BY revision_create_time DESC;

Public grants on any topic, subscription, snapshot or schema

SELECT resource_type, resource, role, member
FROM pubsub.main.iam_policies()
WHERE member IN ('allUsers', 'allAuthenticatedUsers')
ORDER BY resource;

Which principals hold which roles on topics

SELECT member, list(DISTINCT role ORDER BY role) AS roles
FROM pubsub.main.iam_policies(resource_type := 'topic')
WHERE error IS NULL AND member IS NOT NULL
GROUP BY member
ORDER BY member;

Peak backlog per subscription over a day

SELECT subscription, max(value) AS peak_backlog
FROM pubsub.main.time_series('subscription/num_undelivered_messages', start_time := TIMESTAMPTZ '2026-01-01 00:00:00+00', end_time := TIMESTAMPTZ '2026-01-02 00:00:00+00')
GROUP BY subscription
ORDER BY peak_backlog DESC;

Publish requests to a topic per 5 minutes by response code (last hour)

SELECT ts, labels['response_code'] AS response_code, value
FROM pubsub.main.time_series('topic/send_request_count', topic := 'orders', alignment_seconds := 300)
ORDER BY ts, response_code;

Which subscriptions are furthest behind right now

SELECT subscription, undelivered_messages,
  oldest_unacked_age_seconds / 60 AS lag_minutes
FROM pubsub.main.subscription_backlog()
ORDER BY oldest_unacked_age_seconds DESC NULLS LAST;

Backlogged subscriptions with their dead-letter settings

SELECT s.subscription, s.dead_letter_topic, b.undelivered_messages
FROM pubsub.main.subscriptions() s
JOIN pubsub.main.subscription_backlog() b ON b.subscription = s.subscription
WHERE b.undelivered_messages > 1000
ORDER BY b.undelivered_messages DESC;

Replay retained messages of a topic through a temporary subscription (opt-in)

SELECT timestamp, key, headers['tenant'] AS tenant,
  payload_text::JSON->>'order_id' AS order_id
FROM pubsub.main.read_messages('orders', allow_temporary_subscription := true, start_time := TIMESTAMPTZ '2026-01-01 00:00:00+00', max_messages := 50)
ORDER BY timestamp, message_id;

What a snapshot's captured backlog contains, without touching the subscription it was taken from

SELECT headers['event'] AS event, count(*) AS messages,
  max(payload_bytes) AS largest
FROM pubsub.main.read_messages('orders', allow_temporary_subscription := true, snapshot := 'before-deploy', max_messages := 1000)
GROUP BY event
ORDER BY messages DESC;

Which parts of the worker this credential can use

SELECT capability, available, status, used_by
FROM pubsub.main.access_check()
ORDER BY capability;

Short subscription ids next to their topic

SELECT pubsub.main.resource_id(name) AS subscription, topic
FROM pubsub.main.subscriptions()
ORDER BY subscription;

Subscriptions per project of their topic (cross-project subscriptions show up here)

SELECT pubsub.main.resource_project(topic) AS topic_project,
  count(*) AS subscriptions
FROM pubsub.main.subscriptions()
GROUP BY ALL
ORDER BY topic_project;

Convert API duration text to days

SELECT pubsub.main.duration_seconds(d) / 86400 AS days
FROM (VALUES ('604800s'), ('86400s')) t(d)
ORDER BY days;
Scalar functions
duration_seconds (duration VARCHAR) 2 examples

Seconds in a google.protobuf.Duration text value such as '604800s'

Arguments
duration VARCHAR
A google.protobuf.Duration JSON value such as '604800s' or '1.5s'. NULL or invalid text gives NULL.
ReturnsDOUBLE
Examples (2)

Convert API duration text to days

SELECT pubsub.main.duration_seconds(d) / 86400 AS days
FROM (VALUES ('604800s'), ('86400s')) t(d)
ORDER BY days;
SELECT d, pubsub.main.duration_seconds(d) AS seconds
FROM (VALUES ('604800s'), ('1.5s'), ('soon')) t(d)
ORDER BY d;
Link
resource_id (name VARCHAR) 2 examples

The id (last segment) of a Pub/Sub resource name

Arguments
name VARCHAR
A Pub/Sub resource name such as 'projects/my-project/topics/orders'. NULL gives NULL.
ReturnsVARCHAR
Examples (2)

Short subscription ids next to their topic

SELECT pubsub.main.resource_id(name) AS subscription, topic
FROM pubsub.main.subscriptions()
ORDER BY subscription;
SELECT pubsub.main.resource_id(n) AS id
FROM (VALUES ('projects/p/topics/orders'), ('projects/p/subscriptions/orders-worker')) t(n)
ORDER BY id;
Link
resource_project (name VARCHAR) 2 examples

The project of a Pub/Sub resource name

Arguments
name VARCHAR
A Pub/Sub resource name such as 'projects/my-project/topics/orders'. NULL gives NULL.
ReturnsVARCHAR
Examples (2)

Subscriptions per project of their topic (cross-project subscriptions show up here)

SELECT pubsub.main.resource_project(topic) AS topic_project,
  count(*) AS subscriptions
FROM pubsub.main.subscriptions()
GROUP BY ALL
ORDER BY topic_project;
SELECT n, pubsub.main.resource_project(n) AS project
FROM (VALUES ('projects/shared-infra/topics/events'), ('events')) t(n)
ORDER BY n;
Link
Table functions
access_check (project := VARCHAR, secret_name := VARCHAR) 1 example

Check which Pub/Sub and Monitoring reads the credential is allowed to make

Named arguments
project := VARCHAR
Google Cloud project id; default the gcp_pubsub secret's PROJECT_ID.
secret_name := VARCHAR
Name of the gcp_pubsub secret to use when several exist.
Returns columns
capability VARCHAR
What was checked: list_topics, list_subscriptions, list_snapshots, list_schemas, read_iam_policy, attach_subscription, monitoring_metrics.
used_by VARCHAR
The functions that need this capability.
api_call VARCHAR
The REST call made to check it.
available BOOLEAN
true when the call succeeded; false when it was refused; NULL when it could not be checked (e.g. no topic to test against).
http_status BIGINT
HTTP status of the check call; NULL when skipped.
status VARCHAR
Google canonical status of a failure, e.g. 'PERMISSION_DENIED', 'UNIMPLEMENTED' (emulator); 'OK' on success.
message VARCHAR
Error message or why the check was skipped; NULL on success.
Example

Which parts of the worker this credential can use

SELECT capability, available, status, used_by
FROM pubsub.main.access_check()
ORDER BY capability;
Link
iam_policies (resource_type := VARCHAR, resource := VARCHAR, project := VARCHAR, page_size := BIGINT, secret_name := VARCHAR) 2 examples

IAM bindings of Pub/Sub topics, subscriptions, snapshots and schemas, one row per role and member

Named arguments
resource_type := VARCHAR
Which kind of resource to read policies for; 'all' walks topics then subscriptions then snapshots then schemas. · default "all"
resource := VARCHAR
Only this resource (id or full name; needs resource_type other than 'all'): one getIamPolicy call.
project := VARCHAR
Google Cloud project id; default the gcp_pubsub secret's PROJECT_ID.
page_size := BIGINT
Resources listed per API page; one getIamPolicy call per resource. · default 100
secret_name := VARCHAR
Name of the gcp_pubsub secret to use when several exist.
Returns columns
project VARCHAR
Project that owns the resource.
resource_type VARCHAR
'topic', 'subscription', 'snapshot' or 'schema'.
resource VARCHAR
Full resource name the policy is attached to.
role VARCHAR
Role granted, e.g. 'roles/pubsub.subscriber'; NULL on an error row or for a resource with an empty policy.
member VARCHAR
Principal granted the role, e.g. 'serviceAccount:[email protected]', 'allUsers'.
member_type VARCHAR
Principal kind: 'user', 'serviceAccount', 'group', 'domain', 'principal', 'allUsers', 'allAuthenticatedUsers', 'deleted'...
condition_title VARCHAR
Title of the IAM condition on the binding; NULL when unconditional.
condition_expression VARCHAR
CEL expression of the IAM condition; NULL when unconditional.
policy_version BIGINT
IAM policy version (3 when conditions are present).
etag VARCHAR
Policy etag.
error VARCHAR
Why the policy could not be read: the API status, e.g. 'PERMISSION_DENIED', or 'UNIMPLEMENTED' / 'INVALID_ARGUMENT' on the emulator; NULL when it was read.
Examples (2)

Public grants on any topic, subscription, snapshot or schema

SELECT resource_type, resource, role, member
FROM pubsub.main.iam_policies()
WHERE member IN ('allUsers', 'allAuthenticatedUsers')
ORDER BY resource;

Which principals hold which roles on topics

SELECT member, list(DISTINCT role ORDER BY role) AS roles
FROM pubsub.main.iam_policies(resource_type := 'topic')
WHERE error IS NULL AND member IS NOT NULL
GROUP BY member
ORDER BY member;
Link
read_messages (topic VARCHAR, allow_temporary_subscription := BOOLEAN, start_time := TIMESTAMP WITH TIME ZONE, end_time := TIMESTAMP WITH TIME ZONE, snapshot := VARCHAR, filter := VARCHAR, max_messages := BIGINT, wait_seconds := BIGINT, truncate := BIGINT, project := VARCHAR, secret_name := VARCHAR) 2 examples

Replay a topic's retained messages through a temporary subscription (opt-in; never touches existing subscriptions)

Positional arguments
topic VARCHAR
Topic to read (id or full name). Messages are read through a new temporary subscription; existing subscriptions are never touched.
Named arguments
allow_temporary_subscription := BOOLEAN
Required opt-in. true acknowledges that the read CREATES a temporary subscription on the topic (vgi-temp-..., label vgi-temp=true, 24 h expiration), seeks it, pulls and acks on it only, and DELETES it at the end. Never pulls from an existing subscription. · default false
start_time := TIMESTAMP WITH TIME ZONE
Replay messages published at or after this time (seek). Default: the oldest the topic retains (now minus its message retention). Needs topic message retention.
end_time := TIMESTAMP WITH TIME ZONE
Drop messages published after this time.
snapshot := VARCHAR
Instead of start_time, seek the temporary subscription to this snapshot (id or full name) and read the backlog it captured.
filter := VARCHAR
Pub/Sub filter set on the temporary subscription (server-side), e.g. 'attributes.tenant = "a"'. Only attributes can be filtered.
max_messages := BIGINT
Stop after this many messages. · default 100
wait_seconds := BIGINT
Upper bound on the time spent pulling; the read also stops once the subscription is drained. · default 10
truncate := BIGINT
Return at most this many bytes of each message (payload_bytes still gives the full size). · default 65536
project := VARCHAR
Google Cloud project id; default the gcp_pubsub secret's PROJECT_ID.
secret_name := VARCHAR
Name of the gcp_pubsub secret to use when several exist.
Returns columns
project VARCHAR
Project of the topic.
topic VARCHAR
Topic id the message was published to.
subscription VARCHAR
The temporary subscription (vgi-temp-...) the message was read through; it is deleted when the read ends.
sequence BIGINT
Position of the message in its source. Always NULL: Pub/Sub has no offsets (kept for the shared messaging columns; use timestamp and message_id).
timestamp TIMESTAMPTZ
Publish time assigned by Pub/Sub (publishTime).
key VARCHAR
Ordering key the message was published with; NULL when none.
payload BLOB
Message data bytes (truncated to the truncate argument).
payload_text VARCHAR
The data as text when it is valid UTF-8, else NULL. Parse JSON payloads with payload_text::JSON.
payload_bytes BIGINT
Full data size in bytes (before any truncation).
headers MAP(VARCHAR, VARCHAR)
Message attributes (empty map when none).
message_id VARCHAR
Server-assigned message id, unique within the topic.
delivery_attempt BIGINT
Delivery attempt number; NULL (only set on subscriptions with a dead-letter policy).
Examples (2)

Replay retained messages of a topic through a temporary subscription (opt-in)

SELECT timestamp, key, headers['tenant'] AS tenant,
  payload_text::JSON->>'order_id' AS order_id
FROM pubsub.main.read_messages('orders', allow_temporary_subscription := true, start_time := TIMESTAMPTZ '2026-01-01 00:00:00+00', max_messages := 50)
ORDER BY timestamp, message_id;

What a snapshot's captured backlog contains, without touching the subscription it was taken from

SELECT headers['event'] AS event, count(*) AS messages,
  max(payload_bytes) AS largest
FROM pubsub.main.read_messages('orders', allow_temporary_subscription := true, snapshot := 'before-deploy', max_messages := 1000)
GROUP BY event
ORDER BY messages DESC;
Link
schema_revisions (schema VARCHAR, project := VARCHAR, page_size := BIGINT, secret_name := VARCHAR) 1 example

List every revision of a Pub/Sub schema with its definition

Positional arguments
schema VARCHAR
Schema id or full name (projects/<project>/schemas/<id>).
Named arguments
project := VARCHAR
Google Cloud project id; default the gcp_pubsub secret's PROJECT_ID.
page_size := BIGINT
Revisions requested per API page (pageSize); pages are fetched lazily. · default 100
secret_name := VARCHAR
Name of the gcp_pubsub secret to use when several exist.
Returns columns
project VARCHAR
Project that owns the schema.
schema VARCHAR
Schema id.
name VARCHAR
Full resource name, projects/<project>/schemas/<id> (topics reference this in their schema column).
type VARCHAR
'AVRO' or 'PROTOCOL_BUFFER'.
revision_id VARCHAR
Revision id (8 hex characters).
revision_create_time TIMESTAMPTZ
When this revision was committed.
definition VARCHAR
The schema definition text: Avro JSON or a .proto source.
Example

The revision history of a schema, newest first

SELECT revision_id, revision_create_time, definition
FROM pubsub.main.schema_revisions('order-avro')
ORDER BY revision_create_time DESC;
Link
schemas (project := VARCHAR, page_size := BIGINT, secret_name := VARCHAR) 2 examples

List Pub/Sub schemas with type, latest revision and definition

Named arguments
project := VARCHAR
Google Cloud project id; default the gcp_pubsub secret's PROJECT_ID.
page_size := BIGINT
Resources requested per API page (pageSize); pages are fetched lazily. · default 100
secret_name := VARCHAR
Name of the gcp_pubsub secret to use when several exist.
Returns columns
project VARCHAR
Project that owns the schema.
schema VARCHAR
Schema id.
name VARCHAR
Full resource name, projects/<project>/schemas/<id> (topics reference this in their schema column).
type VARCHAR
'AVRO' or 'PROTOCOL_BUFFER'.
revision_id VARCHAR
Revision id (8 hex characters).
revision_create_time TIMESTAMPTZ
When this revision was committed.
definition VARCHAR
The schema definition text: Avro JSON or a .proto source.
Examples (2)

Schemas with their type and current revision

SELECT schema, type, revision_id, length(definition) AS definition_chars
FROM pubsub.main.schemas()
ORDER BY schema;

How many topics use each schema

SELECT s.schema, count(t.name) AS topics
FROM pubsub.main.schemas() s
LEFT JOIN pubsub.main.topics() t ON t.schema = s.name
GROUP BY s.schema
ORDER BY topics DESC, s.schema;
Link
snapshots (topic := VARCHAR, project := VARCHAR, page_size := BIGINT, secret_name := VARCHAR) 1 example

List Pub/Sub snapshots with topic and expiry

Named arguments
topic := VARCHAR
Only snapshots of this topic (id or full name), via projects.topics.snapshots.list.
project := VARCHAR
Google Cloud project id; default the gcp_pubsub secret's PROJECT_ID.
page_size := BIGINT
Resources requested per API page (pageSize); pages are fetched lazily. · default 100
secret_name := VARCHAR
Name of the gcp_pubsub secret to use when several exist.
Returns columns
project VARCHAR
Project that owns the snapshot.
snapshot VARCHAR
Snapshot id.
name VARCHAR
Full resource name, projects/<project>/snapshots/<id>.
topic VARCHAR
Full name of the topic whose messages the snapshot retains.
expire_time TIMESTAMPTZ
When the snapshot expires (at most 7 days after the oldest unacked message it captured).
labels MAP(VARCHAR, VARCHAR)
Resource labels (empty map when none).
Example

Snapshots by expiry (the soonest to disappear first)

SELECT snapshot, topic, expire_time
FROM pubsub.main.snapshots()
ORDER BY expire_time;
Link
subscription_backlog (end_time := TIMESTAMP WITH TIME ZONE, lookback_minutes := BIGINT, subscription := VARCHAR, project := VARCHAR, secret_name := VARCHAR) 2 examples

Latest backlog size and oldest unacked message age (consumer lag) per subscription

Named arguments
end_time := TIMESTAMP WITH TIME ZONE
Look back from this time; default now.
lookback_minutes := BIGINT
How far back to look for the latest point (metrics are sampled every minute and arrive a few minutes late). · default 10
subscription := VARCHAR
Only this subscription (id or full name): pushed into the Monitoring filter.
project := VARCHAR
Google Cloud project id; default the gcp_pubsub secret's PROJECT_ID.
secret_name := VARCHAR
Name of the gcp_pubsub secret to use when several exist.
Returns columns
project VARCHAR
Project of the subscription.
subscription VARCHAR
Subscription id.
ts TIMESTAMPTZ
Time of the latest point used (the newest of the two metrics).
undelivered_messages BIGINT
Messages not yet acknowledged (num_undelivered_messages): the consumer lag in messages. NULL when the metric has no recent point.
oldest_unacked_age_seconds DOUBLE
Age of the oldest unacknowledged message in seconds (oldest_unacked_message_age): the consumer lag in time.
Examples (2)

Which subscriptions are furthest behind right now

SELECT subscription, undelivered_messages,
  oldest_unacked_age_seconds / 60 AS lag_minutes
FROM pubsub.main.subscription_backlog()
ORDER BY oldest_unacked_age_seconds DESC NULLS LAST;

Backlogged subscriptions with their dead-letter settings

SELECT s.subscription, s.dead_letter_topic, b.undelivered_messages
FROM pubsub.main.subscriptions() s
JOIN pubsub.main.subscription_backlog() b ON b.subscription = s.subscription
WHERE b.undelivered_messages > 1000
ORDER BY b.undelivered_messages DESC;
Link
subscriptions (topic := VARCHAR, subscription := VARCHAR, project := VARCHAR, page_size := BIGINT, secret_name := VARCHAR) 2 examples

List Pub/Sub subscriptions with delivery type, ack deadline, dead-letter, retry and push settings

Named arguments
topic := VARCHAR
Only subscriptions of this topic (id or full name). Pushed into the API: the topic's own subscription listing.
subscription := VARCHAR
Only this subscription (id or full name): one GET instead of a listing.
project := VARCHAR
Google Cloud project id; default the gcp_pubsub secret's PROJECT_ID.
page_size := BIGINT
Resources requested per API page (pageSize); pages are fetched lazily. · default 100
secret_name := VARCHAR
Name of the gcp_pubsub secret to use when several exist.
Returns columns
project VARCHAR
Project that owns the subscription.
subscription VARCHAR
Subscription id (the last part of the name).
name VARCHAR
Full resource name, projects/<project>/subscriptions/<id>.
topic VARCHAR
Full name of the topic it receives from; '_deleted-topic_' when the topic was deleted.
type VARCHAR
Delivery type: 'pull', 'push', 'bigquery' or 'cloud_storage'.
ack_deadline_seconds BIGINT
Seconds a subscriber has to acknowledge a message before redelivery.
message_retention_seconds DOUBLE
How long unacknowledged (and, with retain_acked_messages, acknowledged) messages are kept, in seconds.
retain_acked_messages BOOLEAN
Whether acknowledged messages are kept (needed to seek backwards in time).
enable_message_ordering BOOLEAN
Whether messages with the same ordering key are delivered in order.
enable_exactly_once_delivery BOOLEAN
Whether exactly-once delivery is enabled.
filter VARCHAR
Subscription filter on message attributes; NULL = every message.
labels MAP(VARCHAR, VARCHAR)
Resource labels (empty map when none).
expiration_ttl_seconds DOUBLE
Inactivity period after which the subscription is deleted, in seconds; NULL = never expires.
dead_letter_topic VARCHAR
Topic undeliverable messages are forwarded to; NULL = no dead-letter policy.
max_delivery_attempts BIGINT
Delivery attempts before a message is dead-lettered (5-100); NULL without a dead-letter policy.
retry_minimum_backoff_seconds DOUBLE
Minimum redelivery delay of the retry policy, in seconds; NULL = immediate redelivery.
retry_maximum_backoff_seconds DOUBLE
Maximum redelivery delay of the retry policy, in seconds.
detached BOOLEAN
Whether the subscription was detached from its topic (no longer receives messages).
push_endpoint_host VARCHAR
Host of the push endpoint (push subscriptions). Only the host is returned: endpoint paths and query strings can contain tokens.
push_oidc_service_account VARCHAR
Service account whose OIDC identity push requests carry; NULL when unauthenticated. No token or audience is returned.
push_unwrapped BOOLEAN
Whether push delivers the raw payload (no Pub/Sub wrapper); NULL for non-push subscriptions.
bigquery_table VARCHAR
Destination table (project.dataset.table) of a BigQuery subscription.
cloud_storage_bucket VARCHAR
Destination bucket of a Cloud Storage subscription.
export_state VARCHAR
State of a BigQuery or Cloud Storage export, e.g. 'ACTIVE', 'PERMISSION_DENIED', 'NOT_FOUND'.
export_service_account VARCHAR
Service account that writes BigQuery / Cloud Storage exports; NULL = the Pub/Sub service agent.
topic_message_retention_seconds DOUBLE
The topic's retention as seen by this subscription, in seconds.
state VARCHAR
Subscription state: 'ACTIVE' or 'RESOURCE_ERROR'; NULL when the API omits it (emulator).
Examples (2)

Every subscription with its delivery type, ack deadline and dead-letter topic

SELECT subscription, type, ack_deadline_seconds, dead_letter_topic,
  enable_exactly_once_delivery
FROM pubsub.main.subscriptions()
ORDER BY subscription;

Subscriptions per topic: topics with zero subscriptions drop every message

SELECT t.topic, count(s.name) AS subscriptions
FROM pubsub.main.topics() t
LEFT JOIN pubsub.main.subscriptions() s ON s.topic = t.name
GROUP BY t.topic
ORDER BY subscriptions, t.topic;
Link
time_series (metric VARCHAR, start_time := TIMESTAMP WITH TIME ZONE, end_time := TIMESTAMP WITH TIME ZONE, subscription := VARCHAR, topic := VARCHAR, filter := VARCHAR, alignment_seconds := BIGINT, aligner := VARCHAR, reducer := VARCHAR, group_by := VARCHAR, project := VARCHAR, page_size := BIGINT, secret_name := VARCHAR) 2 examples

Cloud Monitoring time series for a Pub/Sub metric as long rows (labels, ts, value)

Positional arguments
metric VARCHAR
Cloud Monitoring metric type. A path without a domain is taken as a Pub/Sub metric (pubsub.googleapis.com/ is prefixed); a full metric type is used as given.
Named arguments
start_time := TIMESTAMP WITH TIME ZONE
Interval start; default end_time minus one hour.
end_time := TIMESTAMP WITH TIME ZONE
Interval end; default now.
subscription := VARCHAR
Only this subscription (id or full name): pushed into the filter as resource.labels.subscription_id.
topic := VARCHAR
Only this topic (id or full name): pushed into the filter as resource.labels.topic_id.
filter := VARCHAR
Extra Cloud Monitoring filter ANDed to the metric filter, e.g. 'metric.labels.response_code = "success"'.
alignment_seconds := BIGINT
Alignment period in seconds (0 = raw points, no alignment). · default 60
aligner := VARCHAR
Per-series aligner; 'auto' sums *_count and byte_cost metrics and averages the rest. · default "auto"
reducer := VARCHAR
Optional cross-series reducer run server-side, e.g. 'REDUCE_SUM' (with group_by to keep some labels).
group_by := VARCHAR
Comma-separated labels kept by the reducer, e.g. 'resource.label.topic_id'.
project := VARCHAR
Google Cloud project id; default the gcp_pubsub secret's PROJECT_ID.
page_size := BIGINT
Points per API page; pages are fetched lazily. · default 1000
secret_name := VARCHAR
Name of the gcp_pubsub secret to use when several exist.
Returns columns
project VARCHAR
Project the series belongs to (resource label project_id).
metric VARCHAR
Full metric type, e.g. 'pubsub.googleapis.com/subscription/num_undelivered_messages'.
resource_type VARCHAR
Monitored resource type: 'pubsub_subscription', 'pubsub_topic' or 'pubsub_snapshot'.
topic VARCHAR
Topic id (resource label topic_id); NULL for subscription metrics.
subscription VARCHAR
Subscription id (resource label subscription_id); NULL for topic metrics.
labels MAP(VARCHAR, VARCHAR)
Every resource and metric label of the series (after any group_by reduction).
ts TIMESTAMPTZ
End of the point's interval (the sample time for gauges).
start_ts TIMESTAMPTZ
Start of the point's interval (for delta metrics, the aligned period start).
value DOUBLE
Point value: int64/double as DOUBLE, booleans as 0/1, distributions as their mean.
metric_kind VARCHAR
'GAUGE', 'DELTA' or 'CUMULATIVE' (after alignment).
value_type VARCHAR
'INT64', 'DOUBLE', 'BOOL' or 'DISTRIBUTION'.
unit VARCHAR
Unit of the value, e.g. 's', 'By', '1'.
Examples (2)

Peak backlog per subscription over a day

SELECT subscription, max(value) AS peak_backlog
FROM pubsub.main.time_series('subscription/num_undelivered_messages', start_time := TIMESTAMPTZ '2026-01-01 00:00:00+00', end_time := TIMESTAMPTZ '2026-01-02 00:00:00+00')
GROUP BY subscription
ORDER BY peak_backlog DESC;

Publish requests to a topic per 5 minutes by response code (last hour)

SELECT ts, labels['response_code'] AS response_code, value
FROM pubsub.main.time_series('topic/send_request_count', topic := 'orders', alignment_seconds := 300)
ORDER BY ts, response_code;
Link
topics (topic := VARCHAR, project := VARCHAR, page_size := BIGINT, secret_name := VARCHAR) 2 examples

List Pub/Sub topics with labels, retention, schema, KMS and ingestion settings

Named arguments
topic := VARCHAR
Only this topic (id or full name): one GET instead of a listing.
project := VARCHAR
Google Cloud project id; default the gcp_pubsub secret's PROJECT_ID.
page_size := BIGINT
Resources requested per API page (pageSize); pages are fetched lazily. · default 100
secret_name := VARCHAR
Name of the gcp_pubsub secret to use when several exist.
Returns columns
project VARCHAR
Project that owns the topic.
topic VARCHAR
Topic id (the last part of the name).
name VARCHAR
Full resource name, projects/<project>/topics/<topic>.
labels MAP(VARCHAR, VARCHAR)
Resource labels (empty map when none).
message_retention_seconds DOUBLE
How long the topic retains published messages (topic retention), in seconds; NULL when retention is off. Retention is what lets read_messages replay past messages.
schema VARCHAR
Full name of the schema messages must conform to; NULL when none.
schema_encoding VARCHAR
Message encoding required by the schema: 'JSON' or 'BINARY'.
schema_first_revision_id VARCHAR
Oldest schema revision messages may use; NULL = any.
schema_last_revision_id VARCHAR
Newest schema revision messages may use; NULL = any.
kms_key_name VARCHAR
Cloud KMS key protecting the topic (CMEK); NULL = Google-managed encryption.
allowed_persistence_regions VARCHAR[]
Regions where messages may be stored (message storage policy); empty = no restriction.
enforce_in_transit BOOLEAN
Whether the storage policy is also enforced in transit.
ingestion_source VARCHAR
Import topic source: 'awsKinesis', 'cloudStorage', 'azureEventHubs', 'awsMsk', 'confluentCloud'; NULL for an ordinary topic.
ingestion_settings VARCHAR
The ingestion data source settings as JSON (open shape); NULL for an ordinary topic.
message_transforms VARCHAR
Single Message Transforms (UDFs) as JSON; NULL when none.
state VARCHAR
Topic state: 'ACTIVE' or 'INGESTION_RESOURCE_ERROR'; NULL when the API omits it (emulator).
satisfies_pzs BOOLEAN
Whether the topic satisfies Physical Zone Separation.
Examples (2)

Every topic with its retention, schema and owning team label

SELECT topic, message_retention_seconds / 86400 AS retention_days, schema,
  labels['team'] AS team
FROM pubsub.main.topics()
ORDER BY topic;

Topics with neither CMEK nor retention (cannot be replayed)

SELECT topic
FROM pubsub.main.topics()
WHERE kms_key_name IS NULL AND message_retention_seconds IS NULL
ORDER BY topic;
Link

Credentials

The secret type pubsub declares, as reported by the worker itself.

gcp_pubsub

How to get these credentials

Google Cloud Pub/Sub connection: project, credentials (service account key JSON or OAuth access token) and optional endpoint overrides (emulator).

secret.sql
CREATE SECRET gcp_pubsub (
    TYPE gcp_pubsub,
    project_id           '<project_id>',
    service_account_json '<GCP_PUBSUB_SERVICE_ACCOUNT_JSON>',  -- secret
    access_token         '<ACCESS_TOKEN>',  -- secret
    endpoint             '<endpoint>',
    monitoring_endpoint  '<monitoring_endpoint>',
    quota_project_id     '<quota_project_id>'
);
Key Type Required Description
project_id VARCHAR — Default Google Cloud project id, e.g. 'my-project'. Functions take project := to override it.
service_account_json secret VARCHAR — Service account key file contents (JSON). The worker signs a JWT and exchanges it at the key's token_uri for an access token.
access_token secret VARCHAR — OAuth 2.0 access token (e.g. from `gcloud auth print-access-token`), sent as a bearer token. Expires after about an hour.
endpoint VARCHAR — Pub/Sub API root. Default https://pubsub.googleapis.com. For the emulator give its host:port (the PUBSUB_EMULATOR_HOST value) or http://host:port; no credentials are sent unless the secret has them.
monitoring_endpoint VARCHAR — Cloud Monitoring API root for time_series and subscription_backlog. Default https://monitoring.googleapis.com.
quota_project_id VARCHAR — Project billed for API quota, sent as x-goog-user-project (needed by some user credentials).

The worker doesn't mark which keys are required.

Needed by access_checkiam_policiesread_messagesschema_revisionsschemassnapshotssubscription_backlogsubscriptionstime_seriestopics

Create the secret in the same session, after attaching pubsub — the worker registers its secret types at ATTACH. Keys marked secret are masked in duckdb_secrets(); angle-bracket values are placeholders. Read credentials from your environment or secret store in your application and pass them through your SQL client’s parameter bindings. Keep real values out of saved SQL and history. Native DuckDB and Haybarn do not provide a SQL getenv() function.

Try these queries

Every topic with its retention, schema and owning team label

SELECT topic, message_retention_seconds / 86400 AS retention_days, schema,
  labels['team'] AS team
FROM pubsub.main.topics()
ORDER BY topic

Uses topics

Every subscription with its delivery type, ack deadline and dead-letter topic

SELECT subscription, type, ack_deadline_seconds, dead_letter_topic,
  enable_exactly_once_delivery
FROM pubsub.main.subscriptions()
ORDER BY subscription

Uses subscriptions

Snapshots by expiry (the soonest to disappear first)

SELECT snapshot, topic, expire_time
FROM pubsub.main.snapshots()
ORDER BY expire_time

Uses snapshots

Schemas with their type and current revision

SELECT schema, type, revision_id, length(definition) AS definition_chars
FROM pubsub.main.schemas()
ORDER BY schema

Uses schemas

The revision history of a schema, newest first

SELECT revision_id, revision_create_time, definition
FROM pubsub.main.schema_revisions('order-avro')
ORDER BY revision_create_time DESC

Uses schema_revisions

Public grants on any topic, subscription, snapshot or schema

SELECT resource_type, resource, role, member
FROM pubsub.main.iam_policies()
WHERE member IN ('allUsers', 'allAuthenticatedUsers')
ORDER BY resource

Uses iam_policies

16 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • Which Pub/Sub subscriptions deliver by push, and to which host?
  • Which Pub/Sub resources grant a role to allUsers or allAuthenticatedUsers?
  • Which subscriptions have a dead-letter topic, and after how many delivery attempts are messages dead-lettered?
  • Which BigQuery or Cloud Storage export subscriptions are not in the ACTIVE state?
  • How many revisions does the payment-proto schema have, and when was the newest one created?
  • At 2026-01-01 00:05 UTC, which subscription had the most undelivered messages, and how many?

Google Pub/Sub is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.