# Google Pub/Sub

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

This page includes setup, release pins, credentials, hosting and verification evidence. [JSON alternative](https://query.farm/products/orchard/api/v1/connectors/pubsub.json) contains the same setup facts for structured readers; choose one format.

## Runtime and release

Use DuckDB or Haybarn **2.0.1** with **VGI protocol 3.4**.
Catalog alias: `pubsub`. Release: [v0.2.0](https://github.com/Query-farm/vgi-pubsub/releases/tag/v0.2.0). Metadata generated: 2026-12-01T18:22:16+00:00.

## Choose where it runs

- On your machine: use an installation method below. No Query Farm account is required for local execution.
- Self-host: follow [the connector deployment instructions](https://github.com/Query-farm/vgi-pubsub) and [connection guide](https://query.farm/vgi/connect-to-a-worker/). Use your real endpoint and its authentication settings.
- Query Farm hosted: [create a deployment](https://auth.queryfarm.cloud/console/new?worker=pubsub). Hosting has a $10 monthly minimum per organization; usage and license fees may apply. Copy the deployment-specific ATTACH from the console.

## Service credentials and prerequisites

Supply your own service credentials or required connection options before querying protected data.

Secret parameter required flags describe the upstream declaration; they do not override the service-level mode above. Keep secrets in environment variables or the deployment secret store. SQL values in angle brackets are placeholders, not automatic environment lookups. Native DuckDB and Haybarn 2.0.1 do not provide a SQL getenv() function, even when worker-supplied snippets mention it. Read environment variables in your application and pass credential values through client parameter bindings (for example, Python con.execute("CREATE SECRET stripe (TYPE stripe, api_key ?)", [os.environ["STRIPE_API_KEY"]]) after attaching the connector. Omit unused optional parameters and keep real values out of saved SQL and logs.

After installing VGI and attaching the connector, create the required secrets using your own values. Replace placeholders and omit unused optional parameters from the templates below.

### gcp_pubsub

Google Cloud Pub/Sub connection: project, credentials (service account key JSON or OAuth access token) and optional endpoint overrides (emulator).
[Credential instructions](https://github.com/Query-farm/vgi-pubsub#secrets-and-configuration)

```json
[
  {
    "name": "project_id",
    "type": "VARCHAR",
    "required": false,
    "redact": false,
    "description": "Default Google Cloud project id, e.g. 'my-project'. Functions take project := to override it."
  },
  {
    "name": "service_account_json",
    "type": "VARCHAR",
    "required": false,
    "redact": true,
    "description": "Service account key file contents (JSON). The worker signs a JWT and exchanges it at the key's token_uri for an access token."
  },
  {
    "name": "access_token",
    "type": "VARCHAR",
    "required": false,
    "redact": true,
    "description": "OAuth 2.0 access token (e.g. from `gcloud auth print-access-token`), sent as a bearer token. Expires after about an hour."
  },
  {
    "name": "endpoint",
    "type": "VARCHAR",
    "required": false,
    "redact": false,
    "description": "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."
  },
  {
    "name": "monitoring_endpoint",
    "type": "VARCHAR",
    "required": false,
    "redact": false,
    "description": "Cloud Monitoring API root for time_series and subscription_backlog. Default https://monitoring.googleapis.com."
  },
  {
    "name": "quota_project_id",
    "type": "VARCHAR",
    "required": false,
    "redact": false,
    "description": "Project billed for API quota, sent as x-goog-user-project (needed by some user credentials)."
  }
]
```

```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>'
);
```

ATTACH options (exact declarations; omitted defaults are unknown):

```json
[
  {
    "name": "use_application_default_credentials",
    "type": "BOOLEAN",
    "description": "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.",
    "required": false,
    "default": null
  }
]
```

## Install the extension

In stock DuckDB:

```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;
```

In Haybarn:

```sql
INSTALL vgi FROM community;
LOAD vgi;
```

## Attach the connector

The local recipes below pin the catalog release for repeatability. A public demo endpoint follows its deployed release.

### From GitHub

Attach the release directly

Uses the verified release each time you attach the connector.

```sql
ATTACH 'pubsub' AS pubsub (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/vgi-pubsub@v0.2.0'
);
```

### Docker

Attach the signed image

Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.

```sql
ATTACH 'pubsub' AS pubsub (
  TYPE vgi,
  LOCATION 'oci://ghcr.io/query-farm/vgi-pubsub:0.2.0'
);
```

## Find subscriptions falling behind

Service credentials required for this example: yes.

```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
```

- [pubsub.main.subscription_backlog — table_function](https://query.farm/products/orchard/connectors/pubsub/objects/table_function.bWFpbg.c3Vic2NyaXB0aW9uX2JhY2tsb2c.md): exact declaration for this example.

Execution evidence: **not_captured**.

No executed result is recorded for this exact example. Catalog verification does not establish that this query ran.
Supply the required setup and verify your own execution before claiming success.

## Connector reference

### Google Cloud Pub/Sub in DuckDB

Inventory and troubleshoot Pub/Sub from SQL with typed columns: durations as `DOUBLE` seconds, times as `TIMESTAMPTZ`, labels and attributes as `MAP`.

- **Resources**: topics (retention, schema, CMEK, ingestion), subscriptions (type, ack deadline, dead-letter, retry, exactly-once, filter; push endpoint host only), snapshots, schemas and revisions.
- **IAM**: resource policies flattened to role/member rows, with unreadable policies reported, not hidden.
- **Backlog**: Cloud Monitoring series (`labels`, `ts`, `value`) and the current consumer lag per subscription.
- **Messages**: opt-in replay of retained messages through a temporary subscription that the worker deletes. Existing subscriptions are never pulled from.

Credentials come from a `gcp_pubsub` DuckDB secret (service account key or access token).

Upstream references: the [Pub/Sub REST API](https://cloud.google.com/pubsub/docs/reference/rest), [Pub/Sub monitoring metrics](https://cloud.google.com/pubsub/docs/monitoring) via the [Cloud Monitoring API](https://cloud.google.com/monitoring/api/v3), [Pub/Sub access control](https://cloud.google.com/pubsub/docs/access-control), and the [Pub/Sub emulator](https://cloud.google.com/pubsub/docs/emulator).

## Find the exact SQL object

[Browse 13 object declarations](https://query.farm/products/orchard/api/v1/connectors/pubsub/objects.json) or [search within this connector](https://query.farm/products/orchard/api/v1/search.json?kind=object&connector=pubsub&q=pubsub).

Follow one format of each needed object for complete argument types, defaults, named flags, return columns and examples. Existing links above can replace another search. For questions about hosting, credentials or supported operations, stop once the documentation answers the question; SQL and unrelated object lookups are unnecessary.

## Verification and interpretation

- Missing, null, or undeclared metadata means unknown; do not invent defaults, credential scope, platform support or endpoint URLs.
- Search is keyword retrieval, not proof of a capability. Read the exact object declaration before generating SQL.
- A table and a table function can have the same name. Preserve parentheses and use the matching overload and schema.
- Service credentials, external data availability and deployment authentication are separate requirements.
- Catalog verification records the harvest environment. It is not proof that every query or current live API call succeeds. Only an example with captured_result has a saved result for that exact SQL.

```json
{
  "generatedAt": "2026-12-01T18:22:16+00:00",
  "repository": "https://github.com/Query-farm/vgi-pubsub",
  "harvest": {
    "status": "ok",
    "method": "github-auto",
    "error": null,
    "vgi_version": "9773130dde"
  },
  "catalogVerification": {
    "verified": true,
    "status": "passed",
    "total": 3,
    "passed": 3,
    "failed": 0,
    "needs_credentials": 0,
    "location": "github-auto://Query-farm/vgi-pubsub@v0.2.0",
    "transport": "github-auto",
    "environment": {
      "vgi_extension_version": "9773130dde",
      "haybarn_version": "2.0.1rc3",
      "engine_version": "v2.0.1",
      "python": "3.12.4",
      "platform": "darwin_arm64",
      "protocol_version": "3.4.0"
    },
    "checked_at": "2026-12-01T06:16:09+00:00"
  },
  "interpretation": "Catalog verification records the harvest environment. It is not proof that every query or current live API call succeeds. Only an example with captured_result has a saved result for that exact SQL."
}
```
