百度智能云

All Product Document

          Relational Database Service

          Connect to an Instance

          Connection scenarios

          Connection scenarios supported by the RDS for PostgreSQL include:

          • BSS, access via Intranet
          • BAE (Professional), access via Intranet
          • BCH, access via the public network
          • User Local, access via the public network

          Connection presetting

          There are multiple ways to connect the RDS for PostgreSQL instance, such as accessing through database management tools or accessing through domain name address in the code. No matter which way to access the database you choose, the address, port number, account, and password information of the database are required. Herein, the address of the database is the domain name or IP address and port number of the RDS for PostgreSQL instance. You can click the instance name to enter the "Basic Information" page of the instance to view. Both the related account and password are required for database access connection. For account creation, please see Database Account Management.

          • Intranet connection: set whitelist and connection by Intranet domain name
          • Public network connection: set whitelist, enable the access to the public network, and connection by public network IP or domain name

          Notes:

          • Click "Get IP" to get the Intranet and Extranet IP addresses according to the domain name.
          • To ensure normal operation of the service, link the RDS for PostgreSQL by Extranet IP or domain name, link Intranet IP directly with the RDS for PostgreSQL. Master-backup switchover might result in data loss!
          • Access via database management tool is not supported for now.
          • After the creation of the RDS for PostgreSQL instance, all IPs are allowed by default, which facilitates the user's connection. To ensure data security, users shall reset the whitelist before access to the database.

          Enable public network access

          The user can access the RDS for PostgreSQL through the private network and public network. By default, the public network is not enabled for the database. If there is a need for public network access, the public network access needs to be enabled through the following operations.

          1. Enter the "RDS - Instance List" page.
          2. On the Basic Information page, click "Enable" behind the public network access to enable the access after system processing.

          image.png

          Direct access via code

          The user can directly access the database through the domain name or IP address in the code. If accessing through the public network, the public network access to the database needs to be enabled. Take the PHP code linking database as an example:

          $conn = pg_connect("host=localhost port=3306 dbname=myd user=postgres password=postgres");
          
          if($conn){
              print "has connected" . "<br>";
          }else{
              print "connect failure" . "<br>";
          }

          Notes:

          • PostgreSQL access port is 3306 by default.
          • The value of the servername is the domain name or IP address of the "Basic Information" page of the instance, and the values of username and password are the account and password created on the "Account Management" tab.
          Previous
          Data Migration
          Next
          Instance Management