OCI Node.js Client for Database Management Service

2.130.0 · active · verified Wed Apr 22

This package provides the official Oracle Cloud Infrastructure (OCI) Node.js client for interacting with the Database Management Service (DMS). It enables developers to programmatically manage and monitor various aspects of Oracle Databases within OCI, including performance diagnostics, SQL tuning, resource utilization, and lifecycle operations. The current stable version is 2.130.0, which is part of the larger OCI TypeScript SDK. The SDK maintains a rapid release cadence, with frequent minor versions released often weekly or bi-weekly, continuously adding support for new OCI services, features, and regions across the entire cloud platform. Its primary differentiators include being the officially supported client from Oracle, guaranteeing compatibility with the latest OCI API specifications, and providing comprehensive TypeScript type definitions for enhanced developer experience. This module is essential for automating database administration tasks and integrating OCI Database Management into custom applications.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to initialize the OCI Database Management client using various authentication methods and list managed databases within a specified compartment and region.

import { DatabaseManagementClient } from 'oci-databasemanagement';
import * as common from 'oci-common';
import * as models from 'oci-databasemanagement/lib/model'; // Correct path for models

async function listManagedDatabasesExample() {
    // Ensure these environment variables are set or replace with actual values
    const COMPARTMENT_OCID = process.env.OCI_COMPARTMENT_OCID ?? 'ocid1.compartment.oc1..examplecompartmentid';
    const REGION = process.env.OCI_REGION ?? 'us-ashburn-1'; // e.g., 'us-phoenix-1'

    // Configure authentication using a config file (~/.oci/config)
    // and a specific profile (e.g., 'DEFAULT') or pass a ConfigFileAuthenticationDetailsProvider instance.
    let provider: common.Auth.AuthenticationDetailsProvider;
    try {
        provider = new common.ConfigFileAuthenticationDetailsProvider();
        // Set the region from the provider's config or explicitly
        common.Region.set(provider.getRegion());
    } catch (error) {
        console.warn("Could not load OCI config file, attempting instance principal or resource principal authentication.");
        // Fallback to instance principal or resource principal if config file fails
        provider = new common.InstancePrincipalAuthenticationDetailsProvider();
        common.Region.set(REGION); // Explicitly set region for instance principal
    }


    const client = new DatabaseManagementClient({ authenticationDetailsProvider: provider });
    // You can also explicitly set the region if not derived from provider or for overriding
    client.region = REGION;

    try {
        const listManagedDatabasesRequest: models.ListManagedDatabasesRequest = {
            compartmentId: COMPARTMENT_OCID,
            limit: 10,
        };

        console.log(`Listing managed databases in compartment: ${COMPARTMENT_OCID} in region: ${client.region}...`);
        const response = await client.listManagedDatabases(listManagedDatabasesRequest);

        if (response.managedDatabaseCollection.items.length > 0) {
            console.log(`Found ${response.managedDatabaseCollection.items.length} managed databases:`);
            response.managedDatabaseCollection.items.forEach(db => {
                console.log(`  - Name: ${db.name}, ID: ${db.id}, Status: ${db.lifecycleState}`);
            });
        } else {
            console.log('No managed databases found in this compartment.');
        }
    } catch (error) {
        console.error('Error listing managed databases:', error);
        if (error instanceof common.ServiceError) {
            console.error(`OCI Service Error: ${error.statusCode} - ${error.serviceCode} - ${error.message}`);
        }
    }
}

listManagedDatabasesExample();

view raw JSON →