postgresql数据库|数据库实操----表复制详解

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
简介: postgresql数据库|数据库实操----表复制详解

前言:

通常情况下,我们对数据库的增删改查的时候,为了确保数据的安全,需要备份表,那么,一种方法是通过pg_dump 这个工具做SQL转储操作,此方法比较复杂,麻烦,但十分的安全,可靠性也基本是百分百,但对于大表备份,十分耗时并且可能有锁表的情况发生,另一种常用方法是复制原表,当表数据不是很大的时候,此方式非常方便,快捷。

postgresql的表复制是和oracle或者MySQL有所不同的,但,差异不是太大。

本文将就表复制这一操作做一个详细的解读,计划使用常用的emp表来做示例。

一,

示例的emp表的建立

####注:此建表SQL语句适用于postgresql

-- 创建数据表
CREATE TABLE dept (
deptno    NUMERIC CONSTRAINT PK_DEPT PRIMARY KEY,
dname    VARCHAR(14) ,
loc        VARCHAR(13) 
) ;
CREATE TABLE emp (
empno    NUMERIC CONSTRAINT PK_EMP PRIMARY KEY,
ename    VARCHAR(10),
job        VARCHAR(9),
mgr        NUMERIC,
hiredate    DATE,
sal        NUMERIC(7,2),
comm    NUMERIC(7,2),
deptno    NUMERIC(2) CONSTRAINT FK_DEPTNO REFERENCES DEPT 
);
CREATE TABLE bonus (
enamE    VARCHAR(10)    ,
job        VARCHAR(9)  ,
sal        NUMERIC,
comm    NUMERIC 
) ;
CREATE TABLE salgrade ( 
grade        NUMERIC,
losal        NUMERIC,
hisal        NUMERIC 
);
-- 插入测试数据 —— dept
INSERT INTO dept VALUES    (10,'ACCOUNTING','NEW YORK');
INSERT INTO dept VALUES (20,'RESEARCH','DALLAS');
INSERT INTO dept VALUES    (30,'SALES','CHICAGO');
INSERT INTO dept VALUES    (40,'OPERATIONS','BOSTON');
-- 插入测试数据 —— emp
INSERT INTO emp VALUES (7369,'SMITH','CLERK',7902,to_date('17-12-1980','dd-mm-yyyy'),800,NULL,20);
INSERT INTO emp VALUES (7499,'ALLEN','SALESMAN',7698,to_date('20-2-1981','dd-mm-yyyy'),1600,300,30);
INSERT INTO emp VALUES (7521,'WARD','SALESMAN',7698,to_date('22-2-1981','dd-mm-yyyy'),1250,500,30);
INSERT INTO emp VALUES (7566,'JONES','MANAGER',7839,to_date('2-4-1981','dd-mm-yyyy'),2975,NULL,20);
INSERT INTO emp VALUES (7654,'MARTIN','SALESMAN',7698,to_date('28-9-1981','dd-mm-yyyy'),1250,1400,30);
INSERT INTO emp VALUES (7698,'BLAKE','MANAGER',7839,to_date('1-5-1981','dd-mm-yyyy'),2850,NULL,30);
INSERT INTO emp VALUES (7782,'CLARK','MANAGER',7839,to_date('9-6-1981','dd-mm-yyyy'),2450,NULL,10);
INSERT INTO emp VALUES (7788,'SCOTT','ANALYST',7566,to_date('13-07-87','dd-mm-yyyy')-85,3000,NULL,20);
INSERT INTO emp VALUES (7839,'KING','PRESIDENT',NULL,to_date('17-11-1981','dd-mm-yyyy'),5000,NULL,10);
INSERT INTO emp VALUES (7844,'TURNER','SALESMAN',7698,to_date('8-9-1981','dd-mm-yyyy'),1500,0,30);
INSERT INTO emp VALUES (7876,'ADAMS','CLERK',7788,to_date('13-07-87','dd-mm-yyyy')-51,1100,NULL,20);
INSERT INTO emp VALUES (7900,'JAMES','CLERK',7698,to_date('3-12-1981','dd-mm-yyyy'),950,NULL,30);
INSERT INTO emp VALUES (7902,'FORD','ANALYST',7566,to_date('3-12-1981','dd-mm-yyyy'),3000,NULL,20);
INSERT INTO emp VALUES (7934,'MILLER','CLERK',7782,to_date('23-1-1982','dd-mm-yyyy'),1300,NULL,10);
-- 插入测试数据 —— salgrade
INSERT INTO salgrade VALUES (1,700,1200);
INSERT INTO salgrade VALUES (2,1201,1400);
INSERT INTO salgrade VALUES (3,1401,2000);
INSERT INTO salgrade VALUES (4,2001,3000);
INSERT INTO salgrade VALUES (5,3001,9999);
-- 事务提交
COMMIT;

