官术网_书友最值得收藏!

PostgreSQL utility tools

Several PostgreSQL utility tools are wrappers around SQL constructs. These tools are used to create and drop databases, users, and languages. For example, the dropdb and createdb commands are wrappers around DROP DATABASE [ IF EXISTS ] and CREATE DATABASE, respectively.

PostgreSQL also provides tools to maintain the system objects, mainly clusterdb and reindexdb. clusterdb is a wrapper around the CLUSTER statement, which is used to physically reorder the table based on certain index information. This can increase database-performance read operations due to the locality of reference principles, mainly the spatial locality. Clustering the table helps to retrieve data from adjacent storage blocks and thus reduces the hard-disk-access cost. 

The CLUSTER command is a blocking command, which means that querying the table will be blocked until the clustering is done. In production systems, blocking commands, such as CLUSTER, should be used wisely. 

reindexdb is a wrapper around reindex SQL statement. There are several reasons to reindex an index, for example, the index might get corrupted—which rarely happens in practice—or bloated. Index bloat happens when the index size grows due to sparse deletion. Index bloat affects performance since index scans take more time due to reading more disk blocks than needed.

In addition to the previous tools, PostgreSQL also provides tools for the following:

  • Physical backup: This is used to back up PostgreSQL's database files. This method is a very fast way to create a backup, but the backup can only be restored on compatible PostgreSQL versions. The pg_basebackup tool is used for this purpose. pg_basebackup is often used to set up streaming replication as the standby is a clone of a master.
  • Logical backup: This is used to back up the database objects in the form of SQL statements, such as CREATE TABLE, CREATE VIEW, and COPY. The generated backup can be restored on different PostgreSQL cluster versions, but it's slow. The pg_dump and pg_dumpall tools are used to dump a single database or a database cluster, respectively. pg_dump also can be used to dump a specific relation or a set of relations and schemas. Also, it has a lot of features, such as dumping schemas only or data only. pg_dumpall internally uses pg_dump to dump all databases on the cluster. Finally, the pg_restore tool is used to restore the dumps generated by pg_dump or pg_dumpall.
pg_dump doesn't dump the  CREATE DATABASE statement command. For example, you can dump a database called customer to another database called client. Due to this, if you have special privileges assigned to the database, such as CONNECT, you need to assign these privileges to the new database.
主站蜘蛛池模板: 巴里| 枣阳市| 屏山县| 桐柏县| 环江| 嘉鱼县| 来宾市| 昭通市| 汉中市| 大石桥市| 邹城市| 自贡市| 凌云县| 云南省| 师宗县| 河南省| 福鼎市| 普陀区| 舟曲县| 沅陵县| 咸宁市| 龙井市| 衡水市| 宜君县| 天峨县| 库伦旗| 贡觉县| 桃江县| 滨州市| 苏尼特右旗| 杨浦区| 连州市| 邳州市| 和政县| 大连市| 新郑市| 得荣县| 额尔古纳市| 西峡县| 惠州市| 仁怀市|