The advantages and disadvantages of mysql and posgresql are compared

characteristic MySQL PostgreSQL
example Start the instance by executing the MySQL command (mysqld). An instance can manage one or more databases. A server can run multiple instances of mysqld. An instance manager can monitor individual instances of mysqld. Start the instance by executing the Postmaster process (pg_ctl). An instance can manage one or more databases, which form a cluster. A cluster is an area on disk that is initialized at install time and consists of a directory in which all data is stored. Use initdb to create the first database. Multiple instances can be launched on a single machine.
database A database is a named collection of objects, a separate entity from other databases in an instance. All databases in a MySQL instance share the same system catalog. A database is a named collection of objects, and each database is a separate entity from the others. Each database has its own system catalog, but all databases share pg_databases.
data buffer The data buffer is set through the innodb_buffer_pool_size configuration parameter. This parameter is the number of bytes in the memory buffer that InnoDB uses to cache table data and indexes. On a dedicated database server, this parameter can be set up to 80% of the machine's physical memory. Shared_buffers cache. 64 buffers are allocated by default. The default block size is 8K. The buffer cache can be updated by setting the shared_buffers parameter in the postgresql.conf file.
Database linkage The client uses the CONNECT or USE statement to connect to the database. At this time, the database name should be specified, and the user id and password can also be specified. Use roles to manage users and user groups in the database. The client uses the connect statement to connect to the database. At this time, you need to specify the database name, and you can also specify the user id and password. Use roles to manage users and user groups in the database.
Authentication MySQL manages authentication at the database level. Basically, only password authentication is supported. PostgreSQL supports rich authentication methods: trust authentication, password authentication, Kerberos authentication, Ident-based authentication, LDAP authentication, PAM authentication
encryption Passwords can be specified at the table level to encrypt data. Column data can also be encrypted and decrypted using the AES_ENCRYPT and AES_DECRYPT functions. Network encryption is possible over an SSL connection. Columns can be encrypted/decrypted using functions in the pgcrypto library. Network encryption is possible over an SSL connection.
audit You can grep the querylog. You can use PL/pgSQL triggers on tables for auditing.
query explanation Use the EXPLAIN command to view the explain plan of a query. Use the EXPLAIN command to view the explain plan of a query.
Backup, Recovery and Logging InnoDB uses write-ahead logging. Online and offline full backups and crash and transaction recovery are supported. Third-party software is required to support hot backup. A write-ahead log is maintained in a subdirectory of the data directory. Online and offline full backups and crash, point-in-time, and transaction recovery are supported. Can support hot backup.
JDBC driver  The JDBC driver can be downloaded from  Resources .  The JDBC driver can be downloaded from  Resources .
table type Depends on storage engine. For example, the NDB storage engine supports partitioned tables, and the in-memory engine supports in-memory tables. Temporary tables, regular tables, and partitioned tables of range and list types are supported. Hash partitioned tables are not supported. Since PostgreSQL's table partitioning is accomplished through table inheritance and rule system, more complex partitioning methods can be implemented.
index type Depends on storage engine. MyISAM: BTREE, InnoDB: BTREE. B-Tree, Hash, R-Tree and Gist indexes are supported.
constraint Primary key, foreign key, unique and not-null constraints are supported. Check constraints are resolved, but not enforced. Supports primary keys, foreign keys, unique, not-null, and check constraints.
Stored Procedures and User-Defined Functions The CREATE PROCEDURE and CREATE FUNCTION statements are supported. Stored procedures can be written in SQL and C++. User-defined functions can be written in SQL, C, and C++. 没有单独的存储过程,都是通过函数实现的。用户定义函数可以用 PL/pgSQL(专用的过程语言)、PL/Tcl、PL/Perl、PL/Python 、SQL 和 C 编写。
触发器 支持行前触发器、行后触发器和语句触发器,触发器语句用过程语言复合语句编写。 支持行前触发器、行后触发器和语句触发器,触发器过程用 C 编写。
系统配置文件 my.conf Postgresql.conf
数据库配置 my.conf Postgresql.conf
客户机连接文件 my.conf pg_hba.conf
XML 支持 有限的 XML 支持。 有限的 XML 支持。
数据访问和管理服务器 OPTIMIZE TABLE —— 回收未使用的空间并消除数据文件的碎片
myisamchk -analyze —— 更新查询优化器所使用的统计数据(MyISAM 存储引擎)
mysql —— 命令行工具
MySQL Administrator —— 客户机 GUI 工具
Vacuum —— 回收未使用的空间
Analyze —— 更新查询优化器所使用的统计数据
psql —— 命令行工具
pgAdmin —— 客户机 GUI 工具
并发控制 支 持表级和行级锁。InnoDB 存储引擎支持 READ_COMMITTED、READ_UNCOMMITTED、REPEATABLE_READ 和 SERIALIZABLE。使用 SET TRANSACTION ISOLATION LEVEL 语句在事务级设置隔离级别。 支 持表级和行级锁。支持的 ANSI 隔离级别是 Read Committed(默认 —— 能看到查询启动时数据库的快照)和 Serialization(与 Repeatable Read 相似 —— 只能看到在事务启动之前提交的结果)。使用 SET TRANSACTION 语句在事务级设置隔离级别。使用 SET SESSION 在会话级进行设置。

