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

Template databases

By default, when a database is created, it is cloned from a template database called template1. The template database contains a set of tables, views, and functions, which is used to model the relation between the user-defined database objects. These tables, views, and functions are a part of the system catalog schema called pg_catalog.

The schema is very close to the namespace concept in object-oriented languages. It is often used to organize the database objects, functionality, security access, or to eliminate name collision.

The PostgreSQL server has two template databases:

  • template1: The default database to be cloned. It can be modified to allow global modification to all the newly created databases. For example, if someone intends to use a certain extension in all the databases, then they can install this extension in the template1 database. Certainly, installing an extension in template1 will not be cascaded to the already existing databases, but it will affect the databases that will be created after this installation.
  • template0: A safeguard or version database that has several purposes:
    • If template1 is corrupted by a user, then it can be used to fix template1.
    • It is handy in restoring a database dump. When a developer dumps a database, all the extensions are also dumped. If the extension is already installed in template1, this will lead to a collision, because the newly created database already contains the extensions. Unlike template1, template0 does not contain encoding-specific or locale-specific data.

One can create a database using a user database as a template. This is very handy for testing, database refactoring purposes, deployment plans, and more.

主站蜘蛛池模板: 察雅县| 龙山县| 健康| 苏尼特右旗| 巴东县| 白银市| 乌兰县| 申扎县| 姚安县| 岚皋县| 浦北县| 南澳县| 资兴市| 巴彦淖尔市| 图木舒克市| 合山市| 孟州市| 陇南市| 建宁县| 井冈山市| 绥棱县| 石渠县| 黄浦区| 恭城| 湖州市| 新丰县| 岳普湖县| 通化市| 海南省| 独山县| 临澧县| 甘孜县| 剑川县| 凤凰县| 平江县| 南乐县| 富阳市| 东方市| 梁平县| 且末县| 丰台区|