PG :template1 is being accessed by other users
来源:互联网 发布:淘宝怎么投诉刷订单 编辑:程序博客网 时间:2024/06/04 10:39
开发在给一台开发机上新建一个Postgres数据库的时候报错。 建库语句:
解决办法:
1.使用PG的另外一个模板库template0
附带模板库template0 与 template 1以及数据库视图pg_database的说明
1.安装好数据库初始化时,template0与template1都是一样的,是一个干净的库,内容也一样
2.初始化完以后,用户可定制template1,比如新增自定义函数,在创建新库时都会附带该自定义函数而无需在新库里创建
3.一般不允许再对template0进行各种操作,以保证其是个干净的库,对数据库的恢复比较有帮助。数据库恢复建立新库时可以指定template0为模板,可以创建一个干净的新库
4.创建新库时是不能连接新的session的,而有新的session连在模板库上会导致创建失败,如上例
5.视图pg_database的主要字段说明
datallowconn 表示可否允许连接,template0一般不允许连接,其他数据库可连接
datconnlimit 表示连接限制,-1表示无限制
CREATE DATABASE temp_kenyon WITH OWNER = postgres ENCODING = 'UTF8' TABLESPACE = pg_default LC_COLLATE = 'C' LC_CTYPE = 'C' CONNECTION LIMIT = -1;报错信息:
ERROR: source database "template1" is being accessed by other usersDETAIL: There are 1 other session(s) using the database.********** 错误 **********ERROR: source database "template1" is being accessed by other usersSQL 状态: 55006详细:There are 1 other session(s) using the database.分析: 错误提示比较明显,有一个其他的session正连在template1上,而这个是模板库,PG不允许在新建库时有其他连接连在上面
解决办法:
1.使用PG的另外一个模板库template0
[postgres@kenyon ~]$ createdb -T template0 tets_kenyon -p 5432Password: [postgres@kenyon ~]$ psql -p 5432Password: psql (9.1.2)Type "help" for help.postgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -------------+----------+----------+---------+-------+----------------------- postgres | postgres | UTF8 | C | C | template0 | postgres | UTF8 | C | C | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | C | C | =c/postgres + | | | | | postgres=CTc/postgres testof | postgres | UTF8 | C | C | tets_kenyon | postgres | UTF8 | C | C | (6 rows)postgres=# drop database test_kenyon;ERROR: database "test_kenyon" does not existpostgres=# drop database tets_kenyon;DROP DATABASE2.杀掉连接到template1的进程,再执行一次建库语句
postgres=# select procpid from pg_stat_activity where DATNAME = 'template1'; procpid --------- 8879postgres=# \q[postgres@kenyon ~]$ kill 8879CREATE DATABASE blacktea WITH OWNER = postgres ENCODING = 'UTF8' TABLESPACE = pg_default LC_COLLATE = 'C' LC_CTYPE = 'C' CONNECTION LIMIT = -1;It works.
附带模板库template0 与 template 1以及数据库视图pg_database的说明
1.安装好数据库初始化时,template0与template1都是一样的,是一个干净的库,内容也一样
2.初始化完以后,用户可定制template1,比如新增自定义函数,在创建新库时都会附带该自定义函数而无需在新库里创建
3.一般不允许再对template0进行各种操作,以保证其是个干净的库,对数据库的恢复比较有帮助。数据库恢复建立新库时可以指定template0为模板,可以创建一个干净的新库
4.创建新库时是不能连接新的session的,而有新的session连在模板库上会导致创建失败,如上例
5.视图pg_database的主要字段说明
postgres=# \d pg_database; Table "pg_catalog.pg_database" Column | Type | Modifiers ---------------+-----------+----------- datname | name | not null datdba | oid | not null encoding | integer | not null datcollate | name | not null datctype | name | not null datistemplate | boolean | not null datallowconn | boolean | not null datconnlimit | integer | not null datlastsysoid | oid | not null datfrozenxid | xid | not null dattablespace | oid | not null datacl | aclitem[] | Indexes: "pg_database_datname_index" UNIQUE, btree (datname), tablespace "pg_global" "pg_database_oid_index" UNIQUE, btree (oid), tablespace "pg_global"Tablespace: "pg_global"datistemplate:可否允许作为模板,如果true,则任何有createdb的用户都可创建,一般用户数据库该值是false
datallowconn 表示可否允许连接,template0一般不允许连接,其他数据库可连接
datconnlimit 表示连接限制,-1表示无限制
- PG :template1 is being accessed by other users
- 新建数据库失败,提示"template1" being accessed by other users
- PostgreSQL创建数据库时报错:ERROR: source database "template1" is being accessed by other users
- PostgreSQL创建数据库时报错:ERROR: source database "template1" is being accessed by other users
- database "mydb" is being accessed by other users
- 解决方法 dropdb: database removal failed: ERROR: database "TDADB" is being accessed by other users
- ORA-15028: ASM file '+data/prod/datafile/USERS.259.857444651' not dropped; currently being accessed
- Failed to add VMware DC to zone due to : This DC is being managed by other CloudStack deployment.
- Love is being happy for the other person
- template1
- ORA-01105: mount is incompatible with mounts by other instances
- DoIt is Being Flooded
- The process cannot access the file XXX because it is being used by another process
- IIS:The process cannot access the file because it is being used by another process.
- FileStream:The process cannot access the file because it is being used by another process
- error while unload assembly from GAC "assembly is being used by another process"
- 解决 MAC 10.8.2 + VirtualBox 4.1.20 报VT-x is being used by another hypervisor
- The process cannot access the file because it is being used by another process.
- linux命令(16):which命令
- jxl 导出excel通用工具方法
- 数字图像处理:11.傅里叶变换
- 我的Oracle导入数据日志
- linux命令(17):whereis 命令
- PG :template1 is being accessed by other users
- IOS 文件中的沙盒和Bundle
- 黑马程序员-缓冲技术
- linux命令(18):locate 命令
- 第三章 面向对象
- Android.mk可以定义的变量
- 软件测试工具英雄榜
- 使用Yii框架做权限验证 -- 从无到企业级别控制
- linux命令(19):find 命令概览