Skip to content

Odoo Database Creation Failed — 'could not create database' and Template Errors Fix

DeployMonkey Team · March 24, 2026 9 min read

Database Creation Failures in Odoo

When you try to create a new database through the Odoo database manager or command line, several errors can block creation. The most common error messages:

ProgrammingError: could not create database "mydb"
DETAIL: permission denied to create database

OperationalError: source database "template1" is being accessed by other users
DETAIL: There is 1 other session using the database.

Error: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)

Error 1: Permission Denied to Create Database

Cause: The PostgreSQL user configured in odoo.conf does not have the CREATEDB privilege.

# Check current privileges
sudo -u postgres psql -c "\du" | grep odoo

# Grant CREATEDB privilege
sudo -u postgres psql -c "ALTER USER odoo CREATEDB;"

# Verify
sudo -u postgres psql -c "SELECT usename, usecreatedb FROM pg_user WHERE usename='odoo';"

If Odoo uses a superuser role, ensure it has the right permissions:

# Make odoo a superuser (development only — not recommended for production)
sudo -u postgres psql -c "ALTER USER odoo WITH SUPERUSER;"

Error 2: Template1 In Use

Cause: Another connection is using the template1 database, which PostgreSQL needs as a template for new databases.

# Find connections to template1
sudo -u postgres psql -c "SELECT pid, usename, application_name FROM pg_stat_activity WHERE datname='template1';"

# Terminate those connections
sudo -u postgres psql -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname='template1' AND pid <> pg_backend_pid();"

# Retry database creation

Alternatively, use template0 which cannot have active connections:

sudo -u postgres createdb -T template0 -O odoo mydb

Error 3: Encoding Mismatch

Cause: The template database uses SQL_ASCII encoding, but Odoo requires UTF8.

# Check template encoding
sudo -u postgres psql -c "SELECT datname, pg_encoding_to_char(encoding) FROM pg_database;"

# Fix: Create database from template0 with explicit encoding
sudo -u postgres createdb -T template0 -E UTF8 --lc-collate='en_US.UTF-8' --lc-ctype='en_US.UTF-8' -O odoo mydb

To fix template1 permanently:

sudo -u postgres psql
UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';
DROP DATABASE template1;
CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8';
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';
\q

Error 4: Disk Space Full

Cause: PostgreSQL cannot create the database files because the disk is full.

# Check disk space
df -h /var/lib/postgresql/

# Check PostgreSQL data directory specifically
du -sh /var/lib/postgresql/16/main/

# Free space by cleaning old WAL files, vacuuming, etc.
sudo -u postgres psql -c "VACUUM FULL;"

# Or remove old unused databases
sudo -u postgres dropdb old_test_database

Error 5: Database Manager Disabled

If the Odoo web database manager shows no creation form:

# Check odoo.conf
list_db = True        # Must be True to show database manager
db_name =             # Must be empty (not set to a specific database)
admin_passwd = admin  # Master password must be set

# If list_db is False, enable it:
list_db = True

Error 6: Timeout During Creation

Large demo data or slow disks can cause timeouts:

# Create without demo data (faster)
./odoo-bin -d mydb --without-demo=all --stop-after-init

# Increase timeout in odoo.conf
limit_time_real = 600
limit_time_cpu = 300

Quick Diagnostic Flow

ErrorFirst CheckFix
Permission denied\du in psqlALTER USER odoo CREATEDB
Template in usepg_stat_activityTerminate or use template0
Encoding mismatchpg_database encodingRecreate template1 as UTF8
Disk fulldf -hFree space or expand disk

Prevention

DeployMonkey creates databases with validated templates, correct encoding, and proper user privileges. The AI agent monitors disk space and connection limits proactively. Database provisioning is fully automated and error-free.