- 浏览: 239306 次
最新评论
今天使用pg建库发现两个报错:
ERROR: new collation (zh_CN.UTF-8) is incompatible with the collation of the template database (en_US.UTF-8)
ERROR: source database "template1" is being accessed by other users
建库语句:
CREATE DATABASE tinadb
WITH OWNER = postgres
ENCODING = 'UTF8'
TABLESPACE = pg_default
LC_COLLATE = 'zh_CN.UTF-8'
LC_CTYPE = 'zh_CN.UTF-8'
CONNECTION LIMIT = -1
template template1;
报错信息:
ERROR: new collation (zh_CN.UTF-8) is incompatible with the collation of the template database (en_US.UTF-8)
HINT: Use the same collation as in the template database, or use template0 as template.
按照提示,我们应该使用跟模板数据库相同的collation,或者使用模板template0
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
--------------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
rename_check | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =Tc/postgres +
| | | | | postgres=CTc/postgres
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
其实我们可以看到template0和template1的collate是一样的,但template0允许建立不同的collation的库
解决办法:
CREATE DATABASE rename_check
WITH OWNER = postgres
ENCODING = 'UTF8'
TABLESPACE = pg_default
LC_COLLATE = 'zh_CN.UTF-8'
LC_CTYPE = 'zh_CN.UTF-8'
CONNECTION LIMIT = -1
TEMPLATE template0; --使用template0
另外一个常见的报错信息:
ERROR: source database "template1" is being accessed by other users
DETAIL: There are 1 other session(s) using the database.
解决办法:
1.使用pg的另外一个模板库template0
[postgres@kenyon ~]$ createdb -T template0 tinadb -p 5432
Password:
2.杀掉连接到template1的进程,再执行一次建库语句
postgres=# select procpid from pg_stat_activity where DATNAME = 'template1';
procpid
---------
8879
postgres=# \q
[postgres@kenyon ~]$ kill 8879
附带模板库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表示无限制
postgres=# select * from pg_database;
datname | datdba | encoding | datcollate | datctype | datistemplate | datallowconn | datconnlimit | datlastsysoid | datfrozenxid | dattablespace
| datacl
--------------+--------+----------+-------------+-------------+---------------+--------------+--------------+---------------+--------------+---------------
+--------------------------------------
template1 | 10 | 6 | en_US.UTF-8 | en_US.UTF-8 | t | t | -1 | 12772 | 1795 | 1663
| {=c/postgres,postgres=CTc/postgres}
template0 | 10 | 6 | en_US.UTF-8 | en_US.UTF-8 | t | f | -1 | 12772 | 1795 | 1663
| {=c/postgres,postgres=CTc/postgres}
ERROR: new collation (zh_CN.UTF-8) is incompatible with the collation of the template database (en_US.UTF-8)
ERROR: source database "template1" is being accessed by other users
建库语句:
CREATE DATABASE tinadb
WITH OWNER = postgres
ENCODING = 'UTF8'
TABLESPACE = pg_default
LC_COLLATE = 'zh_CN.UTF-8'
LC_CTYPE = 'zh_CN.UTF-8'
CONNECTION LIMIT = -1
template template1;
报错信息:
ERROR: new collation (zh_CN.UTF-8) is incompatible with the collation of the template database (en_US.UTF-8)
HINT: Use the same collation as in the template database, or use template0 as template.
按照提示,我们应该使用跟模板数据库相同的collation,或者使用模板template0
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
--------------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
rename_check | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =Tc/postgres +
| | | | | postgres=CTc/postgres
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
其实我们可以看到template0和template1的collate是一样的,但template0允许建立不同的collation的库
解决办法:
CREATE DATABASE rename_check
WITH OWNER = postgres
ENCODING = 'UTF8'
TABLESPACE = pg_default
LC_COLLATE = 'zh_CN.UTF-8'
LC_CTYPE = 'zh_CN.UTF-8'
CONNECTION LIMIT = -1
TEMPLATE template0; --使用template0
另外一个常见的报错信息:
ERROR: source database "template1" is being accessed by other users
DETAIL: There are 1 other session(s) using the database.
解决办法:
1.使用pg的另外一个模板库template0
[postgres@kenyon ~]$ createdb -T template0 tinadb -p 5432
Password:
2.杀掉连接到template1的进程,再执行一次建库语句
postgres=# select procpid from pg_stat_activity where DATNAME = 'template1';
procpid
---------
8879
postgres=# \q
[postgres@kenyon ~]$ kill 8879
附带模板库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表示无限制
postgres=# select * from pg_database;
datname | datdba | encoding | datcollate | datctype | datistemplate | datallowconn | datconnlimit | datlastsysoid | datfrozenxid | dattablespace
| datacl
--------------+--------+----------+-------------+-------------+---------------+--------------+--------------+---------------+--------------+---------------
+--------------------------------------
template1 | 10 | 6 | en_US.UTF-8 | en_US.UTF-8 | t | t | -1 | 12772 | 1795 | 1663
| {=c/postgres,postgres=CTc/postgres}
template0 | 10 | 6 | en_US.UTF-8 | en_US.UTF-8 | t | f | -1 | 12772 | 1795 | 1663
| {=c/postgres,postgres=CTc/postgres}
发表评论
-
pg 锁
2016-01-14 16:26 0pg 锁 ... -
postgresql 的三类日志
2016-01-14 15:59 18406一、PostgreSQL有3种日志: 1)pg_log(数据 ... -
pg存储过程--创建分区表
2016-01-13 15:46 01)将普通表改成按时间字段分区表 调用select fun_c ... -
pg常用自制shell脚本-tina
2016-01-13 15:30 48481)小型监控: 1.在pg库主机上部署,每5分钟执行一次,插入 ... -
postgresql 时间类型和相关函数
2016-01-13 10:41 5339今天来好好学习一下postgresql涉及时间的字段类型和一些 ... -
pg 表空间
2016-01-07 16:28 3088一、说明 在数据库运维工作中,经常会有数据目录使用率较高 ... -
pg 定期vacuum和reindex
2016-01-07 14:56 8565定期vacuum和reindex: 一 ... -
pg 序列
2016-01-06 16:58 1577一、简介 一个序列对象通常用于为行或者表生成唯一的标识符。 ... -
pg 简单备份和恢复
2016-01-06 15:53 3728pg的备份和恢复 pg_dump ... -
ERROR: invalid page header in block 27073 of relation base/21078/45300926
2016-01-06 15:12 2114突然断网,检查后通知我们UPS断电,db所在主机重启 1、连上 ... -
pg_cancel_backend()和pg_terminate_backend()
2016-01-05 17:42 3518pg_cancel_backend()和pg_terminat ... -
canceling statement due to conflict with recovery
2016-01-05 17:12 1621报错: canceling statement due to ... -
postgresql dblink 使用
2015-12-31 14:33 2010dblink的使用 pg的跨库查询工具 select dbli ... -
root用户不能使用psql或者pg_dump等pg命令
2015-12-24 14:40 6956root用户不能使用psql或者pg_dump等pg命令 [ ... -
安装postgresql 9.1.1
2015-12-22 16:25 611安装postgresql 9.1.1 ---版本自选,步骤相同 ... -
pgbadger监控安装和使用
2015-12-21 10:01 2001pgbadger监控安装和使用 https://github ... -
oracle,postgresql,mysql一些使用上的区别记录
2015-12-16 11:38 01.限制行数: select * from ta where ... -
postgresql存储过程实例:已审核证书存入临时表
2015-12-14 16:44 622存储过程实例: 需求: 思路:建立存储过程 代码逻辑: 1 ... -
pg 函数sfa_tmp_sleep()执行越来越慢-sql分析
2015-12-11 09:48 646pg 函数sfa_tmp_sleep()执行越来越慢 ... -
pgpool 主从流复制模式下的安装使用
2015-12-11 09:50 4092pgpool-II 是一个位于 PostgreSQL 服务器和 ...
相关推荐
navicat 连接PostgreSQL报错:ERROR: SSL connection is required by the database system
postgresql ubantu离线安装版报错的补丁
CodeSmith8.0.1连接PostgreSQL会报错,缺少对应的Npgsql.dll,文件中包含3个DLL和使用说明,以及给出PostgreSQL的连接字符串示例,本人亲测有效。
Navicat premium是一款数据库管理工具,是一个可多重连线资料库的管理工具,它可以让你以单一程式同时连线到 MySQL、SQLite、Oracle 及 PostgreSQL 资料库,让管理不同类型的资料库更加的方便。
postgresql 示例库 dvdrental.zip
arm架构下的postgresql库文件,postgresql版本postgresql-11.1.tar.bz2。本类库我为编译poco,poco可编译。
Postgresql 10.20.2 Windows 64位安装包Postgresql 10.20.2 Windows 64位安装包Postgresql 10.20.2 Windows 64位安装包Postgresql 10.20.2 Windows 64位安装包Postgresql 10.20.2 Windows 64位安装包Postgresql ...
postgresql, PostgreSQL cookbook 开发库 cookbook 安装并配置PostgreSQL作为客户机或者服务器。要求平台Amazon LinuxDebian 7 Ubuntu 14.04 红色 Hat/CentOS/Scientific 6 Fed
按顺序执行以下命令即可完整安装PostgreSQL所需Zlib和readline依赖: sudo dpkg -i zlib1g-dev_1.2.8.dfsg-1ubuntu1_amd64.deb sudo dpkg -i libtinfo-dev_5.9+20140118-1ubuntu1_amd64.deb sudo dpkg -i ...
postgresql数据库的一个关于租赁DVD的商店的例子,里面详细介绍了DVD租赁的一些逻辑表。
PostgreSQL DBA认证 PGCA-E-090 应用管理基础考核题库
本文是postgreSQL 13.5 windows安装与 Linux 安装 及 常见命令, 由作者自身一步步实践写出来了,主要也是为了记录下操作步骤备忘. 全文通俗易懂,图文并茂一步步安装 和 并使用psql 常规命令; 本文是postgreSQL 13.5 ...
postgresql9.6数据库jdbc连接资源包,一般拷贝至tomcatl下的相应的lib目录下;
postgresql PGCA 课程PPT01_postgresql_PGCA_PGCP_PGCM_课程全免费 postgresql PGCA 课程PPT01_postgresql_PGCA_PGCP_PGCM_课程全免费 postgresql PGCA 课程PPT01_postgresql_PGCA_PGCP_PGCM_课程全免费 postgresql ...
PostgreSQL(postgresql-13.5.tar.bz2) PostgreSQL是一种特性非常齐全的自由软件的对象-关系型数据库管理系统(ORDBMS),是以加州大学计算机系开发的POSTGRES,4.2版本为基础的对象关系型数据库管理系统。...
PostgreSQL(postgresql-14.2-2-windows-x64.exe),适用于Windows系统:PostgreSQL是一种特性非常齐全的自由软件的对象-关系型数据库管理系统(ORDBMS),是以加州大学计算机系开发的POSTGRES,4.2版本为基础的对象...
使用postgreSQL所需要的库文件。包含了头文件,lib文件,dll文件。测过,可用。
PostgreSQL存储二进制数据.htm
PostgreSQL DBA认证 PGCE-E-092-中级SQL题目,可以测试你对SQL的掌握程序,特别好的文档,分享给大家学习了
PostgreSQL学习文档。