Method: instances.demoteMaster

Demotes the stand-alone instance to be a Cloud SQL read replica for an external database server.

HTTP request

POST https://sqladmin.googleapis.com/sql/v1beta4/projects/{project}/instances/{instance}/demoteMaster

The URL uses gRPC Transcoding syntax.

Path parameters

Parameters
project

string

ID of the project that contains the instance.

instance

string

Cloud SQL instance name.

Request body

The request body contains an instance of InstancesDemoteMasterRequest.

Response body

If successful, the response body contains an instance of Operation.

Authorization Scopes

Requires one of the following OAuth scopes:

  • https://www.googleapis.com/auth/cloud-platform
  • https://www.googleapis.com/auth/sqlservice.admin

For more information, see the Authentication Overview.

InstancesDemoteMasterRequest

Database demote primary instance request.

JSON representation
{
  "demoteMasterContext": {
    object (DemoteMasterContext)
  }
}
Fields
demoteMasterContext

object (DemoteMasterContext)

Contains details about the demoteMaster operation.

DemoteMasterContext

Database instance demote primary instance context.

JSON representation
{
  "kind": string,
  "verifyGtidConsistency": boolean,
  "masterInstanceName": string,
  "replicaConfiguration": {
    object (DemoteMasterConfiguration)
  },
  "skipReplicationSetup": boolean
}
Fields
kind

string

This is always sql#demoteMasterContext.

verifyGtidConsistency

boolean

Verify the GTID consistency for demote operation. Default value: True. Setting this flag to false enables you to bypass the GTID consistency check between on-premises primary instance and Cloud SQL instance during the demotion operation but also exposes you to the risk of future replication failures. Change the value only if you know the reason for the GTID divergence and are confident that doing so will not cause any replication issues.

masterInstanceName

string

The name of the instance which will act as on-premises primary instance in the replication setup.

replicaConfiguration

object (DemoteMasterConfiguration)

Configuration specific to read-replicas replicating from the on-premises primary instance.

skipReplicationSetup

boolean

Flag to skip replication setup on the instance.

DemoteMasterConfiguration

Read-replica configuration for connecting to the on-premises primary instance.

JSON representation
{
  "kind": string,
  "mysqlReplicaConfiguration": {
    object (DemoteMasterMySqlReplicaConfiguration)
  }
}
Fields
kind

string

This is always sql#demoteMasterConfiguration.

mysqlReplicaConfiguration

object (DemoteMasterMySqlReplicaConfiguration)

MySQL specific configuration when replicating from a MySQL on-premises primary instance. Replication configuration information such as the username, password, certificates, and keys are not stored in the instance metadata. The configuration information is used only to set up the replication connection and is stored by MySQL in a file named master.info in the data directory.

DemoteMasterMySqlReplicaConfiguration

Read-replica configuration specific to MySQL databases.

JSON representation
{
  "kind": string,
  "username": string,
  "password": string,
  "clientKey": string,
  "clientCertificate": string,
  "caCertificate": string
}
Fields
kind

string

This is always sql#demoteMasterMysqlReplicaConfiguration.

username

string

The username for the replication connection.

password

string

The password for the replication connection.

clientKey

string

PEM representation of the replica's private key. The corresponsing public key is encoded in the client's certificate. The format of the replica's private key can be either PKCS #1 or PKCS #8.

clientCertificate

string

PEM representation of the replica's x509 certificate.

caCertificate

string

PEM representation of the trusted CA's x509 certificate.

Examples

Uses the .NET client library.

// BEFORE RUNNING:
// ---------------
// 1. If not already done, enable the Cloud SQL Administration API
//    and check the quota for your project at
//    https://console.developers.google.com/apis/api/sqladmin
// 2. This sample uses Application Default Credentials for authentication.
//    If not already done, install the gcloud CLI from
//    https://cloud.google.com/sdk and run
//    `gcloud beta auth application-default login`.
//    For more information, see
//    https://developers.google.com/identity/protocols/application-default-credentials
// 3. Install the C# client library by adding a dependency on the relevant NuGet
//    package. Libraries published by Google are owned by google-apis-packages:
//    https://www.nuget.org/profiles/google-apis-packages

using Google.Apis.Auth.OAuth2;
using Google.Apis.SQLAdmin.v1beta4;
using Google.Apis.Services;
using Newtonsoft.Json;
using System;
using System.Threading.Tasks;

using Data = Google.Apis.SQLAdmin.v1beta4.Data;

namespace SQLAdminSample
{
   
public class SQLAdminExample
   
{
       
public static void Main(string[] args)
       
{
           
SQLAdminService sqlAdminService = new SQLAdminService(new BaseClientService.Initializer
           
{
               
HttpClientInitializer = GetCredential(),
               
ApplicationName = "Google-SQLAdminSample/0.1",
           
});

           
// ID of the project that contains the instance.
           
string project = "my-project";  // TODO: Update placeholder value.

           
// Cloud SQL instance name.
           
string instance = "my-instance";  // TODO: Update placeholder value.

           
// TODO: Assign values to desired properties of `requestBody`:
           
Data.InstancesDemoteMasterRequest requestBody = new Data.InstancesDemoteMasterRequest();

           
InstancesResource.DemoteMasterRequest request = sqlAdminService.Instances.DemoteMaster(requestBody, project, instance);

           
// To execute asynchronously in an async method, replace `request.Execute()` as shown:
           
Data.Operation response = request.Execute();
           
// Data.Operation response = await request.ExecuteAsync();

           
// TODO: Change code below to process the `response` object:
           
Console.WriteLine(JsonConvert.SerializeObject(response));
       
}

       
public static GoogleCredential GetCredential()
       
{
           
GoogleCredential credential = Task.Run(() => GoogleCredential.GetApplicationDefaultAsync()).Result;
           
if (credential.IsCreateScopedRequired)
           
{
                credential
= credential.CreateScoped("https://www.googleapis.com/auth/cloud-platform");
           
}
           
return credential;
       
}
   
}
}