PostgreSQL主要优势:
1. PostgreSQL完全免费,而且是BSD协议,如果你把PostgreSQL改一改,然后再拿去卖钱,也没有人管你,这一点很重要,这表明了 PostgreSQL数据库不会被其它公司控制。oracle数据库不用说了,是商业数据库,不开放。而MySQL数据库虽然是开源的,但现在随着SUN 被oracle公司收购,现在基本上被oracle公司控制,其实在SUN被收购之前,MySQL中最重要的InnoDB引擎也是被oracle公司控制 的,而在MySQL中很多重要的数据都是放在InnoDB引擎中的,反正我们公司都是这样的。所以如果MySQL的市场范围与oracle数据库的市场范 围冲突时,oracle公司必定会牺牲MySQL,这是毫无疑问的。
2. 与PostgreSQl配合的开源软件很多,有很多分布式集群软件,如pgpool、pgcluster、slony、plploxy等等,很容易做读写分离、负载均衡、数据水平拆分等方案,而这在MySQL下则比较困难。
3. PostgreSQL源代码写的很清晰,易读性比MySQL强太多了,怀疑MySQL的源代码被混淆过。所以很多公司都是基本PostgreSQL做二次开发的。
4. PostgreSQL在很多方面都比MySQL强,如复杂SQL的执行、存储过程、触发器、索引。同时PostgreSQL是多进程的,而MySQL是线 程的,虽然并发不高时,MySQL处理速度快,但当并发高的时候,对于现在多核的单台机器上,MySQL的总体处理性能不如PostgreSQL,原因是 MySQL的线程无法充分利用CPU的能力。
目前只想到这些,以后想到再添加,欢迎大家拍砖。
PostgreSQL与oracle或InnoDB的多版本实现的差别

PostgreSQL与oracle或InnoDB的多版本实现最大的区别在于最新版本和历史版本是否分离存储,PostgreSQL不分,而oracle和InnoDB分,而innodb也只是分离了数据,索引本身没有分开。
PostgreSQL的主要优势在于:
1. PostgreSQL没有回滚段,而oracle与innodb有回滚段,oracle与Innodb都有回滚段。对于oracle与Innodb来说, 回滚段是非常重要的,回滚段损坏,会导致数据丢失,甚至数据库无法启动的严重问题。另由于PostgreSQL没有回滚段,旧数据都是记录在原先的文件 中,所以当数据库异常crash后,恢复时,不会象oracle与Innodb数据库那样进行那么复杂的恢复,因为oracle与Innodb恢复时同步 需要redo和undo。所以PostgreSQL数据库在出现异常crash后,数据库起不来的几率要比oracle和mysql小一些。
2. 由于旧的数据是直接记录在数据文件中,而不是回滚段中,所以不会象oracle那样经常报ora-01555错误。
3. 回滚可以很快完成,因为回滚并不删除数据,而oracle与Innodb,回滚时很复杂,在事务回滚时必须清理该事务所进行的修改,插入的记录要删除,更新的记录要更新回来(见row_undo函数),同时回滚的过程也会再次产生大量的redo日志。
4. WAL日志要比oracle和Innodb简单,对于oracle不仅需要记录数据文件的变化,还要记录回滚段的变化。

PostgreSQL的主要劣势在于:
1、最新版本和历史版本不分离存储,导致清理老旧版本需要作更多的扫描,代价比较大,但一般的数据库都有高峰期,如果我们合理安排VACUUM,这也不是很大的问题,而且在PostgreSQL9.0中VACUUM进一步被加强了。
2、由于索引中完全没有版本信息,不能实现Coverage index scan,即查询只扫描索引,直接从索引中返回所需的属性,还需要访问表。而oracle与Innodb则可以;
PostgreSQL9.0中的特色功能:
PostgreSQL中的Hot Standby功能
也就是standby在应用日志同步时,还可以提供只读服务,这对做读写分离很有用。这个功能是oracle11g才有的功能。

PostgreSQL异步提交(Asynchronous Commit)的功能:
这个功能oracle中也是到oracle11g R2才有的功能。因为在很多应用场景中,当宕机时是允许丢失少量数据的,这个功能在这样的场景中就特别合适。在PostgreSQL9.0中把 synchronous_commit设置为false就打开了这个功能。需要注意的是,虽然设置为了异步提交,当主机宕机时,PostgreSQL只会 丢失少量数据,异步提交并不会导致数据损坏而数据库起不来的情况。MySQL中没有听说过有这个功能。

PostgreSQL中索引的特色功能:
PostgreSQL中可以有部分索引,也就是只能表中的部分数据做索引,create index 可以带where 条件。同时PostgreSQL中的索引可以反向扫描,所以在PostgreSQL中可以不必建专门的降序索引了。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324685116&siteId=291194637