欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ERROR: source database "template1" is being accessed by other users解决方法

程序员文章站 2024-03-21 11:56:58
...

postgresql创建新库时报错,显示其他用户正在访问模板库“template1”,详细信息如下:

    postgres=# create database cctest;
    ERROR:  source database "template1" is being accessed by other users 
    DETAIL:  There are 1 other session(s) using the database. 

解决方法:
select * from pg_stat_activity where DATNAME = ‘template1’;

postgres=# select * from pg_stat_activity where DATNAME = 'template1'; 
 datid | datname | pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | xact_start | query_start | state_change | waiting | state | backend_xid | backend_xmin | query 
-------+---------+-----+----------+---------+------------------+-------------+-----------------+-------------+---------------+------------+-------------+--------------+---------+-------+-------------+--------------+-------
(0 rows)

将查出的pid kill掉
SELECT pg_terminate_backend(PID);
之后创建新库即可

或者使用其他模板库创建新库

相关标签: postgres