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

Template databases

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

The schema is very close to the namespace concept in object-oriented languages. It's often used to organize 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, they can install this extension in the template1 database. Installing an extension in template1 won't 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, this can be used to fix template1.
    • It's 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 doesn't contain encoding-specific or locale-specific data.
You can create a database using a user database as a template. This is very handy for testing, database refactoring purposes, deployment plans, and so on.
主站蜘蛛池模板: 襄汾县| 墨脱县| 竹北市| 岳阳县| 平顶山市| 纳雍县| 吉安县| 饶河县| 拜城县| 南丰县| 长宁区| 济宁市| 台中市| 高陵县| 姚安县| 凌云县| 靖江市| 涿州市| 开江县| 大名县| 五华县| 贡山| 盱眙县| 曲靖市| 常山县| 彝良县| 仙居县| 靖远县| 安达市| 大姚县| 新民市| 临清市| 和政县| 和林格尔县| 丽水市| 铁岭市| 哈尔滨市| 响水县| 珠海市| 常德市| 新建县|