PostgreSQL 理解 template1 和 template0
模板数据库
模板数据库就是创建新database时,PostgreSQL会基于模板数据库制作一份副本,其中会包含所有的数据库设置和数据文件。
PostgreSQL安装好以后会默认附带两个模板数据库:template0和template1。
postgres=# create database db1;
CREATE DATABASE
|
备注:建库时如果不指定 TEMPLATE 属性,默认用的是 template1 模板库.
postgres=# create database db2 template template0;
CREATE DATABASE
|
备注:也可以指定模板库为 template0
任何时候都不要对template0模板数据库进行任何修改,因为这是原始的干净模板,如果其它模板数据库被搞坏了,基于这个数据库做一个副本就可以了。如果希望定制自己的模板数据库,那么请基于template1进行修改,或者自己另外创建一个模板数据库再修改。对基于template1或你自建的模板数据库创建的数据库来说,你不能修改其字符集编码和排序规则。template0可以。
postgres=# \c template1
You are now connected to database “template1” as user “postgres”.
template1=# create table tmp_1( id int4);
CREATE TABLE
template1=# \c template0
FATAL: database “template0” is not currently accepting connections
Previous connection kept
|
备注:当然可以通过其它方法连接 template0 库,有兴趣的同学自己研究下,这里不演示了。
template1=# create database db3 TEMPLATE template0 ENCODING ‘SQL_ASCII’ ;
CREATE DATABASE
template1=# create database db4 TEMPLATE template1 ENCODING ‘SQL_ASCII’ ;
ERROR: new encoding (SQL_ASCII) is incompatible with the encoding of the template database (UTF8)
HINT: Use the same encoding as in the template database, or use template0 as template.
|
postgres=# drop database template0;
ERROR: cannot drop a template database
postgres=# drop database template1;
ERROR: cannot drop a template database
|
备注:当然有方法删除 template1 库,而且这个操作并不危险,需要修改系统表,这里不演示了。
postgres=# \c francs
You are now connected to database “francs” as user “postgres”.
francs=# select count(*) from pg_stat_user_tables ;
count
——-
41
(1 row)
postgres=# create database francs1 TEMPLATE francs ;
CREATE DATABASE
postgres=# \c francs1 francs
You are now connected to database “francs1” as user “francs”.
francs1=> select count(*) from pg_stat_user_tables ;
count
——-
41
(1 row)
|
备注:这种方法在复制数据库时提供了方便, 也可以定制自己的数据库模板, 但是这么操作有个前提,
ERROR: source database “francs” is being accessed by other users
DETAIL: There is 1 other session using the database.
|
PostgreSQL 理解 template1 和 template0相关推荐
- pgsql之template1 和 template0
template1和template0是pgsql的模板数据库.所谓模板数据库就是创建新database时,PostgreSQL会基于模板数据库制作一份副本,其中会包含所有的数据库设置和数据文件.Po ...
- postgresql 15源码浅析(1)—— postgres中的1号数据库
摘要 在创建数据库集簇后,该集簇中默认会包含三个系统数据库template1.template0和postgres,其中template0和postgres都是在初始化过程中从template1复制出 ...
- PostgreSQL 数据目录结构
根目录介绍 data ├── base # use to store database file(SELECT oid, datname FROM pg_database;) ├── global # ...
- PostgreSQL 编译安装
PostgreSQL 作为一款优秀的开源关系型数据库产品,一直受到各大企业和IT人士的关注.虽然在中国的流行度远远落后于MySQL,但是相信随着开源社区的宣传,还有其优秀的特性,PostgreSQL在 ...
- 安装配置postgreSQL+pgcli+pgadmin3
记录了postgreSQL数据库的完整的安装配置过程,以及postgreSQL的pgcli命令行智能提醒扩展,pgadmin3图形化管理客户端的配置安装.此postgresql是bigsql版安装详情 ...
- Postgresql在Windows下的解压安装
1.将下载的压缩包解压,我是解压在D:\postgreSQL\pgsql中. 2.设置环境变量如下: set PGHOME=D:\postgreSQL\pgsql set PGDATA=%PG ...
- PostgreSQL 压缩包 在win7上安装
1:下载postgresql-9.4.5-3-windows-x64-binaries.zip http://get.enterprisedb.com/postgresql/postgresql-9. ...
- PostgreSQL数据库、表空间、角色及用户
一.创建数据库 1.通过pgAdmin创建数据库TestDb1: 打开数据库TestDb1看到建库脚本: 在目录--PostgreSQL(pg_catalog)--数据表--pg_database中可 ...
- ubuntu14.04 LTS 源码编译安装postgreSQL
一.环境 ubuntu14.04 postgresql-9.4.3 二.安装 1.依赖包安装 sudo apt-get install libperl-dev python-dev libreadli ...
最新文章
- day3 python 学习随笔
- 刀片服务器提升三要点
- SecureCRT 端口转发连接服务器
- Python爬取Json格式数据并读写(改中文编码)
- 前端中全部盒子靠左对齐_前端面试一百问之弹性盒子中 flex: 0 1 auto 表示什么意思...
- MySQL子查询嵌套查询
- Javascript正则表达式完全学习手册
- nrf52832芯片手册_nRF52832低功耗问题不完全总结
- 图像处理中的通信原理——冈萨雷斯读书笔记(四)
- 邮箱服务器怎么清理缓存,如何清除Outlook的附件缓存?
- 前魅族副总裁李楠上手魅族17:颜值提升了
- html鼠标互动旋转立方体,css3 transform及原生js实现鼠标拖动3D立方体旋转的示例介绍...
- H3C nqa 配置
- Tera Term和TTL(Tera Term Language)
- rabbit 消息丢失
- 人工智能守护青山绿水 内蒙古环保厅引入阿里云ET环境大脑
- Mybatis源码学习笔记之Mybatis二级缓存
- python socket清空接收缓冲区_Python网络编程——修改套接字发送和接收的缓冲区大小...
- 实战:从零开始制作一个跑步微信小程序
- 为什么每次用计算机算数都不对,Excel算出来的数,和计算器结果对不上?
热门文章
- device or resource busy_北海or涠洲岛旅游攻略(收藏篇)
- Keystone controller.py routers.py代码解析
- django 基础知识 ~ forms详解
- Github工程师为MySQL高可用性采用了新架构
- js算法入门(2)--哈希表
- 注解 java.lang.annotation.Inherited 介绍
- Atitit.软件GUI按钮与仪表盘--db数据库区--导入mysql sql错误的解决之道
- 差异分析定位Ring 3保护模块
- Prismatic 机器学习不一定得用大框架
- First Chapter--Getting Started With Testing