Delete a schema for a topic

You can delete schemas with the Google Cloud console,Google Cloud CLI, client library, or Pub/Sub API.

Caution: Deletion is permanent. You cannot restore a schema that is deleted.Any messages published to a topic that used the deleted schema cannot be writtento BigQuery using aBigQuerysubscription withuse topic schemaenabled.

Before you begin

Required roles and permissions

To get the permissions that you need to delete and manage schemas, ask your administrator to grant you thePub/Sub Editor (roles/pubsub.editor) IAM role on your project. For more information about granting roles, seeManage access to projects, folders, and organizations.

This predefined role contains the permissions required to delete and manage schemas. To see the exact permissions that are required, expand theRequired permissions section:

Required permissions

The following permissions are required to delete and manage schemas:

  • Create schema:pubsub.schemas.create
  • Attach schema to topic:pubsub.schemas.attach
  • Commit a schema revision:pubsub.schemas.commit
  • Delete a schema or a schema revision:pubsub.schemas.delete
  • Get a schema or schema revisions:pubsub.schemas.get
  • List schemas:pubsub.schemas.list
  • List schema revisions:pubsub.schemas.listRevisions
  • Rollback a schema:pubsub.schemas.rollback
  • Validate a message:pubsub.schemas.validate
  • Get the IAM policy for a schema:pubsub.schemas.getIamPolicy
  • Configure theIAM policy for a schema:pubsub.schemas.setIamPolicy

You might also be able to get these permissions withcustom roles or otherpredefined roles.

You can grant roles and permissions to principals such as users, groups,domains, or service accounts. You can create a schema in one project andattach it to a topic located in a different project.Ensure that you have the required permissions foreach project.

Delete a schema

Here is a list of important information about deleting schemas:

  • If a schema is deleted, all attempts to publish messages to topics associatedwith that schema fail.

  • The delete operation for a schema also deletes all the revisions associated withthe schema.

  • You can create a schema with the same name as the one that you just deleted.However, the newly created schema is entirely independent of the previouslydeleted one.

  • Before deleting a schema, ensure you removeits association from a topic.

Console

  1. In the Google Cloud console, go to thePub/Sub schemas page.

    Go to Schemas

  2. Select one or more schemas that you want to delete.

  3. ClickDelete.

  4. Confirm the delete operation.

gcloud

gcloud pubsub schemas deleteSCHEMA_NAME

REST

To delete a schema send a DELETE request like the following:

DELETE https://pubsub.googleapis.com/v1/SCHEMA_NAME

C++

Before trying this sample, follow the C++ setup instructions inQuickstart: Using Client Libraries. For more information, see thePub/Sub C++ API reference documentation.