二,

示例表的介绍

观察emp表,关注此表都有哪些约束,外键,主键

emp表创建在test这个数据库内

test=# \c
You are now connected to database "test" as user "postgres".
test=# \dt
          List of relations
 Schema |   Name   | Type  |  Owner   
--------+----------+-------+----------
 public | bonus    | table | postgres
 public | dept     | table | postgres
 public | emp      | table | postgres
 public | salgrade | table | postgres
 public | tmp      | table | postgres
(5 rows)

有两个索引:

test=# \di
              List of relations
 Schema |  Name   | Type  |  Owner   | Table 
--------+---------+-------+----------+-------
 public | pk_dept | index | postgres | dept
 public | pk_emp  | index | postgres | emp

emp表有一个btree主键,一个关联dept(部门)的外键,empno字段有一个非空约束。

test=# \d emp
                        Table "public.emp"
  Column  |         Type          | Collation | Nullable | Default 
----------+-----------------------+-----------+----------+---------
 empno    | numeric               |           | not null | 
 ename    | character varying(10) |           |          | 
 job      | character varying(9)  |           |          | 
 mgr      | numeric               |           |          | 
 hiredate | date                  |           |          | 
 sal      | numeric(7,2)          |           |          | 
 comm     | numeric(7,2)          |           |          | 
 deptno   | numeric(2,0)          |           |          | 
Indexes:
    "pk_emp" PRIMARY KEY, btree (empno)
Foreign-key constraints:
    "fk_deptno" FOREIGN KEY (deptno) REFERENCES dept(deptno)

OK,emp的结构现在基本是清晰明了的了。

三,

复制表的六种方式

第一种

as select

全表复制----复制表结构和表数据,但不包括约束,主键,索引,外键

###此种方法会锁表,请谨慎操作大表

test=# create table emp1 as select * from emp;
SELECT 14

查看复制出来的emp1表各项数据:

test=# select * from emp1;
 empno | ename  |    job    | mgr  |  hiredate  |   sal   |  comm   | deptno 
-------+--------+-----------+------+------------+---------+---------+--------
  7369 | SMITH  | CLERK     | 7902 | 1980-12-17 |  800.00 |         |     20
  7499 | ALLEN  | SALESMAN  | 7698 | 1981-02-20 | 1600.00 |  300.00 |     30
  7521 | WARD   | SALESMAN  | 7698 | 1981-02-22 | 1250.00 |  500.00 |     30
  7566 | JONES  | MANAGER   | 7839 | 1981-04-02 | 2975.00 |         |     20
  7654 | MARTIN | SALESMAN  | 7698 | 1981-09-28 | 1250.00 | 1400.00 |     30
  7698 | BLAKE  | MANAGER   | 7839 | 1981-05-01 | 2850.00 |         |     30
  7782 | CLARK  | MANAGER   | 7839 | 1981-06-09 | 2450.00 |         |     10
  7788 | SCOTT  | ANALYST   | 7566 | 0087-04-19 | 3000.00 |         |     20
  7839 | KING   | PRESIDENT |      | 1981-11-17 | 5000.00 |         |     10
  7844 | TURNER | SALESMAN  | 7698 | 1981-09-08 | 1500.00 |    0.00 |     30
  7876 | ADAMS  | CLERK     | 7788 | 0087-05-23 | 1100.00 |         |     20
  7900 | JAMES  | CLERK     | 7698 | 1981-12-03 |  950.00 |         |     30
  7902 | FORD   | ANALYST   | 7566 | 1981-12-03 | 3000.00 |         |     20
  7934 | MILLER | CLERK     | 7782 | 1982-01-23 | 1300.00 |         |     10
(14 rows)

可以看到,emp1复制成功了emp的表结构和表数据,但索引,主键,外键,约束没有了

