"could not create database" on a new installation of ubuntu and postgresql 8.3

Bug #331065 reported by Lorenzo Battistini
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Invalid
Undecided
Unassigned
openerp-server (Ubuntu)
Confirmed
Undecided
Unassigned
Nominated for Maverick by agent 8131

Bug Description

After installing and executing openerp-server-5.0.0-3 over ubuntu 8.04 (I used this image http://isv-image.ubuntu.com/vmware/Ubuntu-7.10-desktop-i386.zip and upgraded to 8.04) with postgresql 8.3, I get the following while creating a new database:

[2009-02-18 16:17:47,507] INFO:dbpool:Connecting to template1
[2009-02-18 16:17:47,517] DEBUG:sql:bad query: CREATE DATABASE "dev" ENCODING 'unicode'
[2009-02-18 16:17:47,517] DEBUG:sql:[01]: encoding UTF8 does not match server's locale en_US
[2009-02-18 16:17:47,518] DEBUG:sql:[02]: DETAIL: The server's LC_CTYPE setting requires encoding LATIN1.
[2009-02-18 16:17:47,518] INFO:dbpool:Closing all connections to template1
Closing connection <connection object at 0x883c818; dsn: 'user=root dbname=template1', closed: 0>

I tried to set all locales to en_US.UTF-8 (my ubuntu's default was just en_US):

ubuntu@ubuntu:~$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

After that, I reinstalled postgresql, but it did not work.

I even did a "initdb" for postgresql:

# sudo -u postgres /usr/lib/postgresql/8.3/bin/initdb -D /var/lib/postgresql/8.3/main
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale en_US.UTF-8.
The default database encoding has accordingly been set to UTF8.
The default text search configuration will be set to "english".

fixing permissions on existing directory /var/lib/postgresql/8.3/main ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers/max_fsm_pages ... 24MB/153600
creating configuration files ... ok
creating template1 database in /var/lib/postgresql/8.3/main/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.

Success. You can now start the database server using:

    /usr/lib/postgresql/8.3/bin/postgres -D /var/lib/postgresql/8.3/main
or
    /usr/lib/postgresql/8.3/bin/pg_ctl -D /var/lib/postgresql/8.3/main -l logfile start

but result remains the same

description: updated
description: updated
Revision history for this message
Christophe CHAUVET (christophe-chauvet) wrote :

This is PostgreSQL problem, not an OpenERP Bug.

Check locale for your "postgres" user

Changed in openobject-server:
status: New → Invalid
Revision history for this message
Schmirrwurst (schmirrwurst) wrote :

I'm experiencing the same issue under jaunty, after applying the patch from https://bugs.launchpad.net/openerp/+bug/337759

2009-05-03 14:44:14,292] INFO:dbpool:Connecting to template1
[2009-05-03 14:44:14,296] ERROR:dbpool:Unable to connect to template1: FATAL: authentification Ident échouée pour l'utilisateur « openerp »

summary: - "could not create database" on a new installation of ubuntu 8.04 and
+ "could not create database" on a new installation of ubuntu and
postgresql 8.3
Revision history for this message
Schmirrwurst (schmirrwurst) wrote :

For me it was a authentification problem linked with a bug in the init.d script : https://bugs.launchpad.net/debian/+source/openerp-server/+bug/352299

The solution provided there does not work yet for me, but a workaround is to add the line
local all openerp trust !!! where openerp is the name of your dbuser (in /etc/openerp-server)

or simply to change
local all all ident sameuser
to
local all all trust

and restart postgres

Revision history for this message
agent 8131 (agent-8131) wrote :

I am seeing this problem as well:

PDT ERROR: encoding UTF8 does not match locale en_US

What is the best solution?

Revision history for this message
xrg (xrg) wrote : Re: [Bug 331065] Re: "could not create database" on a new installation of ubuntu and postgresql 8.3

On Sunday 23 May 2010, you wrote:
> I am seeing this problem as well:
>
> PDT ERROR: encoding UTF8 does not match locale en_US
>
> What is the best solution?
>

use "en_US.UTF-8" as your locale.

agent 8131 (agent-8131)
Changed in openerp-server (Ubuntu):
status: New → Confirmed
Revision history for this message
agent 8131 (agent-8131) wrote :

I have verified that this problem exists for a fresh installation of Ubuntu 10.04. Most likely this bug has been present for some time.

xrg: can you be more specific, perhaps including what commands to run. I tried the following (as root):

locale-gen en_US.UTF-8
update-locale en_US.UTF-8

but that had no effect.

Revision history for this message
klearvue (thorovsky-gmail) wrote :

I can confirm that the bug exists - using Lucid and Postgresql 8.4, locale en_GB.

Changing locale to "en_US.UTF-8" solves the problem

Revision history for this message
SeanBoran (sean-boran) wrote :

My fix (for Ubuntu 8.04 with postgres 8.3) was as follows, I know it cannot be the "right" solution but after playing with locales for too long (where did you change the locale?)

change /opt/openerp-server/bin/service/web_services.py

diff web_services.py.ORIG web_services.py
71c71,74
< cr.execute("""CREATE DATABASE "%s" ENCODING 'unicode' TEMPLATE "template0" """ % name)
---
> cr.execute("""CREATE DATABASE "%s" ENCODING 'LATIN1' TEMPLATE "template0" """ % name)

Revision history for this message
xrg (xrg) wrote :

On Wednesday 28 July 2010, you wrote:
> My fix (for Ubuntu 8.04 with postgres 8.3) was as follows, I know it
> cannot be the "right" solution but after playing with locales for too
> long (where did you change the locale?)
>
> change /opt/openerp-server/bin/service/web_services.py
>
> diff web_services.py.ORIG web_services.py
> 71c71,74
> < cr.execute("""CREATE DATABASE "%s" ENCODING 'unicode'
> TEMPLATE "template0" """ % name) ---
>
> > cr.execute("""CREATE DATABASE "%s" ENCODING 'LATIN1' TEMPLATE
> > "template0" """ % name)
>

unicode is the only encoding that OpenERP can work with. The reason is that
all of OpenERP is using utf8 and thus requires full unicode support from the
db.
Latin1 is thus bound to fail. Please never use it.

Initializing the postgres cluster with the correct encoding (for those old
versions that have cluster-wide encoding) is a matter of distro + postgres. We
can help you, but it certainly is not an OpenERP bug.

Revision history for this message
SeanBoran (sean-boran) wrote :

I've ubuntu 8.04 with postgres 8.3.
The locale was en_US in /etc/default/locale, change that to LANG="en_US.UTF-8" and rebooted.
The "locale" command return the new value for root, postgres, openerp users etc.

Still getting in the postgres log:
2010-08-03 14:01:50 CEST ERROR: encoding UTF8 does not match server's locale en_US
2010-08-03 14:01:50 CEST DETAIL: The server's LC_CTYPE setting requires encoding LATIN1.
2010-08-03 14:01:50 CEST STATEMENT: CREATE DATABASE "sean1" ENCODING 'unicode' TEMPLATE "template0"

In /etc/postgresql/8.3/main/postgresql.conf found 4 lc_ settings = 'en_US'.
Changed those to en_US.UTF-8 and restarted postgres. Still the same error message as above

Next used psql as the postgres user:
postgres=# initdb -E en_US.UTF-8

Didn't help either. But the following did work:

Stop postgres, kill my current cluster, reinit and restart:
/etc/init.d/postgresql-8.3 stop
cd /var/lib/postgresql/8.3
mv main main.old
mkdir main
su - postgres
locale (make sure you have en_US.UTF-8)
/usr/lib/postgresql/8.3/bin/initdb -D /var/lib/postgresql/8.3/main
cd main
ln -s /etc/postgresql-common/root.crt root.crt
ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem server.crt
ln -s /etc/ssl/private/ssl-cert-snakeoil.key server.key
/etc/init.d/postgresql-8.3 start

# Test:
su - postgres
psql
postgres=# CREATE DATABASE "test3" ENCODING 'unicode' TEMPLATE "template0";
postgres=# drop database test3;
chown postgres:postgres main

Finally start Openerp, create DBs: all is sweet.

So, basically I'd say make sure that locale is right BEFORE installing postgres :-)

Revision history for this message
Marcos Martinez (frommelmak) wrote :

Or you can simple do the same thing as follows:

/etc/init.d/postgresql-8.3 stop
pg_dropcluster --stop 8.3 main
pg_createcluster --locale en_US.UTF-8 --start 8.3 main
/etc/init.d/postgresql-8.3 start

Revision history for this message
joopie (krusty-the4clown) wrote :

Marcos' solution worked for me (https://bugs.launchpad.net/openobject-server/+bug/331065/comments/11)

Afterwards do not forget to add a db user of course (for instance: sudo -u postgres createuser --createdb --no-createrole --no-superuser -w openerp)

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.