Para habilitar las conexiones a un clúster de bases de datos desde direcciones IP fuera de tu organización de GDC, consulta Habilita las conexiones externas.
Accede a la consola de GDC con una cuenta vinculada al rol de project-db-admin para encontrar la siguiente información para conectarte a tu clúster de base de datos. Esta información se encuentra en la sección Conectividad de la página Servicio de base de datos.
Estos pasos incluyen un ejemplo para conectarse a la base de datos con psql. Los pasos exactos variarán según el software del cliente que elijas.
Console
Navega a la sección Connectivity de la página Database Service del clúster de la base de datos. En esta página, se incluye lo siguiente:
La contraseña de la cuenta de administrador (el nombre de usuario es dbsadmin)
Nombre de host y número de puerto del extremo principal del clúster de la base de datos
Indica si el clúster de base de datos permite la conexión externa desde fuera de la organización.
Un comando psql para conectarse al clúster (para clústeres de bases de datos de PostgreSQL y AlloyDB Omni)
Cadena para conectarse al clúster con conectividad a bases de datos de Java (JDBC) (para clústeres de bases de datos de Oracle)
Un vínculo para descargar el certificado de la autoridad certificadora (CA) del clúster de base de datos
Descarga el certificado de CA desde la consola de GDC en la sección Conectividad de la página Servicio de base de datos de tu clúster de base de datos.
Configura tu cliente para que use el certificado de la CA y verifique la base de datos. Para los clientes de psql, establece la variable de entorno PGSSLROOTCERT en la ruta de acceso del archivo de certificado y la variable de entorno PGSSLMODE según tus preferencias:
Configura tu cliente para que use el certificado de la CA y verifique la base de datos. En el caso de los clientes de psql, puedes establecer la variable de entorno PGSSLROOTCERT en la ruta de acceso del archivo de certificado y la variable de entorno PGSSLMODE según tus preferencias:
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-04 (UTC)"],[],[],null,["# Connect to a database cluster\n\nBy default, a database cluster only allows connection from within the\n[user cluster](/distributed-cloud/hosted/docs/latest/gdch/resources/resource-hierarchy#cluster) and the same project.\n\nTo enable connections to all database clusters in your project from another\nproject, see [Enable cross-project connections](/distributed-cloud/hosted/docs/latest/gdch/application/ao-user/db-cross-project-connect).\n\nTo enable connections to a database cluster from IP addresses outside your\nGDC organization, see [Enable external connections](/distributed-cloud/hosted/docs/latest/gdch/application/ao-user/db-external-project-connect).\n\nSign in to the GDC console with an account bound to the\n`project-db-admin` role to find the following information for connecting to your\ndatabase cluster. This information is in the **Connectivity** section of the\n**Database Service** page.\n\nThese steps include an example for connecting to the database using `psql`. The\nexact steps will vary depending on the client software you choose. \n\n### Console\n\n1. Navigate to the **Connectivity** section of the **Database Service** page\n for the database cluster. This page includes:\n\n - The password of the administrator account (the username is `dbsadmin`)\n - Hostname and port number of the database cluster's primary endpoint\n - If the database cluster allows external connection from outside of the organization.\n - A `psql` command for connecting to the cluster (for PostgreSQL and AlloyDB Omni database clusters)\n - A string for connecting to the cluster with Java Database Connectivity (JDBC) (for Oracle database clusters)\n - A link to download the certificate authority (CA) certificate of the database cluster\n2. Download the CA certificate from the GDC console in the\n **Connectivity** section of the **Database Service** page for your\n database cluster.\n\n3. Configure your client to use the CA certificate to verify the database. For\n `psql` clients, set the `PGSSLROOTCERT` env variable to the path of the\n certificate file and the `PGSSLMODE` env variable to your preference:\n\n export PGSSLROOTCERT=\u003cvar translate=\"no\"\u003epath/to/\u003c/var\u003eaccounts_cert.pem\n export PGSSLMODE=\"verify-full\"\n\n4. Connect to the database from your client software. If you're using `psql`,\n run the following command:\n\n PGPASSWORD=\u003cvar translate=\"no\"\u003eDB_PASSWORD\u003c/var\u003e psql -h \u003cvar translate=\"no\"\u003eDB_HOSTNAME\u003c/var\u003e -p \u003cvar translate=\"no\"\u003ePORT\u003c/var\u003e -U \u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e -d postgres\n\nReplace the following variables:\n\n- \u003cvar translate=\"no\"\u003epath/to/\u003c/var\u003e: the path to the `accounts_cert.pem` certificate.\n- \u003cvar translate=\"no\"\u003eDB_PASSWORD\u003c/var\u003e: the password from the console.\n- \u003cvar translate=\"no\"\u003eDB_HOSTNAME\u003c/var\u003e: the database hostname from the console.\n- \u003cvar translate=\"no\"\u003eDB_PORT\u003c/var\u003e: the database port number from the console.\n- \u003cvar translate=\"no\"\u003eDB_USERNAME\u003c/var\u003e: the database username from the console.\n\n### API\n\n1. Retrieve the database endpoint from the database cluster status:\n\n kubectl get dbcluster.\u003cvar translate=\"no\"\u003eDBENGINE_NAME\u003c/var\u003e.dbadmin.gdc.goog \u003cvar translate=\"no\"\u003eDBCLUSTER_NAME\u003c/var\u003e -n \u003cvar translate=\"no\"\u003eUSER_PROJECT\u003c/var\u003e -o=jsonpath='{.status.primary.url}'\n\n2. Download the CA certificate from the Kubernetes secret:\n\n kubectl get secret dbs-certificates -n \u003cvar translate=\"no\"\u003eUSER_PROJECT\u003c/var\u003e -o json | jq -r '.data.\"dbs-\u003cvar translate=\"no\"\u003eDBENGINE_SHORT_NAME\u003c/var\u003e-cert-\u003cvar translate=\"no\"\u003eDBCLUSTER_NAME\u003c/var\u003e\"' | base64 -d \u003e \u003cvar translate=\"no\"\u003epath/to/\u003c/var\u003eca.crt\n\n3. Configure your client to use the CA certificate to verify the database. For\n `psql` clients, you can set the `PGSSLROOTCERT` env variable to the path\n of the certificate file and the `PGSSLMODE` env variable to your preference:\n\n export PGSSLROOTCERT=\u003cvar translate=\"no\"\u003epath/to/\u003c/var\u003eaccounts_cert.pem\n export PGSSLMODE=\"verify-full\"\n\n4. Connect to the database from your client software. If you're using `psql`,\n run the following command:\n\n PGPASSWORD=\u003cvar translate=\"no\"\u003eDB_PASSWORD\u003c/var\u003e psql -h \u003cvar translate=\"no\"\u003eDB_HOSTNAME\u003c/var\u003e -p \u003cvar translate=\"no\"\u003eDB_PORT\u003c/var\u003e -U \u003cvar translate=\"no\"\u003eDB_USERNAME\u003c/var\u003e -d postgres\n\nReplace the following variables:\n\n- \u003cvar translate=\"no\"\u003eDBENGINE_NAME\u003c/var\u003e: the name of the database engine. This is one of `alloydbomni`, `postgresql`, or `oracle`.\n- \u003cvar translate=\"no\"\u003eUSER_PROJECT\u003c/var\u003e: the name of the user project where the database cluster was created.\n- \u003cvar translate=\"no\"\u003eDBENGINE_SHORT_NAME\u003c/var\u003e: the abbreviated name of the database engine. This is one of `al` (AlloyDB Omni), `pg` (PostgreSQL), or `ora` (Oracle).\n- \u003cvar translate=\"no\"\u003eDBCLUSTER_NAME\u003c/var\u003e: the name of the database cluster.\n- \u003cvar translate=\"no\"\u003epath/to/\u003c/var\u003e: the path to the database CA certificate.\n- \u003cvar translate=\"no\"\u003eDB_PASSWORD\u003c/var\u003e: database password for administrator user.\n- \u003cvar translate=\"no\"\u003eDB_HOSTNAME\u003c/var\u003e: the hostname from the database cluster status.\n- \u003cvar translate=\"no\"\u003eDB_PORT\u003c/var\u003e: the database port number from the database cluster status.\n- \u003cvar translate=\"no\"\u003eDB_USERNAME\u003c/var\u003e: with the database username (default is `dbsadmin`)."]]