由此,我们可以得出结论,该表复制方法并不能做到百分百的复制,索引和主外键以及约束是不复制的,表数据和表结构都会完整复制。

究其原因,索引和主外键以及约束的名称是不可重复的,postgresql是没有办法复制的。

test=# \d emp1
                        Table "public.emp1"
  Column  |         Type          | Collation | Nullable | Default 
----------+-----------------------+-----------+----------+---------
 empno    | numeric               |           |          | 
 ename    | character varying(10) |           |          | 
 job      | character varying(9)  |           |          | 
 mgr      | numeric               |           |          | 
 hiredate | date                  |           |          | 
 sal      | numeric(7,2)          |           |          | 
 comm     | numeric(7,2)          |           |          | 
 deptno   | numeric(2,0)          |           |          | 
test=# alter table emp1 add constraint pk_emp primary key(empno);
ERROR:  relation "pk_emp" already exists

第二种表复制

as table

全表复制-----复制表结构和表数据,但不包括约束,主键,索引,外键

test=# create table emp2 as table emp;
SELECT 14

和as select基本没有区别,可以只复制表结构而不复制表数据---with no data:

test=# create table emp3 as  table emp with no data;
CREATE TABLE AS
test=# 
test=# \dt
          List of relations
 Schema |   Name   | Type  |  Owner   
--------+----------+-------+----------
 public | bonus    | table | postgres
 public | dept     | table | postgres
 public | emp      | table | postgres
 public | emp1     | table | postgres
 public | emp2     | table | postgres
 public | emp3     | table | postgres
 public | salgrade | table | postgres
 public | tmp      | table | postgres
(8 rows)
test=# select * from emp3;
 empno | ename | job | mgr | hiredate | sal | comm | deptno 
-------+-------+-----+-----+----------+-----+------+--------
(0 rows)

第三种表复制:

into复制

全表复制----复制表结构和表数据,但不包括约束,主键,索引,外键

###此种方法会锁表,请谨慎操作大表

test=# select * into emp4 from emp;
SELECT 14
test=# \d emp4
                        Table "public.emp4"
  Column  |         Type          | Collation | Nullable | Default 
----------+-----------------------+-----------+----------+---------
 empno    | numeric               |           |          | 
 ename    | character varying(10) |           |          | 
 job      | character varying(9)  |           |          | 
 mgr      | numeric               |           |          | 
 hiredate | date                  |           |          | 
 sal      | numeric(7,2)          |           |          | 
 comm     | numeric(7,2)          |           |          | 
 deptno   | numeric(2,0)          |           |          | 
test=# select * from emp4;
 empno | ename  |    job    | mgr  |  hiredate  |   sal   |  comm   | deptno 
-------+--------+-----------+------+------------+---------+---------+--------
  7369 | SMITH  | CLERK     | 7902 | 1980-12-17 |  800.00 |         |     20
  7499 | ALLEN  | SALESMAN  | 7698 | 1981-02-20 | 1600.00 |  300.00 |     30
  7521 | WARD   | SALESMAN  | 7698 | 1981-02-22 | 1250.00 |  500.00 |     30
  7566 | JONES  | MANAGER   | 7839 | 1981-04-02 | 2975.00 |         |     20
  7654 | MARTIN | SALESMAN  | 7698 | 1981-09-28 | 1250.00 | 1400.00 |     30
  7698 | BLAKE  | MANAGER   | 7839 | 1981-05-01 | 2850.00 |         |     30
  7782 | CLARK  | MANAGER   | 7839 | 1981-06-09 | 2450.00 |         |     10
  7788 | SCOTT  | ANALYST   | 7566 | 0087-04-19 | 3000.00 |         |     20
  7839 | KING   | PRESIDENT |      | 1981-11-17 | 5000.00 |         |     10
  7844 | TURNER | SALESMAN  | 7698 | 1981-09-08 | 1500.00 |    0.00 |     30
  7876 | ADAMS  | CLERK     | 7788 | 0087-05-23 | 1100.00 |         |     20
  7900 | JAMES  | CLERK     | 7698 | 1981-12-03 |  950.00 |         |     30
  7902 | FORD   | ANALYST   | 7566 | 1981-12-03 | 3000.00 |         |     20
  7934 | MILLER | CLERK     | 7782 | 1982-01-23 | 1300.00 |         |     10
