Tuesday, February 11, 2014

PG::ObjectInUse: ERROR: source database "template1" is being accessed by other users

PG::ObjectInUse: ERROR:  source database "template1" is being accessed by other users
DETAIL:  There are 1 other session(s) using the database.

Database template1 exists only to use structure to create another empty database. You should never login to template1, otherwise you will have problems for login or create database.

Most likely easiest solution for you is to restart PostgreSQL server process, and logon again. 

For restart PostgreSQL server use this command:
sudo service postgresql restart
If restarting is not working then you can use another template database: template0.

For this log in with username and password in postgresql with this command:
sudo -u postgres psql template1
          Enter password if you used password for user "postgres"

Then change template with database_name 

By default, database create for template1 with this statement and this statement:
CREATE DATABASE database_name;
is equivalent to:
CREATE DATABASE database_name TEMPLATE template1;
If template1 is not available or corrupted, you can use template0 as last resort:
CREATE DATABASE database_name TEMPLATE template0;
You can read more about template databases here.


  1. You have shared a lot of information in this article. I would like to express my gratitude to everyone who contributed to this useful article. Keep posting. Business IT Support in London

    1. The error PG::ObjectInUse: ERROR: typically occurs in PostgreSQL when an object (such as a table, index, or database) is being accessed or modified while it's still in use by another process or transaction. This error can happen in various scenarios, such as when you are trying to drop a database, table, or schema that is currently being accessed or when an exclusive lock is required but cannot be obtained.

      Big Data Projects For Final Year Students

      Final Year Project Centers in Chennai

      IEEE projects for cse