- [HTTP request](https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/demoteMaster#body.HTTP_TEMPLATE)
- [Path parameters](https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/demoteMaster#body.PATH_PARAMETERS)
- [Request body](https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/demoteMaster#body.request_body)
- [Response body](https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/demoteMaster#body.response_body)
- [Authorization scopes](https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/demoteMaster#body.aspect)
- [InstancesDemoteMasterRequest](https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/demoteMaster#InstancesDemoteMasterRequest)
  - [JSON representation](https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/demoteMaster#InstancesDemoteMasterRequest.SCHEMA_REPRESENTATION)
- [DemoteMasterContext](https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/demoteMaster#DemoteMasterContext)
  - [JSON representation](https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/demoteMaster#DemoteMasterContext.SCHEMA_REPRESENTATION)
- [DemoteMasterConfiguration](https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/demoteMaster#DemoteMasterConfiguration)
  - [JSON representation](https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/demoteMaster#DemoteMasterConfiguration.SCHEMA_REPRESENTATION)
- [DemoteMasterMySqlReplicaConfiguration](https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/demoteMaster#DemoteMasterMySqlReplicaConfiguration)
  - [JSON representation](https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/demoteMaster#DemoteMasterMySqlReplicaConfiguration.SCHEMA_REPRESENTATION)
- [Examples](https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/demoteMaster#examples)
- [Try it!](https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/demoteMaster#try-it)

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](https://google.aip.dev/127) 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 `https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/demoteMaster#InstancesDemoteMasterRequest`.

### Response body

If successful, the response body contains an instance of `https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/operations#Operation`.

### Authorization scopes

Requires one of the following OAuth scopes:

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

For more information, see the [Authentication Overview](https://docs.cloud.google.com/docs/authentication#authorization-gcp).

## InstancesDemoteMasterRequest

Database demote primary instance request.

| JSON representation |
|---|
| ``` { "demoteMasterContext": { object (`https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/demoteMaster#DemoteMasterContext`) } } ``` |

| Fields ||
|---|---|
| `demoteMasterContext` | ``object (`https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/demoteMaster#DemoteMasterContext`)`` Contains details about the demoteMaster operation. |

## DemoteMasterContext

Database instance demote primary instance context.

| JSON representation |
|---|
| ``` { "kind": string, "verifyGtidConsistency": boolean, "masterInstanceName": string, "replicaConfiguration": { object (`https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/demoteMaster#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 (`https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/demoteMaster#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 (`https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/demoteMaster#DemoteMasterMySqlReplicaConfiguration`) } } ``` |

| Fields ||
|---|---|
| `kind` | `string` This is always `sql#demoteMasterConfiguration`. |
| `mysqlReplicaConfiguration` | ``object (`https://docs.cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances/demoteMaster#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 corresponding 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. |