tencent cloud

Feedback

PostgreSQL Component

Last updated: 2024-12-02 10:48:10

    Overview

    PostgreSQL for Serverless (ServerlessDB) is a database product that allocates resources on demand based on PostgreSQL. Its database automatically allocates resources based on your actual number of requests. With PostgreSQL for Serverless, you can create a database instance for easy use without caring about the instance specifications. You only need to pay for the actual usage when the database is active.
    Through the PostgreSQL for Serverless component, you can create, configure, and manage PostgreSQL instances with speed and ease.
    Features:
    Pay-as-you-go billing: fees are charged based on the request usage, and you don't need to pay anything if there is no request.
    Zero configuration: the default configuration will be done by Serverless.
    Fast deployment: you can create or update your database in just a few seconds.
    Convenient collaboration: the database status information and deployment logs in the cloud make multi-person collaborative development easier.

    Directions

    Installation

    Use npm to install Serverless CLI globally:
    $ npm install -g serverless

    Account configuration

    Create the .env file locally:
    $ touch .env # Tencent Cloud configuration information
    Configure Tencent Cloud's SecretId and SecretKey information in the .env file and save it:
    # .env
    TENCENT_SECRET_ID=123
    TENCENT_SECRET_KEY=123
    Note:
    If you don't have a Tencent Cloud account yet, please sign up first.
    If you already have a Tencent Cloud account, you can get SecretId and SecretKey in API Key Management.

    Configuration

    Create a directory and enter it:
    $ mkdir tencent-postgreSQL && cd tencent-postgreSQL
    Create a serverless.yml file in a new directory:
    $ touch serverless.yml
    Configure serverless.yml as follows:
    # serverless.yml
    component: postgresql # Name of the imported component, which is required. The `postgresql` component is used in this example
    name: serverlessDB # Name of the instance created by this component, which is required
    org: test # Organization information, which is optional. The default value is the `appid` of your Tencent Cloud account
    app: serverlessDB # SQL application name, which is optional
    stage: dev # Information for identifying environment, which is optional. The default value is `dev`
    
    inputs:
    region: ap-guangzhou # Valid values: ap-guangzhou, ap-shanghai, ap-beijing
    zone: ap-guangzhou-2 # Valid values: ap-guangzhou-2, ap-shanghai-2, ap-beijing-3
    dBInstanceName: serverlessDB
    vpcConfig:
    vpcId: vpc-xxxxxxx
    subnetId: subnet-xxxxxx
    extranetAccess: false
    The PostgreSQL component supports "zero" configuration deployment, that is, it can be deployed directly through the default values in the configuration file. Nonetheless, you can also modify more optional configuration items to further customize your project.
    Note:
    Currently, PostgreSQL for Serverless is available for creation and deployment only in Beijing Zone 3, Guangzhou Zone 2, and Shanghai Zone 2. Therefore, when entering the region and AZ information in the yaml file, please be sure to use the correct region and corresponding VPC and subnet information.

    Deployment

    Deploy by running the sls command, and you can add the --debug parameter to view the information during the deployment process:
    Note:
    sls is short for the serverless command.
    $ sls deploy

    Removal

    You can run the following commands to remove the deployed database instance:
    $ sls remove

    Best Practice

    After deploying the PostgreSQL Serverless database, you can refer to Deploying Full-Stack Website with Vue + Express + PostgreSQL to use this database instance.

    More Components

    You can view more component information in the repository of Serverless Components.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support