I am trying to create utf-8 database on windows 10:
createdb.exe -h localhost -p 53131 -U user -E UTF8 -T template0 -l en_US.utf-8 test777
But response is:
createdb: database creation failed: ERROR: invalid locale name: "en_US.utf-8"
Any clues?
You should use "English_United States" or "en-US", see the Microsoft documentation about locale names.
PostgreSQL allows the creation of a UTF8 database with any locale on Windows (see the documentation).
By the way, the initdb option for specifying the locale is --locale and not -l.
Related
I was messing around with postgres in docker and wanted to connect to it via url URI.
If the password contains a substring that could be transformed as a character thanks to decodeURIComponent, it will be treated as well, leading to a connection fail.
Is it possible to specify some character in the uri that should not be considered as special characters to decode?
Here is an example:
%23 is automatically encoded as #
$> docker run --name test -p 5433:5432 -e POSTGRES_USER=user -e POSTGRES_DB=db -e POSTGRES_PASSWORD=secret%23 --rm -d postgres
$> psql postgres://user:secret%23#localhost:5433/db
psql: error: could not connect to server: FATAL: password authentication failed for user "user"
$> PGPASSWORD=secret%23 psql --user=user --host=localhost --port=5433 --dbname=db
psql (12.3, server 13.2 (Debian 13.2-1.pgdg100+1))
WARNING: psql major version 12, server major version 13.
Some psql features might not work.
Type "help" for help.
db=#
Working example (without a percent followed by two digits):
$> docker run --name test2 -p 5434:5432 -e POSTGRES_USER=user -e POSTGRES_DB=db -e POSTGRES_PASSWORD=secret# --rm -d postgres
$> psql postgres://user:secret%23#localhost:5434/db
psql (12.3, server 13.2 (Debian 13.2-1.pgdg100+1))
WARNING: psql major version 12, server major version 13.
Some psql features might not work.
Type "help" for help.
db=#
$> PGPASSWORD=secret# psql --user=user --host=localhost --port=5434 --dbname=db
psql (12.3, server 13.2 (Debian 13.2-1.pgdg100+1))
WARNING: psql major version 12, server major version 13.
Some psql features might not work.
Type "help" for help.
db=#
psql postgres://user:secret%23#localhost:5433/db does not work with a password set to secret%23 but does with one set to secret#.
Is it possible to use database uri with a password like secret%23?
The doc says the connection URI must be encoded, so your value of %23 must be encoded to %2523.
I am trying to set client encoding for a session. I am running the following command on linux terminal (postgresql installed on a remote server.
psql -h localhost -p 5432 -U user -d dbase -c "SET client_encoding to 'LATIN1';"
Output: SET
psql -h localhost -p 5432 -U user -d dbase -c "show client_encoding"
Output: UTF8
Why is this happening? Do I need to run this command as a superuser? (I don't think so)
If I run the following commands on Pgadmin4 then it correctly show LATIN1 as the output.
SET client_encoding to 'LATIN1'
show client_encoding
The server encoding is set to UTF8.
Setting the client encoding is only for the current session unless you set the environment variable PGCLIENTENCODING.
From postgresql documentation: If the environment variable PGCLIENTENCODING is defined in the client's environment, that client encoding is automatically selected when a connection to the server is made.
So, if you want the client encoding persist try setting this environment var.
Or if you want to execute multiple queries in just one session have a look at the -f parameter to set a file to parse.
Ex: psql -d myDataBase -f myFile
I use pg_restore on Windows 10 with a dump file made on Linux.
I search on the web but I don't find answer.
[NEW] :
I install Ubuntu on my computer to use pg_restore but when I send
pg_restore -d mydatabase /home/user/Documents/dumpfile.dump
the command line is blocked.
Someone has this issue ?
Your new ubuntu installation hasn't defined the en_US.UTF-8 locale yet. So, when you're trying to restore the dumpfile, the dumpfile attempts to do something like:
CREATE DATABASE <database> WITH TEMPLATE = ... LC_COLLATE = 'en_US.UTF-8'...
But, 'en_US.UTF-8' is not defined by your new ubuntu server. First, you can verify this:
# list all "known" locales. In my case, on new Ubuntu 20, I get:
$ locale -a
C
C.UTF-8
POSIX
Edit existing /etc/locale.gen file, which contains the list of possible locales. Most locales will be commented out. These will not be defined, so, un-comment the line with 'en_US.UTF-8'.
Run (as root) locale-gen.
root# locale-gen
Generating locales (this might take a while)...
en_US.UTF-8... done
Generation complete.
Notice it's now a configured locale:
$ locale -a
C
C.UTF-8
POSIX
en_US.utf8
(Yes, it is lower case utf8, not a problem)
Restart your postgres server (so it sees the new locale -- you do not need to restart the ubuntu server itself), and you restore show now work.
You will need to do some research on locales. The place to start is the documentation.
Postgres relies on the operating system for locale information. The names differ between Posix and Windows. Presumably, the simplest solution is to change the name somehow. There might be a way to get Windows to understand the Posix names.
While trying to install opennms :
/usr/share/opennms/bin/install -l /usr/local/lib -dis
I get the error:
ERROR: encoding UTF8 does not match locale en_US Detail: The chosen LC_CTYPE setting requires encoding LATIN1.
and I'm not sure how to proceed, as I've tried creating the DB several different ways (see below).
Full log:
==============================================================================
OpenNMS Installer
==============================================================================
Configures PostgreSQL tables, users, and other miscellaneous settings.
- searching for jicmp:
- trying to load /usr/local/lib/libjicmp.so: NO
- trying to load /usr/lib/jni/libjicmp.so: OK
- searching for jicmp6:
- trying to load /usr/local/lib/libjicmp6.so: NO
- trying to load /usr/lib/jni/libjicmp6.so: OK
- searching for jrrd:
- trying to load /usr/local/lib/libjrrd.so: NO
- trying to load /usr/lib/jni/libjrrd.so: NO
- trying to load /usr/lib/jni/libjrrd.so: NO
- trying to load /usr/lib/jvm/jdk1.6.0_34/jre/lib/amd64/server/libjrrd.so: NO
- trying to load /usr/lib/jvm/jdk1.6.0_34/jre/lib/amd64/libjrrd.so: NO
- trying to load /usr/lib/jvm/jdk1.6.0_34/jre/../lib/amd64/libjrrd.so: NO
- trying to load /libjrrd.so: NO
- trying to load /usr/share/opennms/lib/libjrrd.so: NO
- trying to load /usr/share/opennms/lib/linux64/libjrrd.so: NO
- trying to load /usr/java/packages/lib/amd64/libjrrd.so: NO
- trying to load /usr/lib64/libjrrd.so: NO
- trying to load /lib64/libjrrd.so: NO
- trying to load /lib/libjrrd.so: NO
- trying to load /usr/lib/libjrrd.so: NO
- trying to load /usr/lib/jni/libjrrd.so: NO
- trying to load /usr/lib/libjrrd.so: NO
- trying to load /usr/local/lib/libjrrd.so: NO
- trying to load /opt/NMSjicmp/lib/32/libjrrd.so: NO
- trying to load /opt/NMSjicmp/lib/64/libjrrd.so: NO
- trying to load /opt/NMSjicmp6/lib/32/libjrrd.so: NO
- trying to load /opt/NMSjicmp6/lib/64/libjrrd.so: NO
- Failed to load the optional jrrd library.
- This error is not fatal, since jrrd is only required for optional features.
- For more information, see http://www.opennms.org/index.php/jrrd
- using SQL directory... /usr/share/opennms/etc
- using create.sql... /usr/share/opennms/etc/create.sql
* using 'postgres' as the PostgreSQL user for OpenNMS
* using 'opennms' as the PostgreSQL database name for OpenNMS
Exception in thread "main" org.opennms.core.schema.MigrationException: an error occurred creating the OpenNMS database
at org.opennms.core.schema.Migrator.createDatabase(Migrator.java:428)
at org.opennms.core.schema.Migrator.prepareDatabase(Migrator.java:444)
at org.opennms.install.Installer.install(Installer.java:236)
at org.opennms.install.Installer.main(Installer.java:949)
Caused by: org.postgresql.util.PSQLException: ERROR: encoding UTF8 does not match locale en_US
Detail: The chosen LC_CTYPE setting requires encoding LATIN1.
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:374)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:366)
at org.opennms.core.schema.Migrator.createDatabase(Migrator.java:425)
... 3 more
List of databases:
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+-----------------------
postgres | postgres | LATIN1 | en_US | en_US |
rhq | rhqadmin | LATIN1 | en_US | en_US |
template0 | postgres | LATIN1 | en_US | en_US | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | LATIN1 | en_US | en_US | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
I have used the following 3 initdb options but none of them work
/usr/local/pgsql/bin/initdb -E UTF-8 --pgdata=/usr/local/pgsql/data
/usr/local/pgsql/bin/initdb -E LATIN1 --pgdata=/usr/local/pgsql/data
/usr/local/pgsql/bin/initdb -E en_US.UTF8 --pgdata=/usr/local/pgsql/data
Also, do i need to delete all data in /usr/local/pgsql/data before i use initdb ?
appending locale command stdout:
$locale
LANG=en_US
LANGUAGE=en_US:
LC_CTYPE="en_US"
LC_NUMERIC="en_US"
LC_TIME="en_US"
LC_COLLATE="en_US"
LC_MONETARY="en_US"
LC_MESSAGES="en_US"
LC_PAPER="en_US"
LC_NAME="en_US"
LC_ADDRESS="en_US"
LC_TELEPHONE="en_US"
LC_MEASUREMENT="en_US"
LC_IDENTIFICATION="en_US"
LC_ALL=
I combined two solutions from other sites that did the job (this answer works for Ubuntu server 12.04 and PGSQL 9.1):
Create a file: nano /etc/profile.d/lang.sh.
Add the following:
export LANGUAGE="en_US.UTF-8"
export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
Save the file
Restart the shell or run all export commands manually in current shell instance
Reconfigure so the encoding can be UTF8 ([got it from here][1])
sudo su postgres
psql
update pg_database set datistemplate=false where datname='template1';
drop database Template1;
create database template1 with owner=postgres encoding='UTF-8'
lc_collate='en_US.utf8' lc_ctype='en_US.utf8' template template0;
update pg_database set datistemplate=true where datname='template1';
Use template1 for db creation.
Thanks for locale output. OpenNMS seems to be using your en_US (non-UTF-8) locale in order to create postgres db, and this is wrong. This should work:
export LANG=en_US.UTF-8
locale # confirm that it shows only en_US.UTF-8 for all settings
# finally, run your opennms installer
/usr/share/opennms/bin/install -l /usr/local/lib -dis
this worked for me:
CREATE DATABASE mydb WITH ENCODING='UTF8' LC_CTYPE='en_US.UTF-8' LC_COLLATE='en_US.UTF-8' OWNER=postgres TEMPLATE=template0 CONNECTION LIMIT=-1;
This is happening because your system is setup to use Latin1 encoding instead of UTF-8. Your language is set correctly to en_US, but the encoding is not set to UTF-8. Try running this:$
localedef -v -c -i en_US -f UTF-8 en_US.UTF-8
This will set tell all of your applications that are installed after the change (i think) to use the English language with unicode encoding. More information can be found here: https://www.linux.com/learn/docs/ldp/790-Unicode-HOWTO#s3
I had a similar issue so I:
aptitude purge postresql ...
localedef -v -c -i en_US -f UTF-8 en_US.UTF-8
aptitude install postresql ....
and then postregsql knew to set itself to use the english language with unicode encoding.
Of course, you could do this on a per database basis as described here: http://www.postgresql.org/docs/9.1/static/multibyte.html
I have the same error:
ERROR: new collation (en_US.utf8) 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.
Solution:
dpkg-reconfigure locales (choose en_US.UTF-8)
then:
sudo -u postgres psql
postgres=# update pg_database set datistemplate=false where datname='template1';
UPDATE 1
postgres=# drop database Template1;
DROP DATABASE
postgres=# create database template1 with owner=postgres encoding='UTF-8'
postgres-# lc_collate='en_US.utf8' lc_ctype='en_US.utf8' template template0;
CREATE DATABASE
postgres=# update pg_database set datistemplate=true where datname='template1';
UPDATE 1
Test:
postgres=# CREATE DATABASE Person
WITH
OWNER = Person
ENCODING = 'UTF8'
LC_COLLATE = 'en_US.utf8'
LC_CTYPE = 'en_US.utf8'
TABLESPACE = pg_default
CONNECTION LIMIT = -1;
CREATE DATABASE
It works :)
Change the locales and languages of SO for compatibilty with BD.
dpkg-reconfigure locales
enjoy!
I meet the similar error. old database LC_CTYPE is UTF-8, but new one is en_US.UTF-8, I solve the problem after reinit database.
initdb --pgdata=/path/to/postgresql -E utf8
You should choice the right -E parameter
I have had the "same issue" while installing odoo. Turns out that before installing odoo you have to configure locale
export LC_CTYPE="en_US.UTF-8"
sudo dpkg-reconfigure locales
And then configuler locale with UTF-8
BUT you have to configure locale before posgres installation.
So I'm walking through the GeoDjango tutorial and I'm stuck on this error message:
postgres#lucid32:~$ createdb -E UTF8 template_postgis
createdb: database creation failed: ERROR: encoding UTF8 does not match locale en_US
DETAIL: The chosen LC_CTYPE setting requires encoding LATIN1.
I've googled and read some Ubuntu docs but to no avail. Any insight would be greatly appreciated!
I'm using the default Vagrant Box lucid 32, for testing out my setup.
It is better to just specify the locale for the database and have the encoding be figured out from that. So use something like
createdb --locale=en_US.utf8 template_postgis
Both -E UTF8 and --locale=en_US.utf8 are needed
$ createdb -E UTF8 -T template0 --locale=en_US.utf8 template_postgis
Else, try this when you log in to postgresql :
create database databse_name with owner database_owner encoding='UTF-8'lc_collate='en_US.utf8' lc_ctype='en_US.utf8' template template0;
You need to set your operating system's locale to any utf8 compatible locale. Run locale -a to get a list of locales you can use, and then do something like update-locale LANG=en_US.utf8, replacing en_US.utf8 with whatever locale you want.
look at this: https://askubuntu.com/questions/20880/unicode-in-postgresql-8-4/114922#114922
maybe you need configure the locale before to create the cluster
~#export LANGUAGE=en_US.UTF-8
~#export LANG=en_US.UTF-8
~#export LC_ALL=en_US.UTF-8
~#locale-gen en_US.UTF-8
~#dpkg-reconfigure locales