(14 rows)

第四种表复制:

llike复制

----此方法非常重要,可以include 指定复制索引,主键,约束,但不包含外键,只复制表结构,不复制表数据

est=# create table emp5 (like emp);
CREATE TABLE
test=# \d emp5
                        Table "public.emp5"
  Column  |         Type          | Collation | Nullable | Default 
----------+-----------------------+-----------+----------+---------
 empno    | numeric               |           | not null | 
 ename    | character varying(10) |           |          | 
 job      | character varying(9)  |           |          | 
 mgr      | numeric               |           |          | 
 hiredate | date                  |           |          | 
 sal      | numeric(7,2)          |           |          | 
 comm     | numeric(7,2)          |           |          | 
 deptno   | numeric(2,0)          |           |          | 
test=# select * from emp5;
 empno | ename | job | mgr | hiredate | sal | comm | deptno 
-------+-------+-----+-----+----------+-----+------+--------
(0 rows)

如果希望索引、主键约束和唯一约束被复制的话,那么需要指定INCLUDING INDEXES

  • including constraints :CHECK约束
  • including indexes :主键约束 和索引约束
  • including comments:注释
  • including defaults:复制序列 (复制default now(),sequence这类)
test=# create table emp7 (like emp INCLUDING INDEXES INCLUDING DEFAULTS);
CREATE TABLE
test=# select * from emp7;
 empno | ename | job | mgr | hiredate | sal | comm | deptno 
-------+-------+-----+-----+----------+-----+------+--------
(0 rows)
test=# \d emp7
                        Table "public.emp7"
  Column  |         Type          | Collation | Nullable | Default 
----------+-----------------------+-----------+----------+---------
 empno    | numeric               |           | not null | 
 ename    | character varying(10) |           |          | 
 job      | character varying(9)  |           |          | 
 mgr      | numeric               |           |          | 
 hiredate | date                  |           |          | 
 sal      | numeric(7,2)          |           |          | 
 comm     | numeric(7,2)          |           |          | 
 deptno   | numeric(2,0)          |           |          | 
Indexes:
    "emp7_pkey" PRIMARY KEY, btree (empno)

第五种复制

继承复制

这种复制表的方法和其他方法有所区别,任何针对父表的修改通常也会自动修改子表,可以简单理解为单向映射,不可对子表更改,子表存在的时候不可以删除父表。

test=# create table emp6 (note text not null) inherits (emp); 
CREATE TABLE
test=# \d emp6
                        Table "public.emp6"
  Column  |         Type          | Collation | Nullable | Default 
----------+-----------------------+-----------+----------+---------
 empno    | numeric               |           | not null | 
 ename    | character varying(10) |           |          | 
 job      | character varying(9)  |           |          | 
 mgr      | numeric               |           |          | 
 hiredate | date                  |           |          | 
 sal      | numeric(7,2)          |           |          | 
 comm     | numeric(7,2)          |           |          | 
 deptno   | numeric(2,0)          |           |          | 
 note     | text                  |           | not null | 
Inherits: emp
test=# select * from emp6;
 empno | ename | job | mgr | hiredate | sal | comm | deptno | note 
-------+-------+-----+-----+----------+-----+------+--------+------
(0 rows)

此时对父表的更改将会作用到继承表:

test=# alter table emp add column city varchar;
ALTER TABLE
test=# \d emp6
                        Table "public.emp6"
  Column  |         Type          | Collation | Nullable | Default 
----------+-----------------------+-----------+----------+---------
 empno    | numeric               |           | not null | 
 ename    | character varying(10) |           |          | 
 job      | character varying(9)  |           |          | 
 mgr      | numeric               |           |          | 
 hiredate | date                  |           |          | 
 sal      | numeric(7,2)          |           |          | 
 comm     | numeric(7,2)          |           |          | 
 deptno   | numeric(2,0)          |           |          | 
 note     | text                  |           | not null | 
 city     | character varying     |           |          | 
Inherits: emp
test=# alter table emp6 drop column city;
ERROR:  cannot drop inherited column "city"
test=# drop table emp;
ERROR:  cannot drop table emp because other objects depend on it
DETAIL:  table emp6 depends on table emp
HINT:  Use DROP ... CASCADE to drop the dependent objects too.

