Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Por padrão, um cluster de banco de dados só permite conexões de dentro do cluster de usuário e do mesmo projeto.
Para ativar conexões com todos os clusters de banco de dados no seu projeto de outro projeto, consulte Ativar conexões entre projetos.
Para ativar conexões com um cluster de banco de dados de endereços IP fora da sua organização do
GDC, consulte Ativar conexões externas.
Faça login no console do GDC com uma conta vinculada à função
project-db-admin para encontrar as seguintes informações de conexão com o cluster de banco de dados. Essas informações estão na seção Conectividade da página Serviço de banco de dados.
Essas etapas incluem um exemplo de conexão com o banco de dados usando psql. As etapas exatas variam de acordo com o software cliente escolhido.
Console
Acesse a seção Conectividade da página Serviço de banco de dados do cluster de banco de dados. Esta página inclui:
A senha da conta de administrador (o nome de usuário é dbsadmin)
Nome do host e número da porta do endpoint principal do cluster de banco de dados
Se o cluster de banco de dados permitir conexões externas de fora da organização.
Um comando psql para se conectar ao cluster (para clusters de banco de dados PostgreSQL e AlloyDB Omni)
Uma string para se conectar ao cluster com Java Database Connectivity (JDBC) (para clusters de banco de dados Oracle)
Um link para fazer o download do certificado da autoridade certificadora (CA) do cluster de banco de dados
Faça o download do certificado da CA no console do GDC na seção Conectividade da página Serviço de banco de dados do cluster de banco de dados.
Configure o cliente para usar o certificado da CA e verificar o banco de dados. Para clientes
psql, defina a variável de ambiente PGSSLROOTCERT como o caminho do
arquivo de certificado e a variável de ambiente PGSSLMODE como sua preferência:
Configure o cliente para usar o certificado da CA e verificar o banco de dados. Para clientes psql, defina a variável de ambiente PGSSLROOTCERT como o caminho do arquivo de certificado e a variável de ambiente PGSSLMODE como sua preferência:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 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`)."]]