Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Instance Usage Suggestions

Updated on 2024-10-14 GMT+08:00

Database Connection

RDS for PostgreSQL uses a process architecture, providing a backend service process for each client connection.

  • Set max_connections depending on the type of your application. Use the parameter settings provided on pgtune as examples:
    • Set max_connections to 200 for web applications.
    • Set max_connections to 300 for OLTP applications.
    • Set max_connections to 40 for data warehouses.
    • Set max_connections to 20 for desktop applications.
    • Set max_connections to 100 for hybrid applications.
  • Limit the maximum number of connections allowed for a single user based on workload requirements.
    ALTER ROLE xxx CONNECTION LIMIT xxx;
  • Set the number of active connections to two to three times the number of vCPUs.
  • Avoid long transactions, which may block autovacuum and affect database performance.
  • Periodically release persistent connections because maintaining them may generate a large cache and use up memory. You can configure parameters such as idle_session_timeout and idle_in_transaction_session_timeout to release idle connections.
  • Check the application framework to prevent the application from automatically starting transactions without performing any operations.

Read Replicas

  • Avoid long transactions, which may cause query conflicts and affect playback.
  • Configure hot_standby_feedback for instances requiring real-time data and set max_standby_streaming_delay to a proper value.
  • Monitor long transactions, long connections, and replication delay and address all issues in a timely manner.
  • Ensure that applications connected to a read replica can be switched to other nodes because read replicas are single-node instances incapable of providing high availability.

Reliability and Availability

  • Select primary/standby DB instances for production databases.
  • Keep vCPU, memory, and storage usage less than 85% for production databases to prevent problems such as out of memory (OOM) and full storage.
  • Deploy primary and standby instances in different AZs to improve availability.
  • Set the time window for automated backup to off-peak hours. Do not disable full backup.
  • Configure asynchronous replication between primary and standby DB instances to prevent workloads on the primary instance from being blocked due to a fault on the standby instance.
  • Pay attention to the size of temporary files and the generation rate. Too many temporary files affect database performance, slow down database startup, and even cause service unavailability.
  • Do not create too many objects in one instance. Generally, the number of tables in a single instance does not exceed 20,000, and that in a single database does not exceed 4,000. This prevents service unavailability caused by long-time table file scanning during database startup.

Logical Replication

  • Keep the name of a logical replication slot less than 40 bytes to prevent full backup failures.
  • Delete replication slots that are no longer used for logical replication to prevent database bloat.
  • Replication slots will be lost after a primary/standby switchover is performed (due to an instance class change, a minor version upgrade, or a host failure). When this occurs, you need to create replication slots again.
  • Use failover slots for RDS for PostgreSQL 12.6 and later minor versions, and all minor versions of RDS for PostgreSQL 13 and 14 to prevent replication slot loss after a primary/standby switchover or instance reboot.
  • When using logical replication, avoid long transactions and commit discarded two-phase transactions in a timely manner to prevent stacked WAL logs from occupying too much storage space.
  • When using logical replication, avoid using a large number of sub-transactions (such as savepoints and exception clauses in a transaction) to prevent high memory usage.
  • When using Data Replication Service (DRS) to synchronize or migrate data, delete the logical replication slots contained in the databases that are rarely accessed or add heartbeat tables to periodically push the replication slots to prevent stacked WAL logs.

Database Age

  • Definition of database age:
    • Database age is a PostgreSQL-specific concept. It refers to the latest transaction ID minus oldest transaction ID in the database.
    • As defined in the Multi-Version Concurrency Control (MVCC) mechanism of RDS for PostgreSQL, the maximum age allowed for a database is 2 billion transactions old. When a database reaches the maximum age, it will be forcibly shut down. In this case, contact technical support to vacuum the database.
    • To view the age of a database, run the following SQL statement:

      select datname, age(datfrozenxid) from pg_database;

  • You are advised to use the db_max_age metric to monitor the database age and set the alarm threshold to 1 billion.

Stability

  • Commit or roll back two-phase transactions in a timely manner to prevent database bloat.
  • Change the table structure, for example, adding fields or indexes, during off-peak hours.
  • To create indexes during peak hours, use the CONCURRENTLY syntax to avoid blocking the DML of the table.
  • Before modifying the structure of a table during peak hours, perform a verification test to prevent the table from being rewritten.
  • Configure a lock wait timeout duration for DDL operations to avoid blocking operations on related tables.
  • Partition your database if its capacity exceeds 2 TB.
  • If a frequently accessed table contains more than 20 million records or its size exceeds 10 GB, split the table or create partitions.
  • To prevent replication exceptions on the standby instance or read replicas, control the data write speed of the primary instance under 50 MB/s. That's because the standby instance or read replica replays WAL logs in a single process at a maximum speed of 50 MB/s to 70 MB/s.

Routine O&M

  • Periodically download and view slow query logs on the Logs page to identify and resolve performance issues in a timely manner.
  • Periodically check the resource usage of your instance. If the service pressure fluctuates greatly, you are advised to configure resource alarms and upgrade the instance specifications when necessary. High write pressure will slow down database reboots and affect service availability.
  • Run the SELECT statement before deleting or modifying a record.
  • After a large amount of data is deleted or updated in a table, run VACUUM on the table.
  • Note the number of available replication slots and ensure that at least one replication slot is available for database backup.
  • Remove any replication slots that are no longer used to prevent the replication slots from blocking log reclaiming.
  • Do not use unlogged tables because data in these tables will be lost after a database exception (such as OOM or underlying faults) or primary/standby switchover.
  • Do not run VACUUM FULL on system catalogs. If necessary, run VACUUM. Running VACUUM FULL on system catalogs causes the instance to reboot and the instance cannot be connected for a long time.

Security

  • Avoid enabling access to your database from the Internet. If you do need to enable Internet access, bind an EIP to your DB instance and configure a whitelist.
  • Use SSL to connect to your DB instance.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback