Reference documentation and code samples for the Cloud Spanner V1 Client class DatabaseAdminClient.
Service Description: Cloud Spanner Database Admin API
The Cloud Spanner Database Admin API can be used to:
- create, drop, and list databases
- update the schema of pre-existing databases
- create, delete and list backups for a database
- restore a database from an existing backup
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
$databaseAdminClient = new DatabaseAdminClient();
try {
$formattedParent = $databaseAdminClient->instanceName('[PROJECT]', '[INSTANCE]');
$backupId = 'backup_id';
$formattedSourceBackup = $databaseAdminClient->backupName('[PROJECT]', '[INSTANCE]', '[BACKUP]');
$expireTime = new Timestamp();
$operationResponse = $databaseAdminClient->copyBackup($formattedParent, $backupId, $formattedSourceBackup, $expireTime);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
$result = $operationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $databaseAdminClient->copyBackup($formattedParent, $backupId, $formattedSourceBackup, $expireTime);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $databaseAdminClient->resumeOperation($operationName, 'copyBackup');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
$result = $newOperationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$databaseAdminClient->close();
}
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parseName method to extract the individual identifiers contained within formatted names that are returned by the API.
This service has a new (beta) implementation. See Google\Cloud\Spanner\Admin\Database\V1\Client\DatabaseAdminClient to use the new surface.
Namespace
Google \ Cloud \ Spanner \ Admin \ Database \ V1Methods
__construct
Constructor.
Parameters | |
---|---|
Name | Description |
options |
array
Optional. Options for configuring the service API wrapper. |
↳ apiEndpoint |
string
The address of the API remote host. May optionally include the port, formatted as "
|
↳ credentials |
string|array|FetchAuthTokenInterface|CredentialsWrapper
The credentials to be used by the client to authorize API calls. This option accepts either a path to a credentials file, or a decoded credentials file as a PHP array. Advanced usage: In addition, this option can also accept a pre-constructed Google\Auth\FetchAuthTokenInterface object or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored. |
↳ credentialsConfig |
array
Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see Google\ApiCore\CredentialsWrapper::build() . |
↳ disableRetries |
bool
Determines whether or not retries defined by the client configuration should be disabled. Defaults to |
↳ clientConfig |
string|array
Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder. |
↳ transport |
string|TransportInterface
The transport used for executing network requests. May be either the string |
↳ transportConfig |
array
Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'grpc' => [...], 'rest' => [...], ]; See the Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods for the supported options. |
↳ clientCertSource |
callable
A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS. |
copyBackup
Starts copying a Cloud Spanner Backup.
The returned backup long-running operation
will have a name of the format
projects/<project>/instances/<instance>/backups/<backup>/operations/<operation_id>
and can be used to track copying of the backup. The operation is associated
with the destination backup.
The metadata field type is
CopyBackupMetadata.
The response field type is
Backup, if successful. Cancelling the returned operation will stop the
copying and delete the backup.
Concurrent CopyBackup requests can run on the same source backup.
Sample code:
$databaseAdminClient = new DatabaseAdminClient();
try {
$formattedParent = $databaseAdminClient->instanceName('[PROJECT]', '[INSTANCE]');
$backupId = 'backup_id';
$formattedSourceBackup = $databaseAdminClient->backupName('[PROJECT]', '[INSTANCE]', '[BACKUP]');
$expireTime = new Timestamp();
$operationResponse = $databaseAdminClient->copyBackup($formattedParent, $backupId, $formattedSourceBackup, $expireTime);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
$result = $operationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $databaseAdminClient->copyBackup($formattedParent, $backupId, $formattedSourceBackup, $expireTime);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $databaseAdminClient->resumeOperation($operationName, 'copyBackup');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
$result = $newOperationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$databaseAdminClient->close();
}
Parameters | |
---|---|
Name | Description |
parent |
string
Required. The name of the destination instance that will contain the backup copy.
Values are of the form: |
backupId |
string
Required. The id of the backup copy.
The |
sourceBackup |
string
Required. The source backup to be copied.
The source backup needs to be in READY state for it to be copied.
Once CopyBackup is in progress, the source backup cannot be deleted or
cleaned up on expiration until CopyBackup is finished.
Values are of the form:
|
expireTime |
Google\Protobuf\Timestamp
Required. The expiration time of the backup in microsecond granularity.
The expiration time must be at least 6 hours and at most 366 days
from the |
optionalArgs |
array
Optional. |
↳ encryptionConfig |
CopyBackupEncryptionConfig
Optional. The encryption configuration used to encrypt the backup. If this field is not specified, the backup will use the same encryption configuration as the source backup by default, namely encryption_type = |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
createBackup
Starts creating a new Cloud Spanner Backup.
The returned backup long-running operation
will have a name of the format
projects/<project>/instances/<instance>/backups/<backup>/operations/<operation_id>
and can be used to track creation of the backup. The
metadata field type is
CreateBackupMetadata. The
response field type is
Backup, if successful. Cancelling the returned operation will stop the
creation and delete the backup.
There can be only one pending backup creation per database. Backup creation
of different databases can run concurrently.
Sample code:
$databaseAdminClient = new DatabaseAdminClient();
try {
$formattedParent = $databaseAdminClient->instanceName('[PROJECT]', '[INSTANCE]');
$backupId = 'backup_id';
$backup = new Backup();
$operationResponse = $databaseAdminClient->createBackup($formattedParent, $backupId, $backup);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
$result = $operationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $databaseAdminClient->createBackup($formattedParent, $backupId, $backup);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $databaseAdminClient->resumeOperation($operationName, 'createBackup');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
$result = $newOperationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$databaseAdminClient->close();
}
Parameters | |
---|---|
Name | Description |
parent |
string
Required. The name of the instance in which the backup will be
created. This must be the same instance that contains the database the
backup will be created from. The backup will be stored in the
location(s) specified in the instance configuration of this
instance. Values are of the form
|
backupId |
string
Required. The id of the backup to be created. The |
backup |
Google\Cloud\Spanner\Admin\Database\V1\Backup
Required. The backup to create. |
optionalArgs |
array
Optional. |
↳ encryptionConfig |
CreateBackupEncryptionConfig
Optional. The encryption configuration used to encrypt the backup. If this field is not specified, the backup will use the same encryption configuration as the database by default, namely encryption_type = |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
createDatabase
Creates a new Cloud Spanner database and starts to prepare it for serving.
The returned long-running operation will
have a name of the format <database_name>/operations/<operation_id>
and
can be used to track preparation of the database. The
metadata field type is
CreateDatabaseMetadata. The
response field type is
Database, if successful.
Sample code:
$databaseAdminClient = new DatabaseAdminClient();
try {
$formattedParent = $databaseAdminClient->instanceName('[PROJECT]', '[INSTANCE]');
$createStatement = 'create_statement';
$operationResponse = $databaseAdminClient->createDatabase($formattedParent, $createStatement);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
$result = $operationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $databaseAdminClient->createDatabase($formattedParent, $createStatement);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $databaseAdminClient->resumeOperation($operationName, 'createDatabase');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
$result = $newOperationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$databaseAdminClient->close();
}
Parameters | |
---|---|
Name | Description |
parent |
string
Required. The name of the instance that will serve the new database.
Values are of the form |
createStatement |
string
Required. A |
optionalArgs |
array
Optional. |
↳ extraStatements |
string[]
Optional. A list of DDL statements to run inside the newly created database. Statements can create tables, indexes, etc. These statements execute atomically with the creation of the database: if there is an error in any statement, the database is not created. |
↳ encryptionConfig |
EncryptionConfig
Optional. The encryption configuration for the database. If this field is not specified, Cloud Spanner will encrypt/decrypt all data at rest using Google default encryption. |
↳ databaseDialect |
int
Optional. The dialect of the Cloud Spanner Database. For allowed values, use constants defined on Google\Cloud\Spanner\Admin\Database\V1\DatabaseDialect |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
deleteBackup
Deletes a pending or completed Backup.
Sample code:
$databaseAdminClient = new DatabaseAdminClient();
try {
$formattedName = $databaseAdminClient->backupName('[PROJECT]', '[INSTANCE]', '[BACKUP]');
$databaseAdminClient->deleteBackup($formattedName);
} finally {
$databaseAdminClient->close();
}
Parameters | |
---|---|
Name | Description |
name |
string
Required. Name of the backup to delete.
Values are of the form
|
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
dropDatabase
Drops (aka deletes) a Cloud Spanner database.
Completed backups for the database will be retained according to their
expire_time
.
Note: Cloud Spanner might continue to accept requests for a few seconds
after the database has been deleted.
Sample code:
$databaseAdminClient = new DatabaseAdminClient();
try {
$formattedDatabase = $databaseAdminClient->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]');
$databaseAdminClient->dropDatabase($formattedDatabase);
} finally {
$databaseAdminClient->close();
}
Parameters | |
---|---|
Name | Description |
database |
string
Required. The database to be dropped. |
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
getBackup
Gets metadata on a pending or completed Backup.
Sample code:
$databaseAdminClient = new DatabaseAdminClient();
try {
$formattedName = $databaseAdminClient->backupName('[PROJECT]', '[INSTANCE]', '[BACKUP]');
$response = $databaseAdminClient->getBackup($formattedName);
} finally {
$databaseAdminClient->close();
}
Parameters | |
---|---|
Name | Description |
name |
string
Required. Name of the backup.
Values are of the form
|
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Spanner\Admin\Database\V1\Backup |
getDatabase
Gets the state of a Cloud Spanner database.
Sample code:
$databaseAdminClient = new DatabaseAdminClient();
try {
$formattedName = $databaseAdminClient->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]');
$response = $databaseAdminClient->getDatabase($formattedName);
} finally {
$databaseAdminClient->close();
}
Parameters | |
---|---|
Name | Description |
name |
string
Required. The name of the requested database. Values are of the form
|
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Spanner\Admin\Database\V1\Database |
getDatabaseDdl
Returns the schema of a Cloud Spanner database as a list of formatted DDL statements. This method does not show pending schema updates, those may be queried using the Operations API.
Sample code:
$databaseAdminClient = new DatabaseAdminClient();
try {
$formattedDatabase = $databaseAdminClient->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]');
$response = $databaseAdminClient->getDatabaseDdl($formattedDatabase);
} finally {
$databaseAdminClient->close();
}
Parameters | |
---|---|
Name | Description |
database |
string
Required. The database whose schema we wish to get.
Values are of the form
|
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Spanner\Admin\Database\V1\GetDatabaseDdlResponse |
getIamPolicy
Gets the access control policy for a database or backup resource.
Returns an empty policy if a database or backup exists but does not have a policy set.
Authorization requires spanner.databases.getIamPolicy
permission on
resource.
For backups, authorization requires spanner.backups.getIamPolicy
permission on resource.
Sample code:
$databaseAdminClient = new DatabaseAdminClient();
try {
$resource = 'resource';
$response = $databaseAdminClient->getIamPolicy($resource);
} finally {
$databaseAdminClient->close();
}
Parameters | |
---|---|
Name | Description |
resource |
string
REQUIRED: The resource for which the policy is being requested. See the operation documentation for the appropriate value for this field. |
optionalArgs |
array
Optional. |
↳ options |
GetPolicyOptions
OPTIONAL: A |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Iam\V1\Policy |
listBackupOperations
Lists the backup long-running operations in
the given instance. A backup operation has a name of the form
projects/<project>/instances/<instance>/backups/<backup>/operations/<operation>
.
The long-running operation
metadata field type
metadata.type_url
describes the type of the metadata. Operations returned
include those that have completed/failed/canceled within the last 7 days,
and pending operations. Operations returned are ordered by
operation.metadata.value.progress.start_time
in descending order starting
from the most recently started operation.
Sample code:
$databaseAdminClient = new DatabaseAdminClient();
try {
$formattedParent = $databaseAdminClient->instanceName('[PROJECT]', '[INSTANCE]');
// Iterate over pages of elements
$pagedResponse = $databaseAdminClient->listBackupOperations($formattedParent);
foreach ($pagedResponse->iteratePages() as $page) {
foreach ($page as $element) {
// doSomethingWith($element);
}
}
// Alternatively:
// Iterate through all elements
$pagedResponse = $databaseAdminClient->listBackupOperations($formattedParent);
foreach ($pagedResponse->iterateAllElements() as $element) {
// doSomethingWith($element);
}
} finally {
$databaseAdminClient->close();
}
Parameters | |
---|---|
Name | Description |
parent |
string
Required. The instance of the backup operations. Values are of
the form |
optionalArgs |
array
Optional. |
↳ filter |
string
An expression that filters the list of returned backup operations. A filter expression consists of a field name, a comparison operator, and a value for filtering. The value must be a string, a number, or a boolean. The comparison operator must be one of: |
↳ pageSize |
int
The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved. |
↳ pageToken |
string
A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
listBackups
Lists completed and pending backups.
Backups returned are ordered by create_time
in descending order,
starting from the most recent create_time
.
Sample code:
$databaseAdminClient = new DatabaseAdminClient();
try {
$formattedParent = $databaseAdminClient->instanceName('[PROJECT]', '[INSTANCE]');
// Iterate over pages of elements
$pagedResponse = $databaseAdminClient->listBackups($formattedParent);
foreach ($pagedResponse->iteratePages() as $page) {
foreach ($page as $element) {
// doSomethingWith($element);
}
}
// Alternatively:
// Iterate through all elements
$pagedResponse = $databaseAdminClient->listBackups($formattedParent);
foreach ($pagedResponse->iterateAllElements() as $element) {
// doSomethingWith($element);
}
} finally {
$databaseAdminClient->close();
}
Parameters | |
---|---|
Name | Description |
parent |
string
Required. The instance to list backups from. Values are of the
form |
optionalArgs |
array
Optional. |
↳ filter |
string
An expression that filters the list of returned backups. A filter expression consists of a field name, a comparison operator, and a value for filtering. The value must be a string, a number, or a boolean. The comparison operator must be one of: |
↳ pageSize |
int
The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved. |
↳ pageToken |
string
A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
listDatabaseOperations
Lists database longrunning-operations.
A database operation has a name of the form
projects/<project>/instances/<instance>/databases/<database>/operations/<operation>
.
The long-running operation
metadata field type
metadata.type_url
describes the type of the metadata. Operations returned
include those that have completed/failed/canceled within the last 7 days,
and pending operations.
Sample code:
$databaseAdminClient = new DatabaseAdminClient();
try {
$formattedParent = $databaseAdminClient->instanceName('[PROJECT]', '[INSTANCE]');
// Iterate over pages of elements
$pagedResponse = $databaseAdminClient->listDatabaseOperations($formattedParent);
foreach ($pagedResponse->iteratePages() as $page) {
foreach ($page as $element) {
// doSomethingWith($element);
}
}
// Alternatively:
// Iterate through all elements
$pagedResponse = $databaseAdminClient->listDatabaseOperations($formattedParent);
foreach ($pagedResponse->iterateAllElements() as $element) {
// doSomethingWith($element);
}
} finally {
$databaseAdminClient->close();
}
Parameters | |
---|---|
Name | Description |
parent |
string
Required. The instance of the database operations.
Values are of the form |
optionalArgs |
array
Optional. |
↳ filter |
string
An expression that filters the list of returned operations. A filter expression consists of a field name, a comparison operator, and a value for filtering. The value must be a string, a number, or a boolean. The comparison operator must be one of: |
↳ pageSize |
int
The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved. |
↳ pageToken |
string
A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
listDatabaseRoles
Lists Cloud Spanner database roles.
Sample code:
$databaseAdminClient = new DatabaseAdminClient();
try {
$formattedParent = $databaseAdminClient->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]');
// Iterate over pages of elements
$pagedResponse = $databaseAdminClient->listDatabaseRoles($formattedParent);
foreach ($pagedResponse->iteratePages() as $page) {
foreach ($page as $element) {
// doSomethingWith($element);
}
}
// Alternatively:
// Iterate through all elements
$pagedResponse = $databaseAdminClient->listDatabaseRoles($formattedParent);
foreach ($pagedResponse->iterateAllElements() as $element) {
// doSomethingWith($element);
}
} finally {
$databaseAdminClient->close();
}
Parameters | |
---|---|
Name | Description |
parent |
string
Required. The database whose roles should be listed.
Values are of the form
|
optionalArgs |
array
Optional. |
↳ pageSize |
int
The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved. |
↳ pageToken |
string
A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
listDatabases
Lists Cloud Spanner databases.
Sample code:
$databaseAdminClient = new DatabaseAdminClient();
try {
$formattedParent = $databaseAdminClient->instanceName('[PROJECT]', '[INSTANCE]');
// Iterate over pages of elements
$pagedResponse = $databaseAdminClient->listDatabases($formattedParent);
foreach ($pagedResponse->iteratePages() as $page) {
foreach ($page as $element) {
// doSomethingWith($element);
}
}
// Alternatively:
// Iterate through all elements
$pagedResponse = $databaseAdminClient->listDatabases($formattedParent);
foreach ($pagedResponse->iterateAllElements() as $element) {
// doSomethingWith($element);
}
} finally {
$databaseAdminClient->close();
}
Parameters | |
---|---|
Name | Description |
parent |
string
Required. The instance whose databases should be listed.
Values are of the form |
optionalArgs |
array
Optional. |
↳ pageSize |
int
The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved. |
↳ pageToken |
string
A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
restoreDatabase
Create a new database by restoring from a completed backup. The new
database must be in the same project and in an instance with the same
instance configuration as the instance containing
the backup. The returned database long-running
operation has a name of the format
projects/<project>/instances/<instance>/databases/<database>/operations/<operation_id>
,
and can be used to track the progress of the operation, and to cancel it.
The metadata field type is RestoreDatabaseMetadata. The response type is Database, if successful. Cancelling the returned operation will stop the restore and delete the database. There can be only one database being restored into an instance at a time. Once the restore operation completes, a new restore operation can be initiated, without waiting for the optimize operation associated with the first restore to complete.
Sample code:
$databaseAdminClient = new DatabaseAdminClient();
try {
$formattedParent = $databaseAdminClient->instanceName('[PROJECT]', '[INSTANCE]');
$databaseId = 'database_id';
$operationResponse = $databaseAdminClient->restoreDatabase($formattedParent, $databaseId);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
$result = $operationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $databaseAdminClient->restoreDatabase($formattedParent, $databaseId);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $databaseAdminClient->resumeOperation($operationName, 'restoreDatabase');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
$result = $newOperationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$databaseAdminClient->close();
}
Parameters | |
---|---|
Name | Description |
parent |
string
Required. The name of the instance in which to create the
restored database. This instance must be in the same project and
have the same instance configuration as the instance containing
the source backup. Values are of the form
|
databaseId |
string
Required. The id of the database to create and restore to. This
database must not already exist. The |
optionalArgs |
array
Optional. |
↳ backup |
string
Name of the backup from which to restore. Values are of the form |
↳ encryptionConfig |
RestoreDatabaseEncryptionConfig
Optional. An encryption configuration describing the encryption type and key resources in Cloud KMS used to encrypt/decrypt the database to restore to. If this field is not specified, the restored database will use the same encryption configuration as the backup by default, namely encryption_type = |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
setIamPolicy
Sets the access control policy on a database or backup resource.
Replaces any existing policy.
Authorization requires spanner.databases.setIamPolicy
permission on resource.
For backups, authorization requires spanner.backups.setIamPolicy
permission on resource.
Sample code:
$databaseAdminClient = new DatabaseAdminClient();
try {
$resource = 'resource';
$policy = new Policy();
$response = $databaseAdminClient->setIamPolicy($resource, $policy);
} finally {
$databaseAdminClient->close();
}
Parameters | |
---|---|
Name | Description |
resource |
string
REQUIRED: The resource for which the policy is being specified. See the operation documentation for the appropriate value for this field. |
policy |
Google\Cloud\Iam\V1\Policy
REQUIRED: The complete policy to be applied to the |
optionalArgs |
array
Optional. |
↳ updateMask |
FieldMask
OPTIONAL: A FieldMask specifying which fields of the policy to modify. Only the fields in the mask will be modified. If no mask is provided, the following default mask is used: |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Iam\V1\Policy |
testIamPermissions
Returns permissions that the caller has on the specified database or backup resource.
Attempting this RPC on a non-existent Cloud Spanner database will
result in a NOT_FOUND error if the user has
spanner.databases.list
permission on the containing Cloud
Spanner instance. Otherwise returns an empty set of permissions.
Calling this method on a backup that does not exist will
result in a NOT_FOUND error if the user has
spanner.backups.list
permission on the containing instance.
Sample code:
$databaseAdminClient = new DatabaseAdminClient();
try {
$resource = 'resource';
$permissions = [];
$response = $databaseAdminClient->testIamPermissions($resource, $permissions);
} finally {
$databaseAdminClient->close();
}
Parameters | |
---|---|
Name | Description |
resource |
string
REQUIRED: The resource for which the policy detail is being requested. See the operation documentation for the appropriate value for this field. |
permissions |
string[]
The set of permissions to check for the |
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Iam\V1\TestIamPermissionsResponse |
updateBackup
Updates a pending or completed Backup.
Sample code:
$databaseAdminClient = new DatabaseAdminClient();
try {
$backup = new Backup();
$updateMask = new FieldMask();
$response = $databaseAdminClient->updateBackup($backup, $updateMask);
} finally {
$databaseAdminClient->close();
}
Parameters | |
---|---|
Name | Description |
backup |
Google\Cloud\Spanner\Admin\Database\V1\Backup
Required. The backup to update.
|
updateMask |
Google\Protobuf\FieldMask
Required. A mask specifying which fields (e.g. |
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Spanner\Admin\Database\V1\Backup |
updateDatabase
Updates a Cloud Spanner database. The returned
long-running operation can be used to track
the progress of updating the database. If the named database does not
exist, returns NOT_FOUND
.
While the operation is pending:
- The database's reconciling field is set to true.
- Cancelling the operation is best-effort. If the cancellation succeeds,
the operation metadata's
cancel_time
is set, the updates are reverted, and the operation terminates with a
CANCELLED
status. - New UpdateDatabase requests will return a
FAILED_PRECONDITION
error until the pending operation is done (returns successfully or with error). - Reading the database via the API continues to give the pre-request values.
Upon completion of the returned operation:
- The new values are in effect and readable via the API.
- The database's reconciling field becomes false.
The returned long-running operation will
have a name of the format
projects/<project>/instances/<instance>/databases/<database>/operations/<operation_id>
and can be used to track the database modification. The
metadata field type is
UpdateDatabaseMetadata.
The response field type is
Database, if successful.
Sample code:
$databaseAdminClient = new DatabaseAdminClient();
try {
$database = new Database();
$updateMask = new FieldMask();
$operationResponse = $databaseAdminClient->updateDatabase($database, $updateMask);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
$result = $operationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $databaseAdminClient->updateDatabase($database, $updateMask);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $databaseAdminClient->resumeOperation($operationName, 'updateDatabase');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
$result = $newOperationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$databaseAdminClient->close();
}
Parameters | |
---|---|
Name | Description |
database |
Google\Cloud\Spanner\Admin\Database\V1\Database
Required. The database to update.
The |
updateMask |
Google\Protobuf\FieldMask
Required. The list of fields to update. Currently, only
|
optionalArgs |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
updateDatabaseDdl
Updates the schema of a Cloud Spanner database by
creating/altering/dropping tables, columns, indexes, etc. The returned
long-running operation will have a name of
the format <database_name>/operations/<operation_id>
and can be used to
track execution of the schema change(s). The
metadata field type is
UpdateDatabaseDdlMetadata. The operation has no response.
Sample code:
$databaseAdminClient = new DatabaseAdminClient();
try {
$formattedDatabase = $databaseAdminClient->databaseName('[PROJECT]', '[INSTANCE]', '[DATABASE]');
$statements = [];
$operationResponse = $databaseAdminClient->updateDatabaseDdl($formattedDatabase, $statements);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
// operation succeeded and returns no value
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $databaseAdminClient->updateDatabaseDdl($formattedDatabase, $statements);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $databaseAdminClient->resumeOperation($operationName, 'updateDatabaseDdl');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
// operation succeeded and returns no value
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$databaseAdminClient->close();
}
Parameters | |
---|---|
Name | Description |
database |
string
Required. The database to update. |
statements |
string[]
Required. DDL statements to be applied to the database. |
optionalArgs |
array
Optional. |
↳ operationId |
string
If empty, the new update request is assigned an automatically-generated operation ID. Otherwise, |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
getOperationsClient
Return an OperationsClient object with the same endpoint as $this.
Returns | |
---|---|
Type | Description |
Google\ApiCore\LongRunning\OperationsClient |
resumeOperation
Resume an existing long running operation that was previously started by a long running API method. If $methodName is not provided, or does not match a long running API method, then the operation can still be resumed, but the OperationResponse object will not deserialize the final response.
Parameters | |
---|---|
Name | Description |
operationName |
string
The name of the long running operation |
methodName |
string
The name of the method used to start the operation |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
static::backupName
Formats a string containing the fully-qualified path to represent a backup resource.
Parameters | |
---|---|
Name | Description |
project |
string
|
instance |
string
|
backup |
string
|
Returns | |
---|---|
Type | Description |
string | The formatted backup resource. |
static::cryptoKeyName
Formats a string containing the fully-qualified path to represent a crypto_key resource.
Parameters | |
---|---|
Name | Description |
project |
string
|
location |
string
|
keyRing |
string
|
cryptoKey |
string
|
Returns | |
---|---|
Type | Description |
string | The formatted crypto_key resource. |
static::cryptoKeyVersionName
Formats a string containing the fully-qualified path to represent a crypto_key_version resource.
Parameters | |
---|---|
Name | Description |
project |
string
|
location |
string
|
keyRing |
string
|
cryptoKey |
string
|
cryptoKeyVersion |
string
|
Returns | |
---|---|
Type | Description |
string | The formatted crypto_key_version resource. |
static::databaseName
Formats a string containing the fully-qualified path to represent a database resource.
Parameters | |
---|---|
Name | Description |
project |
string
|
instance |
string
|
database |
string
|
Returns | |
---|---|
Type | Description |
string | The formatted database resource. |
static::instanceName
Formats a string containing the fully-qualified path to represent a instance resource.
Parameters | |
---|---|
Name | Description |
project |
string
|
instance |
string
|
Returns | |
---|---|
Type | Description |
string | The formatted instance resource. |
static::parseName
Parses a formatted name string and returns an associative array of the components in the name.
The following name formats are supported: Template: Pattern
- backup: projects/{project}/instances/{instance}/backups/{backup}
- cryptoKey: projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}
- cryptoKeyVersion: projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}/cryptoKeyVersions/{crypto_key_version}
- database: projects/{project}/instances/{instance}/databases/{database}
- instance: projects/{project}/instances/{instance}
The optional $template argument can be supplied to specify a particular pattern, and must match one of the templates listed above. If no $template argument is provided, or if the $template argument does not match one of the templates listed, then parseName will check each of the supported templates, and return the first match.
Parameters | |
---|---|
Name | Description |
formattedName |
string
The formatted name string |
template |
string
Optional name of template to match |
Returns | |
---|---|
Type | Description |
array | An associative array from name component IDs to component values. |
Constants
SERVICE_NAME
Value: 'google.spanner.admin.database.v1.DatabaseAdmin'
The name of the service.
SERVICE_ADDRESS
Value: 'spanner.googleapis.com'
The default address of the service.
DEFAULT_SERVICE_PORT
Value: 443
The default port of the service.
CODEGEN_NAME
Value: 'gapic'
The name of the code generator, to be included in the agent header.