Uses the Go client library.

package main

// BEFORE RUNNING:
// ---------------
// 1. If not already done, enable the Cloud SQL Administration API
//    and check the quota for your project at
//    https://console.developers.google.com/apis/api/sqladmin
// 2. This sample uses Application Default Credentials for authentication.
//    If not already done, install the gcloud CLI from
//    https://cloud.google.com/sdk/ and run
//    `gcloud beta auth application-default login`.
//    For more information, see
//    https://developers.google.com/identity/protocols/application-default-credentials
// 3. Install and update the Go dependencies by running `go get -u` in the
//    project directory.

import (
       
"fmt"
       
"log"

       
"golang.org/x/net/context"
       
"golang.org/x/oauth2/google"
       
"google.golang.org/api/sqladmin/v1beta4"
)

func main
() {
        ctx
:= context.Background()

        c
, err := google.DefaultClient(ctx, sqladmin.CloudPlatformScope)
       
if err != nil {
                log
.Fatal(err)
       
}

        sqladminService
, err := sqladmin.New(c)
       
if err != nil {
                log
.Fatal(err)
       
}

       
// ID of the project that contains the instance.
        project
:= "my-project" // TODO: Update placeholder value.

       
// Cloud SQL instance name.
        instance
:= "my-instance" // TODO: Update placeholder value.

        rb
:= &sqladmin.InstancesDemoteMasterRequest{
               
// TODO: Add desired fields of the request body.
       
}

        resp
, err := sqladminService.Instances.DemoteMaster(project, instance, rb).Context(ctx).Do()
       
if err != nil {
                log
.Fatal(err)
       
}

       
// TODO: Change code below to process the `resp` object:
        fmt
.Printf("%#v\n", resp)
}

Uses the Node.js client library.

// BEFORE RUNNING:
// ---------------
// 1. If not already done, enable the Cloud SQL Admin API
//    and check the quota for your project at
//    https://console.developers.google.com/apis/api/sqladmin
// 2. This sample uses Application Default Credentials for authentication.
//    If not already done, install the gcloud CLI from
//    https://cloud.google.com/sdk and run
//    `gcloud beta auth application-default login`.
//    For more information, see
//    https://developers.google.com/identity/protocols/application-default-credentials
// 3. Install the Node.js client library by running
//    `npm install googleapis --save`

const {google} = require('googleapis');
var sqlAdmin = google.sqladmin('v1beta4');

authorize
(function(authClient) {
 
var request = {
   
// ID of the project that contains the instance.
    project
: 'my-project',  // TODO: Update placeholder value.

   
// Cloud SQL instance name.
    instance
: 'my-instance',  // TODO: Update placeholder value.

    resource
: {
     
// TODO: Add desired properties to the request body.
   
},

    auth
: authClient,
 
};

  sqlAdmin
.instances.demoteMaster(request, function(err, response) {
   
if (err) {
      console
.error(err);
     
return;
   
}

   
// TODO: Change code below to process the `response` object:
    console
.log(JSON.stringify(response, null, 2));
 
});
});

function authorize(callback) {
  google
.auth.getClient({
    scopes
: ['https://www.googleapis.com/auth/cloud-platform']
 
}).then(client => {
    callback
(client);
 
}).catch(err => {
    console
.error('authentication failed: ', err);
 
});
}

Uses the Python client library.

"""
BEFORE RUNNING:
---------------
1. If not already done, enable the Cloud SQL Administration API
   and check the quota for your project at
   https://console.developers.google.com/apis/api/sqladmin
2. This sample uses Application Default Credentials for authentication.
   If not already done, install the gcloud CLI from
   https://cloud.google.com/sdk and run
   `gcloud beta auth application-default login`.
   For more information, see
   https://developers.google.com/identity/protocols/application-default-credentials
3. Install the Python client library for Google APIs by running
   `pip install --upgrade google-api-python-client`
"""

from pprint import pprint

from googleapiclient import discovery
from oauth2client.client import GoogleCredentials

credentials
= GoogleCredentials.get_application_default()

service
= discovery.build('sqladmin', 'v1beta4', credentials=credentials)

# ID of the project that contains the instance.
project
= 'my-project'  # TODO: Update placeholder value.

# Cloud SQL instance name.
instance
= 'my-instance'  # TODO: Update placeholder value.

instances_demote_master_request_body
= {
   
# TODO: Add desired entries to the request body.
}

request
= service.instances().demoteMaster(project=project, instance=instance, body=instances_demote_master_request_body)
response
= request.execute()

# TODO: Change code below to process the `response` dict:
pprint
(response)