第六种表复制:

insert 复制

----也就是填充表数据的方法,此方法需要复制目标存在,因此,可以利用第四种方法 ,  先  生成表结构,然后填充数据

以上面第四种方法创建的emp7表为例,填充emp表的数据到emp7表内:

test=# insert into emp7 select * from emp;
INSERT 0 14
test=# select * from emp7;
 empno | ename  |    job    | mgr  |  hiredate  |   sal   |  comm   | deptno 
-------+--------+-----------+------+------------+---------+---------+--------
  7369 | SMITH  | CLERK     | 7902 | 1980-12-17 |  800.00 |         |     20
  7499 | ALLEN  | SALESMAN  | 7698 | 1981-02-20 | 1600.00 |  300.00 |     30
  7521 | WARD   | SALESMAN  | 7698 | 1981-02-22 | 1250.00 |  500.00 |     30
  7654 | MARTIN | SALESMAN  | 7698 | 1981-09-28 | 1250.00 | 1400.00 |     30
  7698 | BLAKE  | MANAGER   | 7839 | 1981-05-01 | 2850.00 |         |     30
  7782 | CLARK  | MANAGER   | 7839 | 1981-06-09 | 2450.00 |         |     10
  7788 | SCOTT  | ANALYST   | 7566 | 0087-04-19 | 3000.00 |         |     20
  7839 | KING   | PRESIDENT |      | 1981-11-17 | 5000.00 |         |     10
  7844 | TURNER | SALESMAN  | 7698 | 1981-09-08 | 1500.00 |    0.00 |     30
  7876 | ADAMS  | CLERK     | 7788 | 0087-05-23 | 1100.00 |         |     20
  7900 | JAMES  | CLERK     | 7698 | 1981-12-03 |  950.00 |         |     30
  7902 | FORD   | ANALYST   | 7566 | 1981-12-03 | 3000.00 |         |     20
  7934 | MILLER | CLERK     | 7782 | 1982-01-23 | 1300.00 |         |     10
  7566 | JONES1 | MANAGER   | 7839 | 1981-04-02 | 2975.00 |         |     20
(14 rows)
test=# \d emp7
                        Table "public.emp7"
  Column  |         Type          | Collation | Nullable | Default 
----------+-----------------------+-----------+----------+---------
 empno    | numeric               |           | not null | 
 ename    | character varying(10) |           |          | 
 job      | character varying(9)  |           |          | 
 mgr      | numeric               |           |          | 
 hiredate | date                  |           |          | 
 sal      | numeric(7,2)          |           |          | 
 comm     | numeric(7,2)          |           |          | 
 deptno   | numeric(2,0)          |           |          | 
Indexes:
    "emp7_pkey" PRIMARY KEY, btree (empno)

可以看到,主键名称是表名,是btree类型的,约束存在的,只是缺少一个外键,因此,重新创建一个外键,就基本是%100复制了。

总结:

复制表推荐使用第四个方法和第六个方法结合,会省掉一点点麻烦,如果需要复制表强一致的话。

