×
Community Blog Tips for SQL Database Optimization

Tips for SQL Database Optimization

In this article, you will get some tips on how to optimize your MySQL, PostgreSQL and SQL databases.

Best Practices for MySQL Database Storage Optimization

In this article, you will get some information on the storage and queries optimization for MySQL database.

First we need to understand the items that take up RDS storage. There are five storage types in the RDS console, namely total disk storage, data storage, log storage, temporary file storage, and system file storage. In the following sections, we will look at four of the five storage types that typically causes confusion to RDS users.

  1. Data files: Data files refer to the files stored in the storage. In the database, they are tables. The tables are mainly composed of data and indexes. Therefore, when you find that your data files are occupying a great deal of instance storage, you should further check which table is most responsible.
  2. Log Files: ApsaraDB for RDS MySQL uses a master/slave M-M high availability architecture. Mater/slave data synchronization relies on binlog. RDS will regularly back up the logs to OSS and then clear the local binlog to diminish the amount of space it takes up. When log storage encounters an error like the one in the figure below, the rate at which binlog grows may exceed the upload speed from RDS to OSS.
  3. Temporary Files: These are files written from memory to disk when the database performs large file operations, and memory proves insufficient. This may lead to the creation of substantial temporary files during significant database operations (order by, group by, distinct).
  4. System Files: This refers to the files created during the installation of the database. These system files are crucial to the normal operation. For MySQL, these files include ibdatal and ib_logfile0. The below graphic shows “other files” taking up a large amount of space. In this situation, you can refer to how to locate the problem causing ibdatal to grow continuously.

How to Optimize Data Queries for Time Series Database

PostgreSQL can optimize data queries in a good way, and here you can get some query optimization tips on how to optimize queries.

Data merging and data cleaning are required in many scenarios. We can use window query for this kind of operation, but how can we make it faster and quickly retrieve batch data?

Here is a quick summary of the common methods of optimizing time sequence data querying:

  1. Recursion is used when there are few unique values and an unknown range.
  2. Use subquery when the number of unique values is relatively small and you know the specific range of the unique values.
  3. Window query is more appropriate than the above method when there are many unique values.
  4. However, stream computing is even better in the same scenarios.

PostgreSQL is the best choice in open-source databases as it provides several solutions to the same problems. It leaves you free to choose the most appropriate solution for you and your individual needs.

How to Backup and Recover Your SQL Database

Data reliability is crucial for business, and here we will discuss how to backup and recover your data in SQL Server.

There are three database recovery models in SQL Server.

1. Simple Recovery Model: Database transaction logs are cleared along with the Checkpoint or Backup operation to minimize transaction logs.

All committed transactions are cleared upon completion of the Checkpoint or Backup operation, with only a few logs kept, necessary for recovery when an instance restarts. This model can minimize database transaction logs and storage usage, reduce storage overhead, and eliminate the need for special DBAs to maintain and back up database logs.

2. Full Recovery Model: The Full model in SQL Server is quite the opposite of the Simple recovery model. This section shows the following four aspects about the Full model: working principles, application scenarios, setting, and example scenarios.

In contrast to Simple, we can consider the Full model as "Checkpoint without truncate log," that is, the SQL Server database engine does not truncate transaction logs. Therefore, compared with databases using the Simple model, databases using the Full model have transaction log files that increase faster and are much larger. These database log files contain all recently committed transactions until a transaction log backup occurs and finishes successfully.

3. Bulk-Logged Recovery Model: As a mix of the Simple and Full recovery models, the Bulk-logged model adapts and improves the Bulk Imports operation under the Full model.

In a SQL Server database system, a method called Bulk Imports is available for quickly importing data, such as BCP, Bulk INSERT, and INSERT INTO... SELECT. If these Bulk operations are performed in a database under the Full model, massive amounts of log information are generated, significantly influencing SQL Server performance. The Bulk-logged model is designed to solve this problem. When a Bulk Imports operation is performed in a database running under the Bulk-logged model, very few logs are recorded to prevent the sharp increase in transaction logs and guarantee stable and efficient SQL Server performance. Simply, when no Bulk Imports operations are performed, the Bulk-logged model is equivalent to the Full model; when a Bulk Imports operation is performed, it is equivalent to the Simple model. Therefore, databases using the Bulk-logged model cannot implement point-in-time recovery. This is also a disadvantage in the Simple model.

Related Blog Posts

How to Manage MySQL Database with Commands

Alibaba Cloud offers highly-available on-demand MySQL, SQL Server and PostgreSQL databases as part of their ApsaraDB for RDS (Relational Database Service), you can manage your Alibaba MySQL databases from a Command Line Interface (CLI) on an Alibaba Cloud instance.

First make sure you have created a whitelist group for the IP address of the computer if you are connecting to ApsaraDB for RDS. Once you are connected to your MySQL database, you can execute SQL (Structured Query Language) commands to manage your MySQL instance including creating; users, databases, tables, columns/fields. You can also perform CRUD (Create Read Update and Delete) operations on any database table.

How to Enable Transparent Data Encryption on Alibaba Cloud

Transparent Data Encryption (TDE) is a technology used to encrypt databases by offering encryption at file level. If you have critical and sensitive data, TDE can help protect the privacy of your information and prevent data breaches by enabling data-at-rest encryption in the database. TDE helps you meet various regulatory requirements including PCI DSS and HIPAA.

Transparent Data Encryption (TDE) can be used to perform real-time I/O encryption and decryption on instance data files. To increase data security, you can enable TDE to encrypt instance data. Data is encrypted before it is written to disk and decrypted when it is read from disk.

Related Documentation

SQL optimization

In this documentation, you can get some useful tips for optimizing SQL database.

  1. Where condition in Join statement
  2. Data skew
  3. Window function optimization
  4. Convert the subquery to Join

Recover a database

DBS provides the database recovery feature that allows you to restore a database to a specified time accurate to seconds. You can also flexibly select recovery objects.

DBS supports recovering an entire database instance, single or multiple databases, and single or multiple tables.

Related Market Products

Windows Server 2016 with SQL Server 2016 Standard

Alibaba Cloud SQL Server image is a pre-configured, ready to run image for running SQL Server on Alibaba Cloud ECS.

Postgres Pro Standard Database 10 (Ubuntu 16)

Postgres Pro Standard Database provides early access to new PostgreSQL features and optimizations. This image contains Postgres Pro Standard Database 10. Zabbix/Mamonsu monitoring solution is installed and preconfigured. OS fixes for Meltdown and Spectre issues are applied. L1 Terminal Fault vulnerability is eliminated.

Related Products

Alibaba Cloud Databases

Alibaba Cloud offers fully managed database services. We monitor, backup, and recover your database automatically so that you can fully focus on your business development. To provide more stable and scalable database services, Alibaba Cloud optimized the source code based on the open-source database engines. Our database services, such as ApsaraDB RDS for MySQL and ApsaraDB RDS for PPAS have lower risk compare to the other services using the community edition.

ApsaraDB RDS for MySQL

MySQL is one of the most popular open-source databases in the world. As a key component of the open-source software bundle LAMP (Linux, Apache, MySQL, and Perl/PHP/Python), MySQL has been widely applied to different scenarios.

Related Course

Operate and Manage a Relational Database on the Cloud

Learn about the basic concepts of RDS, the benefits of using it (compared to conventional database solutions) and understand its key features. It also includes demos that further introduce database/account management, security settings, read-only instances, database backups and third-party tool integration.

0 0 0
Share on

Alibaba Clouder

2,022 posts | 474 followers

You may also like

Comments