- Learning PostgreSQL 11
- Salahaldin Juba Andrey Volkov
- 257字
- 2021-07-02 13:11:48
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.
推薦閱讀
- 從零開始構建企業級RAG系統
- 程序員修煉之道:程序設計入門30講
- Visual FoxPro程序設計教程(第3版)
- 信息可視化的藝術:信息可視化在英國
- Architecting the Industrial Internet
- Python王者歸來
- 單片機應用與調試項目教程(C語言版)
- Python機器學習基礎教程
- Mastering Android Game Development
- Java EE項目應用開發
- Swift High Performance
- 企業級Java現代化:寫給開發者的云原生簡明指南
- 創新工場講AI課:從知識到實踐
- 編程風格:程序設計與系統構建的藝術(原書第2版)
- Learning IBM Bluemix