需要注意,表复制会导致锁表,因此,大表需要谨慎操作。

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
11天前
|
关系型数据库 分布式数据库 数据库
【PolarDB 开源】PolarDB 性能调优实录:提升数据库集群吞吐量的技巧
【5月更文挑战第22天】PolarDB 性能调优关键点包括硬件资源配置、数据库参数调整、索引优化、分区策略、事务优化及性能监控。创建高效索引如`CREATE INDEX idx_name ON table_name (column_name);`,根据业务场景选择分区方式,调整事务隔离级别以提升并发性能。监控 CPU、内存等指标,定期维护数据库,结合业务特点综合调优,从而提升数据库集群吞吐量。这些技巧有助于发挥PolarDB潜力,支持业务高效运行。
219 6
|
2天前
|
存储 关系型数据库 数据管理
探索PostgreSQL的高级数据库操作
【5月更文挑战第31天】探索PostgreSQL的高级特性,如分区表提升大数据查询性能,物化视图加速复杂查询,窗口函数计算累计值,全文搜索快速检索文本,及并行查询优化大规模数据处理。通过这些功能,PostgreSQL能更高效地管理与分析数据,应对复杂场景。
|
5天前
|
人工智能 关系型数据库 分布式数据库
【PolarDB 开源】PolarDB 与 AI 融合:智能数据库管理与预测性维护
【5月更文挑战第28天】PolarDB结合AI,开创数据库管理新纪元,实现智能优化、资源预测与分配、预测性维护。通过AI算法提升查询效率,动态调整资源,提前发现故障,增强安全。示例代码显示如何用AI预测查询时间。面对挑战,持续学习改进,未来二者融合将为数据库管理带来更多创新与竞争力。
82 0
|
5天前
|
存储 监控 关系型数据库
关系型数据库数据库设计优化
【5月更文挑战第18天】关系型数据库数据库设计优化
19 1
|
6天前
|
SQL 关系型数据库 分布式数据库
【PolarDB开源】PolarDB Proxy配置与优化:提升数据库访问效率
【5月更文挑战第27天】PolarDB Proxy是阿里云PolarDB的高性能数据库代理,负责SQL请求转发和负载均衡。其关键配置包括:连接池管理(如最大连接数、空闲超时时间),负载均衡策略(轮询、权重轮询、一致性哈希),以及SQL过滤规则。优化方面,关注监控与调优、缓存策略、网络优化。通过这些措施,可提升数据库访问效率和系统稳定性。
106 1
|
7天前
|
Cloud Native 关系型数据库 分布式数据库
【PolarDB开源】PolarDB与云原生数据库比较:特点、优势与选型建议
【5月更文挑战第26天】PolarDB是阿里云的云原生数据库,以其计算存储分离、一写多读架构和数据一致性保障脱颖而出。与Amazon Aurora和Google Cloud Spanner相比,PolarDB在中国市场更具优势,适合读多写少的场景和需要严格数据一致性的应用。企业在选型时应考虑业务需求、地域、读写比例和兼容性。PolarDB作为优秀解决方案,将在云原生数据库领域持续发挥关键作用。
120 1
|
9天前
|
Cloud Native 关系型数据库 分布式数据库
【PolarDB开源】PolarDB数据迁移实战:平滑过渡至云原生数据库
【5月更文挑战第24天】本文介绍了如何平滑迁移数据至阿里云的云原生数据库PolarDB,包括迁移准备、策略选择、步骤、验证及示例代码。通过需求分析、环境准备和数据评估,选择全量、增量或在线迁移策略。使用数据导出、导入及同步工具(如DTS)完成迁移,并在完成后验证数据一致性、性能和安全。正确执行可确保业务连续性和数据完整性。
111 1
|
9天前
|
关系型数据库 分布式数据库 数据库
【PolarDB开源】PolarDB安全策略:强化数据库防护的多维度措施
【5月更文挑战第24天】PolarDB,阿里云的高性能云原生数据库,提供全面的安全策略,包括SSL/TLS加密、VPC网络隔离、用户访问控制、数据加密和监控审计,构建多层防护体系。通过角色权限、列级加密和审计日志等措施,确保数据传输、访问和存储的安全。建议定期审计、更新系统、安全培训和备份策略,以增强数据库安全性。
116 2
|
9天前
|
关系型数据库 分布式数据库 数据库
【阿里云云原生专栏】云原生时代的数据库选型:阿里云RDS与PolarDB对比分析
【5月更文挑战第24天】阿里云提供RDS和PolarDB两种数据库服务。RDS是高性能的在线关系型数据库,支持MySQL等引擎,适合中小规模需求;而PolarDB是分布式数据库,具备高扩展性和性能,适用于大规模数据和高并发场景。RDS与PolarDB在架构、性能、弹性伸缩、成本等方面存在差异,开发者应根据具体需求选择。示例代码展示了如何通过CLI创建RDS和PolarDB实例。
467 0
|
10天前
|
监控 关系型数据库 分布式数据库
【PolarDB开源】PolarDB监控与报警系统构建:确保数据库健康运行
【5月更文挑战第23天】阿里云PolarDB因其存储计算分离、高兼容性等特性受企业青睐。为了确保其稳定运行,文章介绍了构建PolarDB监控与报警系统的做法。通过阿里云云监控服务开启和自定义监控视图,关注CPU、内存等关键指标,并设置告警规则。此外,通过自定义脚本与开源工具集成,满足特殊监控需求,实现全面、精准的监控报警,保障数据库健康运行。
36 2