namespacepubsub=::google::cloud::pubsub;[](pubsub::SchemaServiceClientclient,std::stringconst&project_id,std::stringconst&schema_id){google::pubsub::v1::DeleteSchemaRequestrequest;request.set_name(pubsub::Schema(project_id,schema_id).FullName());autostatus=client.DeleteSchema(request);// Note that kNotFound is a possible result when the library retries.if(status.code()==google::cloud::StatusCode::kNotFound){std::cout <<"The schema was not found\n";return;}if(!status.ok())throwstd::runtime_error(status.message());std::cout <<"Schema successfully deleted\n";}

C#

Before trying this sample, follow the C# setup instructions inQuickstart: Using Client Libraries. For more information, see thePub/Sub C# API reference documentation.

usingGoogle.Cloud.PubSub.V1;publicclassDeleteSchemaSample{publicvoidDeleteSchema(stringprojectId,stringschemaId){SchemaServiceClientschemaService=SchemaServiceClient.Create();SchemaNameschemaName=SchemaName.FromProjectSchema(projectId,schemaId);schemaService.DeleteSchema(schemaName);}}

Go

The following sample uses the major version of the Go Pub/Sub client library (v2). If you are still using the v1 library, seethe migration guide to v2.To see a list of v1 code samples, seethe deprecated code samples.

Before trying this sample, follow the Go setup instructions inQuickstart: Using Client Libraries.For more information, see thePub/Sub Go API reference documentation.

import("context""fmt""io"pubsub"cloud.google.com/go/pubsub/v2/apiv1""cloud.google.com/go/pubsub/v2/apiv1/pubsubpb")funcdeleteSchema(wio.Writer,projectID,schemaIDstring)error{// projectID := "my-project-id"// schemaID := "my-schema"ctx:=context.Background()client,err:=pubsub.NewSchemaClient(ctx)iferr!=nil{returnfmt.Errorf("pubsub.NewSchemaClient: %w",err)}deferclient.Close()req:=&pubsubpb.DeleteSchemaRequest{Name:fmt.Sprintf("projects/%s/schemas/%s",projectID,schemaID),}iferr:=client.DeleteSchema(ctx,req);err!=nil{returnfmt.Errorf("client.DeleteSchema: %w",err)}fmt.Fprintf(w,"Deleted schema: %s",schemaID)returnnil}

Java

Before trying this sample, follow the Java setup instructions inQuickstart: Using Client Libraries. For more information, see thePub/Sub Java API reference documentation.

importcom.google.api.gax.rpc.NotFoundException;importcom.google.cloud.pubsub.v1.SchemaServiceClient;importcom.google.pubsub.v1.SchemaName;importjava.io.IOException;publicclassDeleteSchemaExample{publicstaticvoidmain(String...args)throwsException{// TODO(developer): Replace these variables before running the sample.StringprojectId="your-project-id";StringschemaId="your-schema-id";deleteSchemaExample(projectId,schemaId);}publicstaticvoiddeleteSchemaExample(StringprojectId,StringschemaId)throwsIOException{SchemaNameschemaName=SchemaName.of(projectId,schemaId);try(SchemaServiceClientschemaServiceClient=SchemaServiceClient.create()){schemaServiceClient.deleteSchema(schemaName);System.out.println("Deleted a schema:"+schemaName);}catch(NotFoundExceptione){System.out.println(schemaName+"not found.");}}}

Node.js

Before trying this sample, follow the Node.js setup instructions inQuickstart: Using Client Libraries. For more information, see thePub/Sub Node.js API reference documentation.

/** * TODO(developer): Uncomment this variable before running the sample. */// const schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID';// Imports the Google Cloud client libraryconst{PubSub}=require('@google-cloud/pubsub');// Creates a client; cache this for further useconstpubSubClient=newPubSub();asyncfunctiondeleteSchema(schemaNameOrId){constschema=pubSubClient.schema(schemaNameOrId);constname=awaitschema.getName();awaitschema.delete();console.log(`Schema${name} deleted.`);}

Node.js

Before trying this sample, follow the Node.js setup instructions inQuickstart: Using Client Libraries. For more information, see thePub/Sub Node.js API reference documentation.

/** * TODO(developer): Uncomment this variable before running the sample. */// const schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID';// Imports the Google Cloud client libraryimport{PubSub}from'@google-cloud/pubsub';// Creates a client; cache this for further useconstpubSubClient=newPubSub();asyncfunctiondeleteSchema(schemaNameOrId:string){constschema=pubSubClient.schema(schemaNameOrId);constname=awaitschema.getName();awaitschema.delete();console.log(`Schema${name} deleted.`);}

PHP

Before trying this sample, follow the PHP setup instructions inQuickstart: Using Client Libraries. For more information, see thePub/Sub PHP API reference documentation.

use Google\Cloud\PubSub\PubSubClient;/** * Delete a schema. * * @param string $projectId * @param string $schemaId */function delete_schema($projectId, $schemaId){    $pubsub = new PubSubClient([        'projectId' => $projectId,    ]);    $schema = $pubsub->schema($schemaId);    if ($schema->exists()) {        $schema->delete();        printf('Schema %s deleted.', $schema->name());    } else {        printf('Schema %s does not exist.', $schema->name());    }}

Python

Before trying this sample, follow the Python setup instructions inQuickstart: Using Client Libraries. For more information, see thePub/Sub Python API reference documentation.

fromgoogle.api_core.exceptionsimportNotFoundfromgoogle.cloud.pubsubimportSchemaServiceClient# TODO(developer): Replace these variables before running the sample.# project_id = "your-project-id"# schema_id = "your-schema-id"schema_client=SchemaServiceClient()schema_path=schema_client.schema_path(project_id,schema_id)try:schema_client.delete_schema(request={"name":schema_path})print(f"Deleted a schema:\n{schema_path}")exceptNotFound:print(f"{schema_id} not found.")

Ruby

The following sample uses Ruby Pub/Sub client library v3. If you are still using the v2 library, see the migration guide to v3.To see a list of Ruby v2 code samples, seethe deprecated code samples.

Before trying this sample, follow the Ruby setup instructions inQuickstart: Using Client Libraries.For more information, see thePub/Sub Ruby API reference documentation.

# schema_id = "your-schema-id"pubsub=Google::Cloud::PubSub.newschemas=pubsub.schemasresult=schemas.delete_schemaname:pubsub.schema_path(schema_id)puts"Schema#{schema_id} deleted."

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.