PostgreSQL与mysql字段对比
MySQL 和 PostgreSQL 对照表
初始化数据库
$prefix/bin/mysql_install_db --ldata=XXX --user=mysql
mkdir XXX; $prefix/bin/initdb [-D $prefix/wdb] -W XXX
启动|停止数据库服务器
$prefix/share/mysql/mysql.server start|stop
显示数据表
mysql$ show tables;
postgres=# \dt
显示表结构
mysql$ describe employee;
postgres=# \d employee
插入记录
mysql$ insert into employee values('1','zhang','F');
postgres=#insert into employee values('1','zhang','F');
pg_ctl -w -D XXX -l $prefix/wdb/xpg_log start|stop
进入命令行
# mysql
# psql postgres
添加用户
mysql$ grant all privileges on *.* to zhangsan@"%" identified by "123"
显示记录
mysql$ select * from employee;
postgres=#select * from employee;
删除记录
mysql$ delete from employee where employee_id='3';
postgresql与mysqlsql语句一样吗
postgresql与mysqlsql语句一样吗postgresql 与mysql sql语句一样吗PostgreSQL 的稳定性极强, Innodb 等引擎在崩溃、断电之类的灾难场景下抗打击能力有了长足进步,然而很多MySQL 使用者都遇到过Server级的资料库丢失的场景——mysql系统库是MyISAM的,相比之下,PG资料库这方面要好一些。
sql server与mysql语句一样么LabVIEW是一种程式开发环境,由美国国家仪器(NI)公司研制开发,类似于C和BASIC开发环境,但是LabVIEW与其他计算机语言的显著区别是:其他计算机语言都是采用基于文字的语言产生程式码,而LabVIEW使用的是图形化编辑语言G编写程式,产生的程式是框图的形式。
LabVIEW软体是NI设计平台的核心,也是开发测量或控制系统的理想选择。
LabVIEW开发环境集成了工程师和科学家快速构建各种应用所需的所有工具,旨在帮助工程师和科学家解决问题、提高生产力和不断创新。
hibernate的hql语句和sql语句一样吗?一样.都是资料库操作语句.只是有区别.sql语句貌似裸奔.hql整装.......sql可比作用dos操作的老版windows系统.hql.....windows xp SQL SERVER和ORACLE中SQL语句一样吗?Oracle与Sql server都遵循SQL-92标准:区别如下:1.Oracle中表名,栏位名,储存过程名,变数名不能超过30个字串长度。
2.Oracle中不支援T op 语法。
使用whererownum < n 代替。
但需要注意如果在Top前有排序的操作,则需要先排序在利用rownum 取得。
3.Oracle中游标的使用与SqlServer中有挺大差别,主要是在回圈控制方面不一致。
在Oracle中如果某列是Date型别,那么它预设的格式是yyyy-MM-dd,如果使用where colDate = ‘2005-06-08 17:14:57’就会出错,‘2005-06-08’可以。
MySQL和PostgreSQL两数据库的对决
MySQL和PostgreSQL两数据库的对决在这篇文章中,我们选用MySQL4.0.2-alpha与PostgreSQL7.2进行比较,因为MySQL4.0.2-alpha开始支持事务的概念,因此这样的比较对于MySQL应该较为有利。
我们这样的比较不想仅仅成为一份性能测试报告,因为至少从我个人来看,对于一个数据库,稳定性和速度并不能代表一切。
对于一个成熟的数据库,稳定性肯定会日益提供。
而随着硬件性能的飞速提高,速度也不再是什么太大的问题。
一、前言前一段时间,我曾经翻译过一篇将你的网站从MySQL改为PostgreSQL,其实当初我更感兴趣的是一个应用程序的后台数据库从MySQL转为PostgreSQL的具体操作,并没有关心MySQL和PostgreSQL的优劣,没想到反应出乎意料的大,因此我也就觉得有写这篇文章的必要了。
在这篇文章中,我们选用MySQL4.0.2-alpha与PostgreSQL7.2进行比较,因为MySQL4.0.2-alpha开始支持事务的概念,因此这样的比较对于MySQL应该较为有利。
我们这样的比较不想仅仅成为一份性能测试报告,因为至少从我个人来看,对于一个数据库,稳定性和速度并不能代表一切。
对于一个成熟的数据库,稳定性肯定会日益提供。
而随着硬件性能的飞速提高,速度也不再是什么太大的问题。
二、两者的共同优势这两个产品都属于开放源码的一员,性能和功能都在高速地提高和增强。
MySQLAB的人们和PostgreSQL的开发者们都在尽可能地把各自的数据库改得越来越好,所以对于任何商业数据库使用其中的任何一个都不能算是错误的选择。
三、两者不同的背景MySQL的背后是一个成熟的商业公司,而PostgreSQL的背后是一个庞大的志愿开发组。
这使得MySQL的开发过程更为慎重,而PostgreSQL的反应更为迅速。
这样的两种背景直接导致了各自固有的优点和缺点。
四、MySQL的主要优点1、首先是速度,MySQL通常要比PostgreSQL快得多。
数据库管理系统:PostgreSQL和MySQL的差异
数据库管理系统:PostgreSQL和MySQL的差异PostgreSQL和MySQL是两种常用的关系型数据库管理系统(RDBMS),它们在很多方面都有相似之处,比如都是开源的、可以在多个平台上运行、支持SQL等等。
但是,它们之间也有不同点,这篇文章将简要介绍这些不同点,以便读者可以更好地选择适合自己需求的数据库管理系统。
1.数据类型PostgreSQL和MySQL在数据类型方面有些区别,例如PostgreSQL 支持数组类型、范围类型和JSON类型,而MySQL不支持。
此外,PostgreSQL还支持网络地址和CIDR类型,以及各种几何数据类型,而MySQL则不支持这些类型。
这些不同可能对于需要使用这些数据类型的应用程序有影响。
2.存储引擎MySQL具有多种存储引擎,其中包括InnoDB、MyISAM等。
InnoDB 是MySQL的默认存储引擎,它支持事务和外键。
而MyISAM不支持事务和外键,但比较适合于只读的应用程序。
PostgreSQL则只有一个存储引擎,即MVCC。
MVCC是多版本并发控制的缩写,它是PostgreSQL实现隔离级别的方式。
它允许多个用户同时访问数据库,每个用户看到的数据都是根据他们所在的事务版本而定的。
这些版本是通过创建快照来实现的,这个快照包括所有已提交的数据。
MVCC的优点是可以确保并发访问的同时,还能提供高可靠性和数据完整性,但是,它的缺点是需要更多的存储空间来存储快照,因此可能导致性能下降。
3.复杂操作PostgreSQL在处理复杂操作和大型数据集时更为出色。
例如PostgreSQL支持CTE(公共表表达式)和窗口函数,这些函数可以让用户更轻松地进行复杂的分析操作。
此外,PostgreSQL还支持全文搜索,这使得用户可以更轻松地搜索包含关键字的文本。
MySQL则在处理事务时更为出色。
MySQL支持更严格的事务隔离级别,因此在多个用户执行写操作时,MySQL可以保证数据的一致性和完整性。
pg和mysql使用差异v0.1
pg和mysql使用差异v0.1-- 详细测试:1.主键自增长方式不同:pg使用sequence实现,可以方便获取当前sequence值.mysql使用 AUTO_INCREMENT来实现,不方便获取当前插入数据的主键id,mysql有LAST_INSERT_ID() 函数,但是此函数是依赖于会话的.需要慎重使用.pg:create table t_id(id serial primary key, name varchar(1024));会自动生成:LOG: statement: create table t_id(id serial primary key,name varchar(1024));NOTICE: CREATE TABLE will create implicit sequence "t_id_id_seq" for serial column "t_id.id"NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "t_id_pkey" for table "t_id"DEBUG: building index "t_id_pkey" on table "t_id"create table t_id(id serial primary key, name varchar(1024));insert into t_id(name) values('cross');insert into t_id(name) values('crossmo_'||currval('t_id_id_seq'::regclass)),('crossmo_'||cur rval('t_id_id_seq'::regclass));-- pg处理先查询 currval('t_id_id_seq'::regclass) ,再insert ,因此查询结果如下:demo=# select * from t_id;LOG: statement: select * from t_id;id | name----+-----------1 | cross2 | crossmo_13 | crossmo_2mysql:drop table t_id cascade ;create table t_id(id int primary key auto_increment, name varchar(1024));insert into t_id(name) values('crossmo01'),('crossmo02');INSERT into t_id(name) VALUES( CONCAT('crosoo',LAST_INSERT_ID()),( CONCAT('crosoo' ,LAST_INSERT_ID());INSERT into t_id(name) VALUES( CONCAT('crosoo',LAST_INSERT_ID());INSERT into t_id(name) VALUES( CONCAT('crosoo',"LAST_INSERT_ID()");create table t_id(id int primary key auto_increment, name varchar(1024)) CHARACTER SET=utf8 COLLATE=utf8_bin;drop table t_id cascade ;create table t_id(id int primary key auto_increment, name varchar(1024)) CHARACTER SET=utf8 COLLATE=utf8_bin;insert into t_id(name) values ('crossmo'),('cRossmo');select * from t_id where name like '%R%'; --返回结果只有1条数据.create table t_id1(id int primary key auto_increment,name varchar(30));INSERT into t_id1(name) VALUES( CONCAT('crosoo',LAST_INSERT_ID()));INSERT into t_id(name) VALUES( CONCAT('crosoo',LAST_INSERT_ID()));SELECT LAST_INSERT_ID();7select * from t_id1;1 crosoo6select * from t_id;1 jAck2 jack3 crosooLAST_INSERT_ID4 crosooLAST_INSERT_ID()5 crosooLAST_INSERT_ID()6 crosoo57 crosoo1由上面执行可以看出:这个session中,执行INSERT into t_id1(name) VALUES( CONCAT('crosoo',LAST_INSERT_ID())); 语句时,获取的不是t_id1的LAST_INSERT_ID(),而是t_id的last_insert_id().此时插入的数据是crosoo6而执行INSERT into t_id(name) VALUES( CONCAT('crosoo',LAST_INSERT_ID()));时,获取的是t_id1 的last_insert_id. 此时插入的数据是:crosoo1.因此需要谨慎使用.2.except 集合差运算.pg支持两个查询结果直接except求差,比如: select id from t_a except select id from t_b;则t_a和t_b都有的id将不返回.mysql 不支持except 运算.pg:create table t_set1(id int primary key,name varchar(30));create table t_set2(id int primary key,name varchar(30));insert into t_set1(id,name) values(1,'crossmo01'),(2,'crossmo02'),(3,'crossmo03'),(4,'crossmo 04');insert into t_set2(id,name) values (2,'crossmo02'),(3,'crossmo03'),(4,'crossmo04'),(5,'crossmo05');集合运算:unionselect id,name from t_set1unionselect id,name from t_set2 ;exceptselect id,name from t_set1exceptselect id,name from t_set2 ;mysql:create table t_set1(id int primary key,name varchar(30));create table t_set2(id int primary key,name varchar(30));insert into t_set1(id,name) values(1,'crossmo01'),(2,'crossmo02'),(3,'crossmo03'),(4,'crossmo 04');insert into t_set2(id,name) values (2,'crossmo02'),(3,'crossmo03'),(4,'crossmo04'),(5,'crossmo05');集合运算:unionselect id from t_set1unionselect id from t_set2 ;mysql 也支持 unionexceptselect id,name from t_set1exceptselect id,name from t_set2 ;报错:[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select id from t_set2' at line 33.boolean数据类型pg数据库存储的是t ,f.mysql内部存储的是int(1).pg:create table t_bool(id serial primary key, isok boolean default true);insert into t_bool(isok) values(true),(false); --okinsert into t_bool(isok) values(true),(false),(1),(0); -- 不能直接用1,0表示.insert into t_bool(isok) values(true),(false),(1::boolean),(0::boolean); --类型转换 ok insert into t_bool(isok) values ('t'),('f'); --ok查询:select * from t_bool where isok='t'; -- okselect * from t_bool where isok is true; -- okselect * from t_bool where isok=1; -- ok sql错误,无法执行.select * from t_bool where isok='1'; -- ok 获取正确的结果mysql:insert into t_bool(isok) values(true),(false); --okinsert into t_bool(isok) values(true),(false),(1),(0); -- 不能直接用1,0表示.insert into t_bool(isok) values(true),(false),(1::boolean),(0::boolean); --类型转换 ok insert into t_bool(isok) values ('t'),('f'); --ok,但是此时插入的数据是错误的.数据库插入的都是0,也就是false.查询:select * from t_bool where isok='t';--查询结果是所有false都查询出来了.也就是和select * from t_bool where isok='f'; 查询结果相同.select * from t_bool where isok=true; -- ok 获取正确的结果.select * from t_bool where isok is true; -- ok 获取正确的结果.select * from t_bool where isok=1; -- ok 获取正确的结果.select * from t_bool where isok='1'; -- ok 获取正确的结果4.with 语法pg支持,可以将一个复杂子查询通过with缓存,方便查询.mysql 不支持.with tmp as (select t_bool.id,name,isok from t_id ,t_bool where t_id.id=t_bool.id) select tmp.*,t_/doc/1b8150502.html, from tmp,t_id where tmp.id=t_id.id;with tmp as (select t_bool.id,name,isok from t_id ,t_bool where t_id.id=t_bool.id) select tmp.*,t_/doc/1b8150502.html, from tmp,t_set1 as t_id where tmp.id=t_id.id;id | name | isok | name----+-----------+------+-----------1 | cor | t | crossmo012 | crossmo_1 | f | crossmo023 | crossmo_2 | t | crossmo03mysql: 不支持此语法:5. 窗口函数pg支持,比如sum() over() 可以对查询结果分组求计数select id,isok, count(id) over(partition by isok) from t_boolorder by id;id | isok | count----+------+-------1 | t | 32 | f | 53 | t | 34 | f | 55 | t | 36 | f | 57 | f | 58 | f | 5-- ps: 如果和with结合起来,可以实现很复杂的查询.mysql不支持.6.rulepg支持CREATE OR REPLACE RULE r_t_demo_20120504 ASON INSERT TO t_demoWHERE new.logintime >= '2012-05-04 00:00:00'::timestamp without time zone AND new.logintime < '2012-05-07 00:00:00'::timestamp without time zone DO INSTEAD INSERT INTO t_demo_20120504 VALUES (new.*);mysql不支持7数据类型pg自身特有的 ip地址,mac地址,数组create table t_ip(id serial primary key ,c_cidr cidr, c_inet inet ,c_macaddr macaddr);insert into t_ip(c_cidr,c_inet,c_macaddr) values ('192.168.1.100','192.168.1.101','08:00:2b:01:02:03') ;-- 查询:id | c_cidr | c_inet | c_macaddr----+------------------+---------------+-------------------1 | 192.168.1.100/32 | 192.168.1.101 | 08:00:2b:01:02:03mysql不支持8时间戳:pg的时间戳可以精确到微妙,mysql到秒.同时mysql有datetime数据类型.而pg没有.create table t_timedate(id serial primary key, c_date date,c_time time,c_timestamp1 timestamp without time zone default now() ,c_timestamp2 timestamp without time zone default now());INSERT INTO t_timedate(c_date, c_time, c_timestamp1, c_timestamp2)VALUES ( now(), now(), now(), now());INSERT INTO t_timedate(c_date, c_time, c_timestamp1, c_timestamp2)VALUES ( current_date, current_time, current_timestamp without time zone,current_timestamp);create table t_datetime(id serial primary key,t_datetime datetime); -- sql错误,没有datetime 数据类型.mysql:create table t_timedate(id serial primary key, c_date date,c_time time,c_timestamp1 timestamp without time zone default now() ,c_timestamp2 timestamp without time zone default now());--[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'without time zone default now() ,c_timestamp2 timestamp without time zone defaul' at line 1-- mysql 没有create table t_datetime (id int primary key auto_increment,c_datetime1 TIMESTAMP default CURRENT_TIMESTAMP(),c_datetime2 TIMESTAMP default CURRENT_TIMESTAMP());- Incorrect table definition; there can be only one TIMESTAMP column withCURRENT_TIMESTAMP in DEFAULT or ON UPDATE clausecreate table t_datetime (id int primary key auto_increment,c_datetime1 TIMESTAMP ,c_datetime2TIMESTAMP default CURRENT_TIMESTAMP());Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clausecreate table t_datetime (id int primary key auto_increment,c_datetime1 TIMESTAMP default CURRENT_TIMESTAMP(),c_datetime2 TIMESTAMP);--创建成功.说明:mysql和pg对比,多了datetime数据类型.但是mysql对多时间戳支持的不好,只能在第一列是时间戳添加默认值,以后所有的都不只支持.9. 创建表时,对关键字的支持.pgcreate table t_key(id int primary key,key varchar(10));insert into t_key(id,key) values (1,'keyword');--mysqlcreate table t_key(id int primary key,key varchar(10));[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(10))' at line 1--正确方法:create table t_key(id int primary key,`key` varchar(10));--insert 和select update都会遇到相同的问题,需要加反引号才能执行.insert into t_key(id,key) values (1,'keyword');insert into t_key(id,`key`) values (1,'keyword');select id,`key` from t_key ;10. 单双引号:pg不支持用双引号包含字符insert into t_id(name) VALUES("demo"); --会报错mysql支持:insert into t_id(name) VALUES("demo"); --成功插入11.like查询pg: 支持like 和ilikecreate table t_like(id serial primary key, name varchar(20));insert into t_like(name) values ('crossmo'),('cRossmo');select * from t_like where name like '%R%';id | name----+---------2 | cRossmoselect * from t_like where name ilike '%R%';id | name----+---------1 | crossmo2 | cRossmomysql 只支持 like ,没有ilike语法.而且mysql的like是否区分字符大小写是根据collate,校验字符来区分的.如果采用二进制校验,则区分大小写,如果使用utf_ci区分则不区分大小写.create table t_like1(id serial primary key, name varchar(20)) CHARACTER SET=utf8 COLLATE=utf8_bin ;create table t_like2(id serial primary key, name varchar(20))CHARACTER SET=utf8 COLLATE=utf8_general_ci ;insert into t_like1(name) values ('crossmo'),('cRossmo');select * from t_like1 where name like '%R%';id | name----+---------2 | cRossmoinsert into t_like2(name) values ('crossmo'),('cRossmo');select * from t_like2 where name like '%R%';id | name----+---------1 | crossmo2 | cRossmo。
Mysql和Postgresql(PGSQL)对比
Mysql和Postgresql(PGSQL)对⽐PostgreSQL与MySQL⽐较使⽤太⼴泛了,以⾄于我不得不将⼀些应⽤从mysql 迁移到postgresql, 很多开源软件都是以Mysql 作为标准,并且以Mysql 作为抽象基础的,但是具体使⽤过程中,发现Mysql 有很多问题,所以都迁移到postgresql上了,转⼀个Mysql 和Postgresql 对⽐的⽂章:PostgreSQL由于是类似Oracle的多进程框架,所以能⽀持⾼并发的应⽤场景,这点与Oracle数据库很像,所以把Oracle DBA转到PostgreSQL数据库上是⽐较容易的,毕竟PostgreSQL数据库与Oracle数据库很相似。
同时,PostgreSQL数据库的源代码要⽐MySQL数据库的源代码更容易读懂,如果团队的C语⾔能⼒⽐较强的知,就能在PostgreSQL数据库上做开发,⽐⽅说实现类似greenplum的系统,这样也能与现在的分布式趋势接轨。
为了说明PostgreSQL的功能,我下⾯简要对⽐⼀下PostgreSQL数据库与MySQL数据库之间的差异:我们先借助Jametong翻译的"从Oracle迁移到Mysql之前必须知道的50件事",看⼀看如何把Oracle转到MySQL中的困难:50 things to know before migrating Oracle to MySQLby Baron Schwartz,Translated by Jametong1. 对⼦查询的优化表现不佳.2. 对复杂查询的处理较弱3. 查询优化器不够成熟4. 性能优化⼯具与度量信息不⾜5. 审计功能相对较弱6. 安全功能不成熟,甚⾄可以说很粗糙.没有⽤户组与⾓⾊的概念,没有回收权限的功能(仅仅可以授予权限).当⼀个⽤户从不同的主机/⽹络以同样地⽤户名/密码登录之后,可能被当作完全不同的⽤户来处理.没有类似于Oracle的内置的加密功能.7. ⾝份验证功能是完全内置的.不⽀持LDAP,Active Directory以及其它类似的外部⾝份验证功能.8. Mysql Cluster可能与你的想象有较⼤差异.9. 存储过程与触发器的功能有限.10. 垂直扩展性较弱.11. 不⽀持MPP(⼤规模并⾏处理).12. ⽀持SMP(对称多处理器),但是如果每个处理器超过4或8个核(core)时,Mysql的扩展性表现较差.13. 对于时间、⽇期、间隔等时间类型没有秒以下级别的存储类型.14. 可⽤来编写存储过程、触发器、计划事件以及存储函数的语⾔功能较弱.15. 没有基于回滚(roll-back)的恢复功能,只有前滚(roll-forward)的恢复功能.16. 不⽀持快照功能.17. 不⽀持数据库链(database link).有⼀种叫做Federated的存储引擎可以作为⼀个中转将查询语句传递到远程服务器的⼀个表上,不过,它功能很粗糙并且漏洞很多.18. 数据完整性检查⾮常薄弱,即使是基本的完整性约束,也往往不能执⾏。
基于PostgreSQL和mysql数据类型对比兼容
基于PostgreSQL和mysql数据类型对⽐兼容1、数值类型整数:mysql中的整数类型和pg相⽐,两者有以下区别:mysql:mysql中⽀持int 1,2,3,4,8 字节,同时⽀持有符号,⽆符号。
并且mysql中⽀持在数值列中指定zerofill,⽤来将存储的数值通过填充0的⽅式达到指定数据类型的长度(mysql8开始不建议使⽤ZEROFILL属性,并且在将来的MySQL版本中将不再⽀持该属性)。
pg:pg⽀持 int 2,4,8 字节,且数值都是有符号的。
mysql整数类型:pg整数类型:那么对于mysql中的1,3字节整型,或者⽆符号整型以及zerofill特性,在pg中该如何实现呢?在pg中我们可以使⽤domain来实现mysql中的1,3字节整数以及⽆符号整型。
创建uint8,8字节⽆符号整型bill=# create domain uint8 as numeric(20,0) check (value <= ((2^64::numeric)::numeric(20,0)-1) and value>=0::numeric(20,0));CREATE DOMAIN使⽤domain,插⼊整型数据,且⼤于等于0,⼩于2^64bill=# create table t5(c1 uint8);CREATE TABLEbill=# insert into t5 values (-1);ERROR: value for domain uint8 violates check constraint "uint8_check"bill=# insert into t5 values (0);INSERT 0 1bill=# insert into t5 values (18446744073709551615);INSERT 0 1bill=# insert into t5 values (18446744073709551616);ERROR: value for domain uint8 violates check constraint "uint8_check"bill=# select * from t5;c1----------------------18446744073709551615(2 rows)同样我们也可以来创建domain实现1,3字节有⽆符号整型,2,4,8字节⽆符号等等:create domain int1 as int2 CHECK (VALUE <= 127 AND VALUE >= (-128));create domain uint1 as int2 CHECK (VALUE <= 255 AND VALUE >= 0);create domain uint2 as int4 CHECK (VALUE <= 65535 AND VALUE >= 0);create domain int3 as int4 CHECK (VALUE <= 8388607 AND VALUE >= (-8388608));create domain uint3 as int4 CHECK (VALUE <= 16777215 AND VALUE >= 0);create domain uint4 as int8 CHECK (VALUE <= 4294967295 AND VALUE >= 0);create domain uint8 as numeric(20,0) check (value <= ((2^64::numeric)::numeric(20,0)-1) and value>=0::numeric(20,0));⽽对于mysql中的zerofill,我们可以使⽤lpad函数来实现,并且这也是mysql官⽅⽂档中推荐的⼀种⽅式。
PostgreSQL与MySQL对比(转载)
PostgreSQL与MySQL对⽐(转载)所有数据库对⽐可以参考:原⽂地址:⽐较版本:PostgreSQL 11 VS MySQL5.7(innodb引擎) Oracle官⽅社区版版权情况:PostgreSQL 11(免费开源)、MySQL5.7 Oracle官⽅社区版(免费开源)1. CPU限制PGSQL没有CPU核⼼数限制,有多少CPU核就⽤多少MySQL能⽤128核CPU,超过128核⽤不上2. 配置⽂件参数PGSQL⼀共有255个参数,⽤到的⼤概是80个,参数⽐较稳定,⽤上个⼤版本配置⽂件也可以启动当前⼤版本数据库MySQL⼀共有707个参数,⽤到的⼤概是180个,参数不断增加,就算⼩版本也会增加参数,⼤版本之间会有部分参数不兼容情况3. 第三⽅⼯具依赖情况PGSQL只有⾼可⽤集群需要依靠第三⽅中间件,例如:patroni+etcd、repmgrMySQL⼤部分操作都要依靠percona公司的第三⽅⼯具(percona-toolkit,XtraBackup),⼯具命令太多,学习成本⾼,⾼可⽤集群也需要第三⽅中间件,官⽅MGR集群还没成熟4. ⾼可⽤主从复制底层原理PGSQL物理流复制,属于物理复制,跟SQL Server镜像/AlwaysOn⼀样,严格⼀致,没有任何可能导致不⼀致,性能和可靠性上,物理复制完胜逻辑复制,维护简单MySQL主从复制,属于逻辑复制,(sql_log_bin、binlog_format等参数设置不正确都会导致主从不⼀致)⼤事务并⾏复制效率低,对于重要业务,需要依赖 percona-toolkit的pt-table-checksum和pt-table-sync⼯具定期⽐较和修复主从⼀致主从复制出错严重时候需要重搭主从MySQL的逻辑复制并不阻⽌两个不⼀致的数据库建⽴复制关系5. 从库只读状态PGSQL系统⾃动设置从库默认只读,不需要⼈⼯介⼊,维护简单MySQL从库需要⼿动设置参数super_read_only=on,让从库设置为只读,super_read_only参数有bug,链接:6. 版本分⽀PGSQL只有社区版,没有其他任何分⽀版本,PGSQL官⽅统⼀开发,统⼀维护,社区版有所有功能,不像SQL Server和MySQL有标准版、企业版、经典版、社区版、开发版、web版之分国内外还有⼀些基于PGSQL做⼆次开发的数据库⼚商,例如:Enterprise DB、瀚⾼数据库等等,当然这些只是⼆次开发并不算独⽴分⽀MySQL由于历史原因,分裂为三个分⽀版本,MariaDB分⽀、Percona分⽀、Oracle官⽅分⽀,发展到⽬前为⽌各个分⽀基本互相不兼容Oracle官⽅分⽀还有版本之分,分为标准版、企业版、经典版、社区版7. SQL特性⽀持PGSQLSQL特性⽀持情况⽀持94种,SQL语法⽀持最完善,例如:⽀持公⽤表表达式(WITH查询)MySQLSQL特性⽀持情况⽀持36种,SQL语法⽀持⽐较弱,例如:不⽀持公⽤表表达式(WITH查询)关于SQL特性⽀持情况的对⽐,可以参考:8. 主从复制安全性PGSQL同步流复制、强同步(remote apply)、⾼安全,不会丢数据PGSQL同步流复制:所有从库宕机,主库会罢⼯,主库⽆法⾃动切换为异步流复制(异步模式),需要通过增加从库数量来解决,⼀般⽣产环境⾄少有两个从库⼿动解决:在PG主库修改参数synchronous_standby_names ='',并执⾏命令: pgctl reload ,把主库切换为异步模式主从数据完全⼀致是⾼可⽤切换的第⼀前提,所以PGSQL选择主库罢⼯也是可以理解MySQL增强半同步复制,mysql5.7版本增强半同步才能保证主从复制时候不丢数据mysql5.7半同步复制相关参数:参数rpl_semi_sync_master_wait_for_slave_count 等待⾄少多少个从库接收到binlog,主库才提交事务,⼀般设置为1,性能最⾼参数rpl_semi_sync_master_timeout 等待多少毫秒,从库⽆回应⾃动切换为异步模式,⼀般设置为⽆限⼤,不让主库⾃动切换为异步模式所有从库宕机,主库会罢⼯,因为⽆法收到任何从库的应答包⼿动解决:在MySQL主库修改参数rpl_semi_sync_master_wait_for_slave_count=09. 多字段统计信息PGSQL⽀持多字段统计信息MySQL不⽀持多字段统计信息10. 索引类型PGSQL多种索引类型(btree , hash , gin , gist , sp-gist , brin , bloom , rum , zombodb , bitmap,部分索引,表达式索引)MySQLbtree 索引,全⽂索引(低效),表达式索引(需要建虚拟列),hash 索引只在内存表11. 物理表连接算法PGSQL⽀持 nested-loop join 、hash join 、merge joinMySQL只⽀持 nested-loop join12. ⼦查询和视图性能PGSQL⼦查询,视图优化,性能⽐较⾼MySQL视图谓词条件下推限制多,⼦查询上拉限制多13. 执⾏计划即时编译PGSQL⽀持 JIT 执⾏计划即时编译,使⽤LLVM编译器MySQL不⽀持执⾏计划即时编译14. 并⾏查询PGSQL并⾏查询(多种并⾏查询优化⽅法),并⾏查询⼀般多见于商业数据库,是重量级功能MySQL有限,只⽀持主键并⾏查询15. 物化视图PGSQL⽀持物化视图MySQL不⽀持物化视图16. 插件功能PGSQL⽀持插件功能,可以丰富PGSQL的功能,GIS地理插件,时序数据库插件,向量化执⾏插件等等MySQL不⽀持插件功能17. check约束PGSQL⽀持check约束MySQL不⽀持check约束,可以写check约束,但存储引擎会忽略它的作⽤,因此check约束并不起作⽤(mariadb ⽀持)18. gpu 加速SQLPGSQL可以使⽤gpu 加速SQL的执⾏速度MySQL不⽀持gpu 加速SQL 的执⾏速度19. 数据类型PGSQL数据类型丰富,如 ltree,hstore,数组类型,ip类型,text类型,有了text类型不再需要varchar,text类型字段最⼤存储1GBMySQL数据类型不够丰富20. 跨库查询PGSQL不⽀持跨库查询,这个跟Oracle 12C以前⼀样MySQL可以跨库查询21. 备份还原PGSQL备份还原⾮常简单,时点还原操作⽐SQL Server还要简单,完整备份+wal归档备份(增量)假如有⼀个三节点的PGSQL主从集群,可以随便在其中⼀个节点做完整备份和wal归档备份MySQL备份还原相对不太简单,完整备份+binlog备份(增量)完整备份需要percona的XtraBackup⼯具做物理备份,MySQL本⾝不⽀持物理备份时点还原操作步骤繁琐复杂22. 性能视图PGSQL需要安装pg_stat_statements插件,pg_stat_statements插件提供了丰富的性能视图:如:等待事件,系统统计信息等不好的地⽅是,安装插件需要重启数据库,并且需要收集性能信息的数据库需要执⾏⼀个命令:create extension pg_stat_statements命令否则不会收集任何性能信息,⽐较⿇烦MySQL⾃带PS库,默认很多功能没有打开,⽽且打开PS库的性能视图功能对性能有影响(如:内存占⽤导致OOM bug)23. 安装⽅式PGSQL有各个平台的包rpm包,deb包等等,相⽐MySQL缺少了⼆进制包,⼀般⽤源码编译安装,安装时间会长⼀些,执⾏命令多⼀些MySQL有各个平台的包rpm包,deb包等等,源码编译安装、⼆进制包安装,⼀般⽤⼆进制包安装,⽅便快捷24. DDL操作PGSQL加字段、可变长字段类型长度改⼤不会锁表,所有的DDL操作都不需要借助第三⽅⼯具,并且跟商业数据库⼀样,DDL操作可以回滚,保证事务⼀致性MySQL由于⼤部分DDL操作都会锁表,例如加字段、可变长字段类型长度改⼤,所以需要借助percona-toolkit⾥⾯的pt-online-schema-change⼯具去完成操作将影响减少到最低,特别是对⼤表进⾏DDL操作DDL操作不能回滚25. ⼤版本发布速度PGSQLPGSQL每年⼀个⼤版本发布,⼤版本发布的第⼆年就可以上⽣产环境,版本迭代速度很快PGSQL 9.6正式版推出时间:2016年PGSQL 10 正式版推出时间:2017年PGSQL 11 正式版推出时间:2018年PGSQL 12 正式版推出时间:2019年MySQLMySQL的⼤版本发布⼀般是2年~3年,⼀般⼤版本发布后的第⼆年才可以上⽣产环境,避免有坑,版本发布速度⽐较慢MySQL5.5正式版推出时间:2010年MySQL5.6正式版推出时间:2013年MySQL5.7正式版推出时间:2015年MySQL8.0正式版推出时间:2018年26. returning语法PGSQL⽀持returning语法,returning clause ⽀持 DML 返回 Resultset,减少⼀次 Client <-> DB Server 交互MySQL不⽀持returning语法27. 内部架构PGSQL多进程架构,并发连接数不能太多,跟Oracle⼀样,既然跟Oracle⼀样,那么很多优化⽅法也是相通的,例如:开启⼤页内存MySQL多线程架构,虽然多线程架构,但是官⽅有限制连接数,原因是系统的并发度是有限的,线程数太多,反⽽系统的处理能⼒下降,随着连接数上升,反⽽性能下降⼀般同时只能处理200 ~300个数据库连接28. 聚集索引PGSQL不⽀持聚集索引,PGSQL本⾝的MVCC的实现机制所导致MySQL⽀持聚集索引29. 空闲事务终结功能PGSQL通过设置 idle_in_transaction_session_timeout 参数来终⽌空闲事务,⽐如:应⽤代码中忘记关闭已开启的事务,PGSQL会⾃动查杀这种类型的会话事务MySQL不⽀持终⽌空闲事务功能30. 应付超⼤数据量PGSQL不能应付超⼤数据量,由于PGSQL本⾝的MVCC设计问题,需要垃圾回收,只能期待后⾯的⼤版本做优化MySQL不能应付超⼤数据量,MySQL⾃⾝架构的问题31. 分布式演进PGSQLHTAP数据库:cockroachDB、腾讯Tbase分⽚集群: Postgres-XC、Postgres-XLMySQLHTAP数据库:TiDB分⽚集群:各种各样的中间件,不⼀⼀列举32. 数据库的⽂件名和命名规律PGSQLPGSQL在这⽅⾯做的⽐较不好,DBA不能在操作系统层⾯(停库状态下)看清楚数据库的⽂件名和命名规律,⽂件的数量,⽂件的⼤⼩⼀旦操作系统发⽣⽂件丢失或硬盘损坏,⾮常不利于恢复,因为连名字都不知道PGSQL表数据物理⽂件的命名/存放规律是:在⼀个表空间下⾯,如果没有建表空间默认在默认表空间也就是base⽂件夹下,例如:/data/base/16454/3599base:默认表空间pg_default所在的物理⽂件夹16454:表所在数据库的oid3599:就是表对象的oid,当然,⼀个表的⼤⼩超出1GB之后会再⽣成多个物理⽂件,还有表的fsm⽂件和vm⽂件,所以⼀个⼤表实际会有多个物理⽂件由于PGSQL的数据⽂件布局内容太多,⼤家可以查阅相关资料当然这也不能全怪PGSQL,作为⼀个DBA,时刻做好数据库备份和容灾才是正道,做介质恢复⼀般是万不得已的情况下才会做MySQL数据库名就是⽂件夹名,数据库⽂件夹下就是表数据⽂件,每个表都有对应的frm⽂件和ibd⽂件,存储元数据和表/索引数据,清晰明了,做介质恢复或者表空间传输都很⽅便33. 权限设计PGSQLPGSQL在权限设计这块是⽐较坑爹,抛开实例权限和表空间权限,PGSQL的权限层次有点像SQL Server,db=》schema=》object要说权限,这⾥要说⼀下Oracle,⽤Oracle来类⽐在ORACLE 12C之前,实例与数据库是⼀对⼀,也就是说⼀个实例只能有⼀个数据库,不像MySQL和SQL Server⼀个实例可以有多个数据库,并且可以随意跨库查询⽽PGSQL不能跨库查询的原因也是这样,PGSQL允许建多个数据库,跟ORACLE类⽐就是有多个实例(之前说的实例与数据库是⼀对⼀)⼀个数据库相当于⼀个实例,因为PGSQL允许有多个实例,所以PGSQL单实例不叫⼀个实例,叫集簇(cluster),集簇这个概念可以查阅PGSQL的相关资料PGSQL⾥⾯⼀个实例/数据库下⾯的schema相当于数据库,所以这个schema的概念对应MySQL的database注意点:正因为是⼀个数据库相当于⼀个实例,PGSQL允许有多个实例/数据库,所以数据库之间是互相逻辑隔离的,导致的问题是,不能⼀次对⼀个PGSQL集簇下⾯的所有数据库做操作必须要逐个逐个数据库去操作,例如上⾯说到的安装pg_stat_statements插件,如果您需要在PGSQL集簇下⾯的所有数据库都做性能收集的话,需要逐个数据库去执⾏加载命令⼜例如跨库查询需要dblink插件或fdw插件,两个数据库之间做查询相当于两个实例之间做查询,已经跨越了实例了,所以需要dblink插件或fdw插件,所以道理⾮常简单权限操作也是⼀样逐个数据库去操作,还有⼀个就是PGSQL虽然像SQL Server的权限层次结构db=》schema=》object,但是实际会⽐SQL Server要复杂⼀些,还有就是新建的表还要另外授权在PGSQL⾥⾯,⾓⾊和⽤户是⼀样的,对新⼿⽤户来说有时候会傻傻分不清,也不知道怎么去⽤⾓⾊,所以PGSQL在权限设计这⼀块确实⽐较坑爹MySQL使⽤mysql库下⾯的5个权限表去做权限映射,简单清晰,唯⼀问题是缺少权限⾓⾊user表db表host表tables_priv表columns_priv表34. 发展历史PGSQL在1995年,开发⼈员Andrew Yu和Jolly Chen在Postgres中添加了⼀个SQL(Structured Query Language,结构化查询语⾔)翻译程序,该版本叫做Postgres95,在开放源代码社区发放。
MySQL与PostgreSQL相比哪个更好?
MySQL与PostgreSQL相⽐哪个更好?⽹上已经有很多拿PostgreSQL与MySQL⽐较的⽂章了,这篇⽂章只是对⼀些重要的信息进⾏下梳理。
在开始分析前,先来看下这两张图:MySQLMySQL声称⾃⼰是最流⾏的开源数据库。
LAMP中的M指的就是MySQL。
构建在LAMP上的应⽤都会使⽤MySQL,如WordPress、Drupal等⼤多数php开源程序。
MySQL最初是由MySQL AB开发的,然后在2008年以10亿美⾦的价格卖给了Sun公司,Sun公司⼜在2010年被Oracle 收购。
Oracle⽀持MySQL的多个版本:Standard、Enterprise、Classic、Cluster、Embedded与Community。
其中有⼀些是免费下载的,另外⼀些则是收费的。
其核⼼代码基于GPL许可,由于MySQL被控制在Oracle,社区担⼼会对MySQL的开源会有影响,所以开发了⼀些分⽀,⽐如: MariaDB和Percona。
PostgreSQLPostgreSQL标榜⾃⼰是世界上最先进的开源数据库。
PostgreSQL的⼀些粉丝说它能与Oracle相媲美,⽽且没有那么昂贵的价格和傲慢的客服。
最初是1985年在加利福尼亚⼤学伯克利分校开发的,作为Ingres数据库的后继。
PostgreSQL是完全由社区驱动的开源项⽬。
它提供了单个完整功能的版本,⽽不像MySQL那样提供了多个不同的社区版、商业版与企业版。
PostgreSQL基于⾃由的BSD/MIT许可,组织可以使⽤、复制、修改和重新分发代码,只需要提供⼀个版权声明即可。
MySQL与PostgreSQL的对⽐MySQL的背后是⼀个成熟的商业公司,⽽PostgreSQL的背后是⼀个庞⼤的志愿开发组。
这使得MySQL的开发过程更为慎重,⽽PostgreSQL的反应更为迅速。
这样的两种背景直接导致了各⾃固有的优点和缺点。
PostgreSQL相对于MySQL的优势1)不仅仅是关系型数据库除了存储正常的数据类型外,还⽀持存储:array,不管是⼀位数组还是多为数组均⽀持json(hStore)和jsonb,相⽐使⽤text存储接送要⾼效很多json和jsonb之间的区别jsonb和json在更⾼的层⾯上看起来⼏乎是⼀样的,但在存储实现上是不同的。
mysql和postgresql性能对比测试
SQL OperationMySQL 5.0.51MySQL 5.1.30with InnoDB 1.0.3PostgreSQLsecondssecondssecondssel_1_cl()00.020.04join_3_cl()0.060.050.02sel_100_ncl()0.010.010.03table_scan()10.54 4.130.64oin_2()1.78 1.620.89sel_variable_select_low()0.030.020sel_variable_select_high()12.527.8249.51oin_4_cl()000proj_100()7.137.35149.97join_4_ncl()0.0300proj_10pct()9.132.6820.06table_scan()select * from uniques where col_int = 1sel_1_cl()select col_key, col_int, col_signed, col_code, col_double, col_name from updates where col_key = 1000sel_1_ncl()select col_key, col_int, col_signed, col_code, col_double, col_name from updates where col_code = ‘BENCHMARKS’sel_100_cl()select col_key, col_int, col_signed, col_code, col_double, col_name from updates where col_key <= 100sel_100_ncl()select col_key, col_int, col_signed, col_code, col_double, col_name from updates where col_int <= 100sel_variable_select_high()select col_key, col_int, col_signed, col_code, col_double, col_name from tenpct where col_signed <:prog_var;sel_variable_select_low()select col_key, col_int, col_signed, col_code, col_double, col_name from tenpct where col_signed <:prog_var;join_4_cl()select uniques.col_date, hundred.col_date, tenpct.col_date, updates.col_date from uniques, hundred, tenpct, updates whereuniques.col_key = hundred.col_key and uniques.col_key = tenpct.col_key and uniques.col_key = updates.col_key andmysql 和postgresql 性能对⽐测试今天突然想知道mysql 和postgresql 的性能哪个好些搜索看了⼀些⽂章,然后看到⼀篇专业的测试⽂章对⽐测试的环境如下电脑配置Hardware ResourcesCPU: Intel(R) Pentium(R) D CPU 3.00GHz Dual Core RAM: 3G RamHDD: WDC WD3200AAJS-0测试安装的软件Software ResourcesDebian Lenny 5.0 64 bit archLinux painkiller 2.6.26-2-amd64 #1 SMP Wed May 13 15:37:46 UTC 2009 x86_64 GNU/Linux MySQL 5.0.51a-24+lenny1MySQL 5.1.30 Sun compiledInnoDB 1.0.3 Plugin compiled by ORACLE for MySQL 5.1.30PostgreSQL 8.3.72.1 – Opensource Database benchmark.使⽤osdb ⽣成了1024m 的数据来测试The test was made on a 1024MB of data and the multiple users test was made with 100 users simultaneously on the same database.截取⼀部分测试结果⼤家看uniques.col_key = 1000join_4_ncl()select uniques.col_date, hundred.col_date, tenpct.col_date, updates.col_date from uniques, hundred, tenpct, updates whereuniques.col_code = hundred.col_code and uniques.col_code = tenpct.col_code and uniques.col_code = updates.col_code anduniques.col_code = ‘BENCHMARKS’sel_variable_select_high()select col_key, col_int, col_signed, col_code, col_double, col_name from tenpct where col_signed < :prog_var;sel_variable_select_low()select col_key, col_int, col_signed, col_code, col_double, col_name from tenpct where col_signed < :prog_var;sel_1_cl()select col_key, col_int, col_signed, col_code, col_double, col_name from updates where col_key = 1000table_scan()select * from uniques where col_int = 1---------------------------------------------------------------------------------------------------------------------------------------------------------- 在⼀些常规的根据表的键查询MySQL 5.1.30 with InnoDB 1.0.3居然还快过postgresql但是表扫描就要慢了可见mysql 也不是被postgresql ⽐的⼀⽆是处⼤家可以再研究下对⽐结果。
PostgreSQL与MySQL对比
特性MySQL PostgreSQL实例通过执行MySQL 命令(mysqld)启动实例。
一个实例可以管理一个或多个数据库。
一台服务器可以运行多个mysqld实例。
一个实例管理器可以监视mysqld的各个实例。
通过执行Postmaster 进程(pg_ctl)启动实例。
一个实例可以管理一个或多个数据库,这些数据库组成一个集群。
集群是磁盘上的一个区域,这个区域在安装时初始化并由一个目录组成,所有数据都存储在这个目录中。
使用initdb创建第一个数据库。
一台机器上可以启动多个实例。
数据库数据库是命名的对象集合,是与实例中的其他数据库分离的实体。
一个MySQL 实例中的所有数据库共享同一个系统编目。
数据库是命名的对象集合,每个数据库是与其他数据库分离的实体。
每个数据库有自己的系统编目,但是所有数据库共享pg_databases。
数据缓冲区通过innodb_buffer_pool_size配置参数设置数据缓冲区。
这个参数是内存缓冲区的字节数,InnoDB使用这个缓冲区来缓存表的数据和索引。
在专用的数据库服务器上,这个参数最高可以设置为机器物理内存量的80%。
Shared_buffers缓存。
在默认情况下分配64 个缓冲区。
默认的块大小是8K。
可以通过设置postgresql.conf文件中的shared_buffers参数来更新缓冲区缓存。
数据库连接客户机使用CONNECT 或USE 语句连接数据库,这时要指定数据库名,还可以指定用户id 和密码。
使用角色管理数据库中的用户和用户组。
客户机使用connect 语句连接数据库,这时要指定数据库名,还可以指定用户id 和密码。
使用角色管理数据库中的用户和用户组。
身份验证MySQL 在数据库级管理身份验证。
基本只支持密码认证。
PostgreSQL支持丰富的认证方法:信任认证、口令认证、Kerberos 认证、基于Ident的认证、LDAP 认证、PAM 认证加密可以在表级指定密码来对数据进行加密。
Oracle、MySQL和PostgreSQL的功能比较
复杂SQL(优化引擎)SQL是你与你的数据库交互的基础和最关键的方法,无论你选择哪个。
这三个平台也恰恰是从它开始真正分离。
Oracle支持非常复杂的查询、几乎不限制表的个数、所有的类型的连接和合并。
虽然Oracle有很多功能,但是它真正宝贵的却是它基于成本的优化器,它可以分析SQL、如果可能的话进行重写和简化、基于成本选择索引、决定对表的操作和它之中的所有其它的各种功能。
阅读MySQL的文档,你会发现对偏向于性能的描述和供应商定义的细节使优化器和性能调整在任何平台上都很复杂。
MySQL规定的最大规模是在任何连接或在一个视图中表的最大数目为61个。
再一次的,我个人觉得无论如何在任何一个应用中这么多表的一个查询将是难以使用的,所以正如上面提到的,目前更适用的是优化器而不是查询最大表规格,等等。
8.x版本的Postgresql支持所有SQL92规范,几乎没有任何限制。
再一次的,我认为你会看到的一个数据库优于其它的数据库的方面就是在优化方面。
复杂的查询会变得凌乱,并且查询计划是你在诊断性能瓶颈时的最好的朋友。
索引类型索引技术对于数据库性能是至关重要的,而Oracle有大量的选项可供选择。
有非常多的不同的索引类型,包括标准的二进制树、转换键的、基于功能的、常被错误使用的位图索引,甚至还有索引表。
随着附加项技术的发展,数据库管理员有了可用的提供索引的Oracle文本,它允许你搜索CLOB(字符大对象),并且Oracle Spatial 提供用于基于位置的数据的索引。
在MySQL中,我们发现有二进制树、哈希、纯文本和GIS索引(对于基于位置的数据)。
还有集群索引,但是如果说我在Oracle方面的经验给我任何指导的话,那么就是大多数应用通常是不相关的。
因此,大多数情况下我在Oracle、MySQL或Postgres应用中看到的只有二进制树索引。
另外,尽管像在MySQL中基于功能的索引是不可用的,但是他们可以通过创建另一个保存使用这个函数的数据的列来进行模拟,然后添加一个触发器来将安装它。
PostgreSQL与mysql字段对比
存储日期和时间。可以存储或不存储数据库服务器的时区,使用8字节存储空间。
VARCHAR(n)
CHARACTER VARYING(n)
CHARACTER VARYING
存储可变长度的字符串,最大长度为n。不存储末尾的空格。
TEXT
存储长度可变的大型字符串数据,最多1 GB。PostgreSQL自动压缩TEXT字符串。
TIME (WITHOUT TIME ZO间。如果不存储数据库服务器的时区,就使用8字节的存储空间;如果存储时区,就使用12字节。
TIMESTAMP (WITHOUT TIME ZONE |
LONGTEXT
用于存储最多4GB的字符串数据。
TIME
用3字节的存储空间存储天内的时间。
TIMESTAMP
用4字节的存储空间存储日期和时间。如果没有提供有效值的话,TIMESTAMP列会自动设置为最近操作的日期和时间。
VARCHAR(n)
CHARACTER VARYING(n)
CHARACTER VARYING
用于存储二进制对象(比如图形)的原始二进制数据,最大255字节。
BLOB
用于存储二进制对象(比如图形)的原始二进制数据,最大65,535字节。
MEDIUMBLOB
用于存储二进制对象(比如图形)的原始二进制数据,最大16,777,215字节。
LONGBLOB
用于存储二进制对象(比如图形)的原始二进制数据,最大4GB。
FLOAT
存储浮点数,限制由硬件决定。单精度浮点数精确到大约7位小数。UNSIGNED属性不允许负数。
DOUBLE
REAL
存储双精度浮点数,限制由硬件决定。双精度浮点数精确到大约15位小数。UNSIGNED属性不允许负数。
postgresql mysql的写法
postgresql mysql的写法摘要:1.PostgreSQL 和MySQL 的概述2.PostgreSQL 和MySQL 的写法比较3.选择PostgreSQL 或MySQL 的建议正文:1.PostgreSQL 和MySQL 的概述PostgreSQL 和MySQL 都是流行的关系型数据库管理系统,被广泛应用于各种场景。
PostgreSQL(简称Postgre)是一款功能强大的开源数据库,它支持复杂的数据类型、存储过程、视图和触发器等,适用于大型企业级应用。
MySQL 同样是一款开源数据库,它具有高性能、易使用等特点,适合于网络应用和数据仓库等场景。
2.PostgreSQL 和MySQL 的写法比较(1)数据类型PostgreSQL 和MySQL 支持许多相同的基本数据类型,如整数、浮点数、日期和字符串等。
但PostgreSQL 支持更多的数据类型,如数组、范围类型和网络地址等。
(2)查询语言两者都支持SQL(结构化查询语言),但PostgreSQL 的SQL 支持更为完整,实现了ANSI SQL 的绝大部分功能。
MySQL 的SQL 语法略有不同,部分功能使用存储过程或触发器实现。
(3)存储过程和触发器PostgreSQL 支持存储过程和触发器,可以实现复杂的业务逻辑。
MySQL 同样支持存储过程和触发器,但存储过程的编写语法略有不同。
(4)视图PostgreSQL 和MySQL 都支持视图,可以定义自定义的查询结果集。
但PostgreSQL 支持视图的范围限制和自定义数据类型等高级功能。
3.选择PostgreSQL 或MySQL 的建议在选择PostgreSQL 或MySQL 时,可以根据以下几个方面进行考虑:(1)项目需求:根据项目的具体需求,如数据类型、查询复杂度等,选择适合的数据库。
(2)性能:如果对性能要求较高,可以选择MySQL,因为它具有较高的性能和稳定性。
(3)安全性:如果对数据安全要求较高,可以选择PostgreSQL,因为它支持更多的安全功能,如可扩展的访问控制、行级安全等。
PostgreSQL与MySQL对比
PostgreSQL与MySQL对⽐
使⽤了⼀段时间的postgresql与mysql,说⼀下⽬前的感受
MySQL优点
1.mysql的资料更多。
因为使⽤的⼈多,⼤部分问题⽹上都有答案。
并且很多⼤⼚使⽤的是mysql,可以流出⼀些⾼质量的实战经验。
2.mysql的binlog解析出来更清晰,可以知道每⼀条执⾏语句。
3.mysql提供了⼀些不完全符合标准但更符合普通⼈思维的易⽤⽅法。
4.mysql的主从配置更简单
5.mysql可以调节字段的顺序
MySQL缺点
1.json功能弱
2.oracle掌管授权
3.被linux排除,代替为mariadb。
PostgreSQL优点
1.postgresql的官⽅⽂档更详细清晰。
2.强⼤的json功能
3.更丰富的扩展和可配置性
PostgreSQL缺点
1.资料相对较少,上⼿⽐mysql难
2.增加了sequence,创建⾃增id多了⼀步
3.增加了模式概念,增加了⼊门的疑惑
4.wal⽇志(类似于mysql的binlog)中⽆法解析出每次执⾏的sql语句,不能直观的知道应该恢复到什么位置。
5.主从配置繁琐,主windows,从linux配置失败
6.postgresql为了性能以及实现的限制,不可以调节字段间前后的顺序
7.postgresql表中排序,默认使⽤更新的时间,⽽不是按照主键
结论
虽然PostgresSQL的json功能更强⼤,有⼀些功能更好⽤,但是由于其备份⽅⾯太⿇烦,不⽅便,与MySQL⽐也是各有千秋,所以放弃继续使⽤。
PostgreSQL VS MySQL&Oracle
记录少量回滚信息,redo日志就记录操作信息;对于PostgreSQL只需要在数据 文件和WAL日志中记录操作。 对于delete操作,oracle和innodb,需要在数据文件删除数据,在回滚段
中记录旧数据,redo日志就记录操作信息;对于PostgreSQL只需要更新数据文 件和在WAL日志中记录操作。 对于update操作,PostgreSQL需要新生成一行,会导致原表膨胀,而对于
事务,会带来很多严重的问题。同时回滚的过程也会再次产生大量的redo日志。 4. WAL日志要比oracle和Innodb简单,对于oracle不仅需要记录数据文
件的变化,还要记录回滚段的变化。
PostgreSQL多版本实现
PostgreSQL的主要劣势在于:
最新版本和历史版本不分离存储,导致清理老旧版本需要作更多的扫描,代 价比较大,但这个问题一般并不是突出,因为VACUUM中也有很多的优化。如 PostgreSQL 8.3中加入了HOT技术。使用HOT后,若所有索引属性都没被修改 (索引键是否修改是在执行时逐行判断的,因此若一条UPDATE语句修改了某属 性,但前后值相同则认为没有修改),且新版本与原版本存储在一个页面上则不 会产生新的索引记录 由于索引中完全没有版本信息,不能实现Coverage index scan,即查询只
扫描索引,直接从索引中返回所需的属性,还需要访问表。而oracle是完全实现 了Covera index scan,Innodb是部分实现了(在某种情况下也是可以的,但不 是所有情况下都可以了)。
PostgreSQL多版本实现
在业务上产生的差异:
对于insert操作,oracle和innodb,需要在数据文件插入数据,在回滚段中
MySQL与PostGreSQL的区别
MySQL与PostGreSQL的区别
openstack性能优化
MySQL与PostGreSQL的区别
⼀.PostgreSQL相对于MySQL的优势
1、在SQL的标准实现上要⽐MySQL完善,⽽且功能实现⽐较严谨;
2、存储过程的功能⽀持要⽐MySQL好,具备本地缓存执⾏计划的能⼒;
3、对表连接⽀持较完整,优化器的功能较完整,⽀持的索引类型很多,复杂查询能⼒较强;
4、PG主表采⽤堆表存放,MySQL采⽤索引组织表,能够⽀持⽐MySQL更⼤的数据量。
5、PG的主备复制属于物理复制,相对于MySQL基于binlog的逻辑复制,数据的⼀致性更加可靠,复制性能更⾼,对主机性能的影响也更⼩。
6、MySQL的存储引擎插件化机制,存在锁机制复杂影响并发的问题,⽽PG不存在。
⼆、MySQL相对于PG的优势:
1、innodb的基于回滚段实现的MVCC机制,相对PG新⽼数据⼀起存放的基于XID的MVCC机制,是占优的。
因此MySQL的速度是⾼于PG 的;
2、MySQL采⽤索引组织表,这种存储⽅式⾮常适合基于主键匹配的查询、删改操作,但是对表结构设计存在约束;
3、MySQL的优化器较简单,系统表、运算符、数据类型的实现都很精简,⾮常适合简单的查询操作;
4、MySQL分区表的实现要优于PG的基于继承表的分区实现,主要体现在分区个数达到上千上万后的处理性能差异较⼤。
总结:
PG具备更⾼的可靠性,对数据⼀致性完整性的⽀持⾼于MySQL,因此PG更加适合严格的企业应⽤场景(⽐如⾦融、电信、ERP、CRM);⽽MySQL查询速度较快,更加适合业务逻辑相对简单、数据可靠性要求较低的互联⽹场景(⽐如google、facebook、alibaba)。
ComparativaPostgreSQL_MySQL
3.6.2 MySQL3.7 DataTypes3.8 Subqueries3.9 Advanced Indexing3.10 Partitioning3.11 Data Storage Engines3.11.1 PostgreSQL3.11.2 MySQL4 Licensing5 Development6 Culture6.1 Community6.2 Name6.3 Popularity7 Links7.1 Pro PostgreSQL7.2 Pro MySQL7.3 Logo Death MatchPerformanceDatabase systems can be optimized according to the environment in which they run. Thus, it is very difficult to give an accurate comparison in performance without paying attention to configuration and environment. PostgreSQL and MySQL both employ various technologies to improve performance at the basic level:BeginningsMySQL began development with a focus on speed while PostgreSQL began development with a focus on features and standards. Thus, MySQL was often regarded as the faster of the two. PostgreSQL's default configuration was designed to run on low-memory systems.Raw SpeedMySQL's MyISAM engine performs faster than PostgreSQL on simple queries and when concurrency is low or follows certain patterns (e.g. inserts are lock-free only on optimized tables, count(*) is very fast). MyISAM's speed comes at the cost of not supporting transactions, foreign keys, and not offering guaranteed data durability. Data CompressionPostgreSQL can compress and decompress its data on the fly with a fast compression scheme to fit more data in an allotted disk space. The advantage of compressed data, besides saving disk space, is that reading data takes less IO, resulting in faster data reads.MySQL's high performance storage engines do not support on-the-fly compression as of 5.1. MySQL 6.0 will support on-the-fly compression with its Falcon storage engine:Data stored in the Falcon tablespace is compressed on disk, but is stored in an uncompressed format inmemory. Compression occurs automatically when data is committed to disk.— MySQL AB , 12.6.6.6. Data Compression (/doc/refman/6.0/en/se-falcon-principles-compression.html)With the InnoDB installed via Plugin MySQL 5.1 supports on-the-fly compression of InnoDB tables: Beginning with this release of the InnoDB Plugin, you can use the attributesROW_FORMAT=COMPRESSED or KEY_BLOCK_SIZE in the CREATE TABLE and ALTER TABLEcommands to request InnoDB to compress each page to 1K, 2K, 4K, 8K, or 16K bytes.— InnoBASE OY , 3.2. Specifying Compression (/doc/innodb_plugin-1.0/innodb-compression.html#innodb-compression-usage)MySQL's MyISAM engine supports index compression which it uses by default to some extent. Better index compression can be gained by using the PACK_KEYS option (/doc/refman/5.0/en/key-space.html) . Other stable storage engines in MySQL at the time of writing do not have this feature, so their indexes use more space.Tables in the MyISAM engine can be packed with myisampack (/doc/refman/5.0/en/myisampack.html) which makes them readonly, but saves a lot of space.MySQL also supports network protocol-level compression which is an option which can be turned on by the client if the server allows it. This compresses everything to and from the server.MySQL supports on-the-fly compression since version 5.0 with the ARCHIVE storage engine(/doc/refman/5.1/en/archive-storage-engine.html) . Archive is a write-once, read-many storage engine, designed for historical data. It compresses data up to 90%. It does not support indexes. However, in version 5.1 it can be used with partitioning.Multi-ProcessorPostgreSQL's speed advantage over MySQL can be seen drastically in a large multi-core/processor environment.[1] (/node/734) Even MySQL developers admit that current MySQL's use of multi-core/processor technology is not up to par. [2] (/2008/09/more-patches-than-we-know-what-to-do.html) Recent patches from Google and Percona hold promise of closing the gap.Configured SpeedPostgreSQL provides features that can lead to faster performance on certain queries:partial indexingTOAST (/docs/current/static/storage-toast.html) data compressiongreater memory allocation by default in recent versions on capable systemsimproved cache management in versions 8.1 and 8.2MySQL also supports partial indexing using the InnoDB engine, but not with the MyISAM engine. Even when using the InnoDB engine, however, system tables use the MyISAM engine.While it is true that with a default install MySQL used to soundly beat PostgreSQL on many performancemetrics, past benchmarks showing greater performance from MySQL than PostgreSQL have tended to suffer from a number of problems:It was not uncommon to see a performance-tuned MySQL server pitted against an untuned, default-configuration PostgreSQL server.Comparison benchmarks often grouped transactions in unrealistic manners that did not reflect real-world application behavior, leading to a mismatch in how many discrete operations were being performed at a time and the relationships between them from one database to the next.MyISAM ACID-noncompliant "transactions" were often compared against PostgreSQL ACID-compliant transactions. While this often resulted in greater performance in benchmarks, it also involved testingsystems doing significantly different things. If transactional integrity is of importance to you, greaterperformance with no transactional integrity guarantees may not be an option at all.MyISAM has largely been optimized for single-user performance. This meant a win for M ySQL using MyISAM in many benchmarks. Under heavy use, however, with many concurrent users, MyISAM use of table locks to control access had a dramatic negative effect on performance as the number of users grew -- which was not often addressed by comparison benchmarks.ConcurrencyPostgreSQL scales much better, both in terms of using up-scale hardware, and dealing with concurrency. MySQL, on the other hand, focuses on scale-out technologies and the use of off-the-shelf commodity hardware. Asynchronous I/OPostgreSQL supports a full fledged asynchronous API (/docs/8.3/static/libpq-async.html) for use by client applications. It is reported to increase performance by up to 40% in some cases (/2008/07/faster-io-for-ruby-with-postgres.html) . MySQL lacks Async support, though some drivers have been created to attempt to overcome this deficiency (perl (/p/perl-mysql-async/) ruby (/tqbf/asymy/tree/master) ).COUNT(*)PostgreSQL COUNT(*) is very slow because instead of counting rows using an index scan, it goes through the entire table sequentially. PostgreSQL implements COUNT(*) this way because of the way MVCC (PostgreSQL's concurrency system) stores transaction visibility in the data row and not in the index.The MyISAM engine in MySQL uses an index for COUNT(*) and also caches the count and is thus much faster:The reason MySQL has fast counts, is because, they’re cached. This works in MySQL because MySQL uses serialized INSERTs, but higher grade DBs are transactional, and PostgreSQL uses MVCC, so caching rowcounts produces inaccurate results.— Bad CTK (/) , PostgreSQL Slow Count() Workaround(/2007/12/12/postgresql-count-workaround/)The InnoDB engine in MySQL works similarly to PostgreSQL and with comparable speed. [3](/2006/12/01/count-for-innodb-tables/)ACID ComplianceACID stands for Atomicity, Consistency, Isolation and Durability. This model is used to judge data integrity across database management systems. Most database systems achieve ACID compliance by using transactions. PostgreSQL is fully ACID-compliant, while MySQL's InnoDB storage engine provides engine-levelACID-compliance:MySQL Server (version 3.23-max and all versions 4.0 and above) supports transactions with the InnoDB and BDB transactional storage engines. InnoDB provides full ACID compliance. MySQL Cluster is also atransaction-safe storage engine.—MySQL AB , MySQL 5.0 Reference Manual :: 1.8.5.2 Transactions and Atomic Operations(/doc/refman/5.0/en/ansi-diff-transactions.html)To use MySQL's ACID-compliant engine by default, simply set default-storage-engine=innodb in your configuration file.Innobase Oy, the company that developed InnoDB, was bought by Oracle in October 2005. Oracle and MySQL AB signed a contract to extend licensing for the InnoDB engine in 2006, but some worry that when that license period ends the commercial competition between Oracle (owner of the InnoDB storage engine) and Sun (which bought MySQL AB in February 2008) may lead to future licensing and cost issues for MySQL users. FeaturesPostgreSQL and MySQL both have an impressive array of features that increase data integrity, functionality, and performance. The features included in a database may help improve performance, ease of use, functionality, or stability.Ease of useA "gotcha" is a feature or function which works as advertised - but not as expected.— http://sql-info.de/mysql/gotchas.htmlMySQL has more "gotcha"s[4] (http://sql-info.de/mysql/gotchas.html) than PostgreSQL[5] (http://sql-info.de /postgresql/postgres-gotchas.html) .Insert Ignore / ReplaceMySQL supports INSERT IGNORE and REPLACE statements which inserts if a row exists and does nothing otherwise or replaces the current row, respectively.PostgreSQL supports neither of these statements and suggests using stored procedures to get around the lack of these statements. However, there are major shortcomings:it can only insert a single value at a time. This is a major performance limitation, and also suffersconcurrency issues. INSERT IGNORE and REPLACE handle multi-valued inserted much more gracefully.— Robin Johnson , PostgreSQL Vs. MySQL for INSERT IGNORE + REPLACE - stored procedures,savepoints and beyond (/214267.html)A similar MySQL feature INSERT ... ON DUPLICATE UPDATE is also missing from PostgreSQL and requires use of stored procedures or RULE s which can work only on one row at a time.ConstraintsBoth PostgreSQL and MySQL support Not-Null, Unique, Primary Key and Foreign Key constraints. However MySQL doesn't support the Check constraint (/showthread.php?t=1633783) while PostgreSQL has supported it for a long time.InnoDB tables support checking of foreign key constraints... For other storage engines, MySQL Serverparses and ignores the FOREIGN KEY and REFERENCES syntax in CREATE TABLE statements.—MySQL AB , MySQL 5.1 Reference Manual :: 12.1.9. CREATE TABLE Syntax (/doc/refman/5.0/en/create-table.html)Stored ProceduresBoth PostgreSQL and MySQL support stored procedures.The first query language for PostgreSQL, PL/PgSQL, is similar to Oracle's PL/SQL. PostgreSQL also supports stored procedures in many other languages, including Python, Perl, TCL, Java &c — notably ISO SQL:2003 PSM.MySQL follows the SQL:2003 syntax for stored routines, which is also used by IBM's DB2.—MySQL AB , MySQL 5.1 Reference Manual :: 18 Stored Procedures and Functions ( /doc/refman/5.1/en/stored-procedures.html)TriggersBoth PostgreSQL and MySQL support triggers. A PostgreSQL trigger can execute any user-defined function from any of its procedural languages, not just PL/pgsql.MySQL triggers are activated by SQL statements only. They are not activated by changes in tables made by APIs that do not transmit SQL statements to the MySQL Server; in particular, they are not activated byupdates made using the NDB API.—MySQL AB , MySQL 5.1 Reference Manual :: 19 Triggers (/doc/refman/5.1/en/triggers.html)PostgreSQL also supports "rules," which allow operating on the query syntax tree, and can do some operations more simply that are traditionally done by triggers.Syntax for definition of triggers in PostgreSQL isn't as straightforward as in MySQL. PostgreSQL requires separate definition of a function with specific data type returned.Replication and High AvailabilityReplication is a database management system's ability to duplicate its stored data for the purposes of backupsafety and is one way to prevent database downtime. PostgreSQL and MySQL both support replication: PostgreSQLPostgreSQL is modular by design, and replication is not in the core. There are several packages(/liber/db-postgresql-replication) that allow replication in PostgreSQL:PGCluster (/)Slony-I (/)DBBalancer (/projects/dbbalancer)pgpool (/)PostgreSQL table comparator (/)SkyTools (https:///SkypeGarage/DbProjects/SkyTools)Sequoia (/HomePage)Bucardo (/)It is a common misconception that these "third-party packages" are somehow less well integrated. Slony, for example, was designed and built by Jan Weick, a PostgreSQL core team member, and has a number of other members of the PostgreSQL community involved in its ongoing design and maintenance. However, Slony is considerably slower and uses more resources than MySQL's built-in replication, as it uses SQL and triggers rather than binary log shipping to replicate the data across servers. That may make it less suitable for larger cluster deployments with high performance demands. Recently, the PostgreSQL core team has announced (/pgsql-hackers/2008-05/msg00913.php) that basic replication is planned as part of the 8.4 release.MySQLMySQL ships with replication support. [6] (/doc/refman/5.1/en/replication.html) Starting with version 5.1, MySQL supports two forms of replication; statement based replication (SBR) and row based replication (RBR). SBR collects SQL queries which affect changes to the database in a binary log which the slave servers subscribe to for their changes. RBR instead records the incremental row changes themselves in this binary log that are then applied to the slave. Some storage engines such as NDB and Falcon only support replication using this new row based format. [7] (/doc/refman/5.1/en/replication-formats.html)DataTypesPostgreSQL does not have an unsigned integer data type, but it has a much richer data type support in several aspects: standards compliance, the logically fundamental data type BOOLEAN, user-defined data types mechanism, built-in and contributed data types.PostgreSQL allows columns of a table to be defined as variable-length multidimensional arrays. Arrays of any built-in or user-defined base type, enum type, or composite type can be created. Arrays of domains are not yet supported. [8] (/docs/8.3/interactive/arrays.html)MySQL does not have network IP address data types that PostgreSQL has but does provide INET_ATON() and INET_NTOA() functions to convert IPv4 addresses to and from easily stored integers.SubqueriesBoth MySQL and PostgreSQL support subqueries, but in MySQL some forms can be a huge performance liability. This will be corrected in version 6.0 [9] (/wiki/6.0_Subquery_Optimization_Cheatsheet)Advanced IndexingAdvanced indexing methods allow database systems to optimize queries to achieve greater performance.PartitioningMySQL Supports several forms of horizontal partitioning.RANGELISTHASHKEYComposite partitioning using a combination of RANGE or LIST with HASH or KEY subpartitions PostgreSQL only supports RANGE and LIST partitioning. HASH partitioning is supported via immutable functions. Composite partitioning is also supported.Data Storage EnginesData Storage Engines take into account the medium it is using (for most purposes, databases are stored on disks to provide persistent data) to maximize read/write performance.PostgreSQLPostgreSQL supports one engine, its default Postgres Storage System.There are a number of ways to increase PostgreSQL performance. For non-critical data, you can put its storage directory on a RAM disk. [15] (/2007/12/12/tip-from-an-rhce-memory-storage-on-postgresql/) This, of course, raises the question of why you'd want to put it in a database anyway. There are DSMSes (Data Stream Management Systems) specifically designed to handle transitory data in a highly efficient fashion.MySQLMySQL 5.1 natively supports 9 storage engines (/doc/refman/5.1/en/storage-engines.html) [16] (/engines.html) :MyISAMInnoDBNDB ClusterMERGEMEMORY (HEAP)FEDERATEDARCHIVECSVBLACKHOLEHowever, the federated, and blackhole engines are not actually "storage" engines. (for example "blackhole" does not store anything). InnoDB is developed by the external company InnoBase, which has been acquired by Oracle. It retains its place in standard MySQL distributions as the main transactional engine.MySQL is planning to introduce new engines named Maria and Falcon in an upcoming 6.x version. [17] (/mysql60/) [18] (/wiki/Maria_RoadMap_Design)They include new features such as recovery and more features. These are expected to replace and supplement the MyISAM and InnoDB engines respectively.There are several externally-developed storage engines, some of the most popular are:SolidDBNitroEDBBrightHouseMySQL has several custom and community storage engines under development:PrimeBase XT (/xt/)FederatedODBC (/2456.html)FederatedX (/5798.html)IBM DB2 (/press/us/en/pressrelease/21430.wss)memcached (/index.pl?node_id=506)In some distributions, the default storage engine is MyISAM, which is not transaction safe. Setting the default engine to a transactional engine such as InnoDB is, however, trivial.LicensingPostgreSQL comes with a BSD-style license, which fits the Free Software Definition (/philosophy/free-sw.html) and Open Source Definition (/docs/osd) , and conforms to both the Debian Free Software Guidelines (/social_contract#guidelines) and the Copyfree Standard (/standard) .MySQL's source code is available under terms of the GNU General Public License, which also fits the Free Software and Open Source definitions and conforms to the Debian Free Software Guidelines (but not to the Copyfree Standard). It is also available under a proprietary license agreement, which is typically intended for use by those who wish to release software incorporating MySQL code without having to release the source code for the entire application. In practical terms, this means that MySQL can be distributed with or without source code, as can PostgreSQL, but to distribute without source code in the case of MySQL requires paying MySQL AB for a MySQL Commercial License.Even the MySQL client library is GPL (not LGPL), which means that to use (and therefore link to) the MySQL client library the program must either itself be GPL or you must have a commercial license from MySQL AB. DevelopmentPostgreSQL is not controlled by any single company, but relies on a global community of developers and companies to develop it.MySQL is owned and sponsored by a single for-profit firm, the Swedish company MySQL AB, which holds the copyright to most of the codebase. On 16 January 2008 MySQL AB announced an agreement to be acquired by Sun Microsystems for approximately US $1 billion. [The acquisition (is expected to) closed in the third or fourth quarter of Sun's fiscal year which ended on 30 June 2008 .]MySQL is an open-source PRODUCT.Postgres is an open-source PROJECT.—Greg Sabino Mullane (/greg/index.php?/authors/1-Greg-Sabino-Mullane) , Postgres is not for sale (/greg/index.php?/archives/120-Postgres-is-not-for-sale.html)CultureCommunityMySQL's community is supported in part by the company's Community Relations Team(/wiki/MySQL_Community_Relations_Team) . MySQL AB has sponsored an annual User's Conference and Expo (/news-and-events/users-conference/) since 2003(/news-and-events/users-conference/2003/index.html) . The fact that MySQL AB's business model is based on providing installation, configuration, migration, and special licensing support for the MySQL DBMS probably contributes to the lack of links to third-party and community resources on the official support page (/support/) . Some believe this creates a contentious relationship between the company and the open source software user community, though the evidence seems to suggest that the relationship is almost nonexistent, rather than hostile.With a higher ratio of developers to users, the PostgreSQL community tends to make up for a smaller number of users with a greater density of knowledge in community support resources (/community/) . Lacking the corporate support of a company like MySQL AB (now a subsidiary of Sun), PostgreSQL does benefit from a number of independent companies (/support/professional_support) around the world whose business models center around providing installation, configuration, and migration support for the open source database.NameWhen the ANSI SQL standard was written, its author explained that the official standards-compliant pronunciation of SQL is "ess queue ell". The names of both MySQL and PostgreSQL reflect the pronunciation specified by the SQL standard's author.MySQL is pronounced "my ess queue ell".Because MySQL is an owned software project, MySQL AB has complete control over the name of the project. As a result of this, and the desire for a consistent brand identity, the MySQL name is likely to remain static.PostgreSQL is pronounced "post gress queue ell", formed by combining Postgres (the name of the original database management system from which PostgreSQL is descended) with SQL. PostgreSQL is a true portmanteau, in that it not only combines the spellings and pronunciations of two words, but also their meanings: it is the Postgres DBMS updated to use SQL.There has been talk of going back to the original Postgres name, though how much traction the idea has had is debatable. The PostgreSQL wiki provides an overview of the debate (/wiki/Postgres) , including pros and cons for such a name change and alternatives.PopularityMySQL is widely popular among various open-source web development packages. The MyISAM engine often is the only database engine included in webhosting providers. Many web developers use MySQL.(/5100-22-1045125.html?tag=rbxccnbtr1) Thus, MySQL became widely popular in web development, and MySQL calls itself "The world's most popular open source database," a claim that may be spurious given the broad deployment of other open source DBMSes such as SQLite.Thus, MySQL is stereotyped as "easier" to use than PostgreSQL because of its popularity.LinksMySQL vs. PostgreSQL (2006-October) (http://monstera.man.poznan.pl/wiki/index.php/Mysql_vs_postgres)Open Source Database Software Comparison (/mailsoftware42/db/)What to consider when moving from MySQL to PostgreSQL (/5100-22-1045665.html?tag=rbxccnbtr1)Comparison Matrix (/dbzone/Article/29480?trk=DXRSS_DB) (includes Apache Derby and One$DB)/mt/archives/2005/08/mysql_vs_postgr.html/dsg/external/freeware/pgsql-vs-mysql.html/dbzone/Article/20743Critical comparison as wiki from PhiloVivero (2005) (/wiki/view/Technical/PostgreSQLvsMySQL)Pro PostgreSQLWhy PostgreSQL Instead of MySQL: Comparing Reliability and Speed in 2007(/wiki/Why_PostgreSQL_Instead_of_MySQL:_Comparing_Reliability_and_Speed_in_2007)Transactional DDL in PostgreSQL: A Competitive Analysis (/wiki/Transactional_DDL_in_PostgreSQL:_A_Competitive_Analysis)PostgreSQL vs MySQL with Rails (/articles/2005/06/18/postgresql-vs-mysql-with-rails)/postgresql.html/ng.ruby.rails/12576/article/site-mysql-postgresql-1/blog/2005/11/20/switched-to-postgresql// - Testimonials including database size and performancePro MySQL/code/x/my-postgresql-foray-is-over/ (Discusses the installation and speed of anobsolete version of tsearch2)Logo Death MatchElephant vs. Dolphin. Death Match. Terrain determines the winner.Retrieved from "/wiki/MySQL_vs_PostgreSQL"Category: SoftwareThis page was last modified on 14 October 2008, at 11:59.。
pg和mysql使用差异v0.1(PGandMySQLusedifferentialv0.1)
pg和mysql使用差异v0.1(PG and MySQL use differential v0.1)-- detailed testing:1., primary key self growth mode is different:PG uses sequence implementation to make it easy to get the current sequence valueMySQL uses AUTO_INCREMENT to make it difficult to obtain the primary key ID of the currently inserted dataMySQL has a LAST_INSERT_ID () function, but this function is dependent on the session. It needs to be used with carePg:Create, table, t_id (ID, serial, primary, key, name, varchar (1024));Automatically generated:LOG:, statement:, create, table, t_id (ID, serial, primary, key, name, varchar (1024));NOTICE:, CREATE, TABLE, will, create, implicit, sequence,t_id_id_seq, for, serial, column, t_id.id"NOTICE:, CREATE, TABLE / PRIMARY, KEY, will, create, implicit, index, t_id_pkey, for, table, t_id"DEBUG:, building, index, t_id_pkey, on, table, t_id"Create, table, t_id (ID, serial, primary, key, name, varchar (1024));Insert, into, t_id (name), values ('cross');Insert, into, t_id (name), values ('crossmo_'||currval('t_id_id_seq':: regclass)) ('crossmo_'||currval('t_id_id_seq':: regclass));-- the PG process first queries currval ('t_id_id_seq':: regclass), and then insert, so the query results are as follows:Demo=# select * from t_id;LOG: statement: select * from t_id;ID name |----+-----------1 | cross2 | crossmo_13 | crossmo_2Mysql:Drop table t_id cascade;Create, table, t_id (ID, int, primary, key, auto_increment, name, varchar (1024));Insert, into, t_id (name), values ('crossmo01'),('crossmo02');INSERT, into, t_id (name), VALUES (CONCAT ('crosoo',LAST_INSERT_ID ()), (CONCAT ('crosoo', LAST_INSERT_ID ());INSERT, into, t_id (name) VALUES (CONCAT ('crosoo',LAST_INSERT_ID ());INSERT into t_id (name) VALUES (CONCAT ('crosoo'),LAST_INSERT_ID ());Create, table, t_id (ID, int, primary, key, auto_increment, name, varchar (1024)) CHARACTER, SET=utf8, COLLATE=utf8_bin;Drop table t_id cascade;Create, table, t_id (ID, int, primary, key, auto_increment, name, varchar (1024)) CHARACTER, SET=utf8, COLLATE=utf8_bin;Insert, into, t_id (name), values ('crossmo'), ('cRossmo');Select * from, t_id, where, like,'%R%', name - returns only 1 dataCreate, table, t_id1 (ID, int, primary, key, auto_increment, name, varchar (30));INSERT, into, t_id1 (name), VALUES (CONCAT ('crosoo',LAST_INSERT_ID ()));INSERT, into, t_id (name), VALUES (CONCAT ('crosoo',LAST_INSERT_ID ()));SELECT, LAST_INSERT_ID ();SevenSelect * from t_id1;1 crosoo6Select * from t_id;1 jAck2 Jack3 crosooLAST_INSERT_ID4 crosooLAST_INSERT_ID ()5 crosooLAST_INSERT_ID ()6 crosoo57 crosoo1From the above implementation can be seen: the session, INSERTinto t_id1 (name) VALUES (CONCAT ('crosoo') (LAST_INSERT_ID)); the statement is not t_id1 (LAST_INSERT_ID access), but t_id (last_insert_id). The inserted data is crosoo6而执行插入t_id(名字)值(concat('crosoo ',last_insert_id()));时,获取的是t_id1的last_insert_id此时插入的数据是:crosoo1。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
REAL
存储双精度浮点数,限制由硬件决定。双精度浮点数精确到大约15位小数。UNSIGNED属性不允许负数。
TINYINT
存储有符号或无符号1字节整数。
SMALLINT
存储有符号或无符号2字节整数。
MEDIUMINT
存储有符号或无符号3字节整数。
INTEGER
存储有符号或无符号4字节整数。
用于存储二进制对象(比如图形)的原始二进制数据,最大65,535字节。
MEDIUMBLOB
用于存储二进制对象(比如图形)的原始二进制数据,最大16,777,215字节。
LONGBLOB
用于存储二进制对象(比如图形)的原始二进制数据,最大4GB。
CHAR(n)
CHARACTER(n)
包含固定长度的字符串,用空格填充到长度n。
BIGINT
存储有符号或无符号8字节整数。
TINYTEXT
用于存储最多255字节的字符串数据。
TEXT
用于存储最多65,535字节的字符串数据。
MEDIUMTEXT
用于存储最多16,777,215字节的字符串数据。
LONGTEXT
用于存储最多4GB的字符串数据。
TIME
用3字节的存储空间存储天内的时间。
SET
一种串对象,它可以具有零个或更多的值,这些值必须从值列表 ‘value1’, ‘value2’, ...中选择。
BINARY
与CHAR类型相似,但是存储二进制字节串而不是字符串。
VARBINARY
与VARCHAR类型相似,但是存储二进制字节串而不是字符串。
PostgreSQL数据类型
数据类型
说明
INT8
BIGINT
存储有符号或无符号8字节整数。
SERIAL
SERIAL4
存储自动递增的惟一整数值,最多4字节存储空间。
TEXT
存储长度可变的大型字符串数据,最多1 GB。PostgreSQL自动压缩TEXT字符串。
TIME (WITHOUT TIME ZONE |
WITH TIME ZONE)
存储天内的时间。如果不存储数据库服务器的时区,就使用8字节的存储空间;如果存储时区,就使用12字节。
NUMERIC(p,s)
存储精确的数值,精度(p)和刻度(s)为0或更高。
FLOAT4
REAL
存储浮点数,精度为8或更低和6个小数位。
FLOAT8
DOUBLE PRECISION
存储浮点数,精度为16或更低和15个小数位。
SMALLINT
存储有符号或无符号2字节整数。
INTEGER
存储有符号或无符号4字节整数。
BYTEA
用于存储大型二进制对象(比如图形)的原始二进制数据。使用的存储空间是4字节加上二进制串的长度。
CHAR(n)
CHARACTER(n)
包含固定长度的字符串,用空格填充到长度n。
DATE
用4字节的存储空间存储日历日期(年、月、日)。
DATETIME
存储日历日期和天内的时间。
DECIMAL(p,s)
DATE
用3字节的存储空间存储日历日期(年、月、日)。
DATETIME
用8字节的存储空间存储日历日期和天内的时间。
YEAR
用1字节的存储空间存储两位或四位格式的年份。
DECIMAL(p,s)
NUMERIC(p,s)
存储精确的数值,精度(p)最高为65,刻度(s)为30或更高。
FLOAT
存储浮点数,限制由硬件决定。单精度浮点数精确到大约7位小数。UNSIGNED属性不允许负数。
PostgreSQL&MySQL
MySQL数据类型
数据类型
说明
Bቤተ መጻሕፍቲ ባይዱT
固定长度的位串。
BOOLEAN
存储逻辑布尔值(true/false/unknown),可以是TRUE、true和1;FALSE、false和0。
TINYBLOB
用于存储二进制对象(比如图形)的原始二进制数据,最大255字节。
BLOB
TIMESTAMP (WITHOUT TIME ZONE |
WITH TIME ZONE)
存储日期和时间。可以存储或不存储数据库服务器的时区,使用8字节存储空间。
VARCHAR(n)
CHARACTER VARYING(n)
CHARACTER VARYING
存储可变长度的字符串,最大长度为n。不存储末尾的空格。
TIMESTAMP
用4字节的存储空间存储日期和时间。如果没有提供有效值的话,TIMESTAMP列会自动设置为最近操作的日期和时间。
VARCHAR(n)
CHARACTER VARYING(n)
CHARACTER VARYING
存储长度可变的字符串,最大长度由n指定。末尾的空格不存储。
ENUM
一种串对象,它的值只能是从值列表 ‘value1’, ‘value2’, ..., NULL中选择的一个值。
BIGSERIAL
SERIAL8
存储自动递增的惟一整数,最多8字节。
BIT
固定长度的位串。
BIT VARYING(n)
VARBIT(n)
可变长度的位串,长度为n位。
BOOLEAN
存储逻辑布尔值(true/false/unknown),可以是TRUE、t、true、y、yes和1,或者FALSE、f、false、n、no和0。