OCI Node.js Client for Database Management Service
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
-
ServiceError: NotAuthenticated. The required information to complete authentication was not supplied.
cause Missing or invalid API key, config file, or authentication provider setup.fixEnsure `~/.oci/config` is correctly configured, including private key path. Verify environment variables for API key auth or correct instance principal setup. -
ServiceError: NotAuthorizedOrNotFound. Authorization failed or requested resource not found.
cause Insufficient IAM permissions for the principal making the request, or the resource OCID/name is incorrect/doesn't exist in the specified compartment/region.fixCheck OCI IAM policies for the user/group or instance principal. Verify the resource OCID and compartment OCID. Confirm the client's region matches the resource's region. -
getaddrinfo ENOTFOUND <service-endpoint>.region.oraclecloud.com
cause Incorrect region specified, or a network connectivity issue preventing DNS resolution of the OCI service endpoint.fixDouble-check the region string (e.g., `us-ashburn-1`, not `ashburn`). Ensure your network allows outbound connections to OCI endpoints. -
TypeError: DatabaseManagementClient is not a constructor
cause CommonJS `require()` syntax used in an environment primarily expecting ES Modules, or incorrect access to the exported class.fixIf using ES Modules, use `import { DatabaseManagementClient } from 'oci-databasemanagement';`. If forced to use CommonJS, use `const { DatabaseManagementClient } = require('oci-databasemanagement');` or `const DatabaseManagementClient = require('oci-databasemanagement').DatabaseManagementClient;`, though ESM is preferred. -
ServiceError: InvalidParameter. compartmentId is required.
cause A required parameter for an API operation (e.g., `compartmentId` for listing resources) was omitted or passed as `undefined`.fixReview the API documentation for the specific request object (e.g., `ListManagedDatabasesRequest`) and ensure all `required` properties are provided with valid values.
Warnings
- gotcha Incorrect or missing OCI configuration file (~/.oci/config), misconfigured environment variables (OCI_CONFIG_FILE_PATH, OCI_PROFILE), or invalid API key details are the most common source of `NotAuthenticated` errors. Ensure the `authenticationDetailsProvider` is correctly instantiated.
- gotcha The client's configured region must match the region where the target resources exist. Mismatched regions can lead to `NotAuthorizedOrNotFound` errors or `Hostname not found` errors, as the SDK attempts to connect to an incorrect endpoint.
- breaking Even with correct authentication, operations will fail with `NotAuthorizedOrNotFound` if the OCI user or instance principal lacks the necessary IAM policies to perform actions on the target resources in the specified compartment.
- gotcha Older Node.js projects using CommonJS `require()` might encounter issues with the OCI SDK, which is primarily designed for ES Modules (`import`). Using `require('oci-databasemanagement').DatabaseManagementClient` might lead to unexpected behavior or `TypeError: ... is not a constructor`.
- breaking While minor releases are additive, major version updates (e.g., `v1` to `v2`) of the OCI SDK can introduce significant breaking changes, including API method signature alterations, model property renames, or complete refactoring of client classes.
Install
-
npm install oci-databasemanagement -
yarn add oci-databasemanagement -
pnpm add oci-databasemanagement
Imports
- DatabaseManagementClient
const DatabaseManagementClient = require('oci-databasemanagement').DatabaseManagementClient;import { DatabaseManagementClient } from 'oci-databasemanagement'; - models
import * as models from 'oci-databasemanagement/lib/model';
- common
import { ConfigFileAuthenticationDetailsProvider } from 'oci-databasemanagement';import * as common from 'oci-common';
- Auth
import { Auth } from 'oci-common';
Quickstart
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();