「PostgreSQL」カテゴリーアーカイブ

PostgreSQL8.3でEUC_JPのデータベースを作成する

PostgreSQL8.3(Mac OSX、MacPortsでインストール)でEUC_JPのデータベースを作成しようとしたら、以下のようにエラーになった。

$ createdb -U postgres -E EUC_JP dbname
createdb: database creation failed: ERROR:  encoding EUC_JP does not match server's locale ja_JP.UTF-8
DETAIL:  The server's LC_CTYPE setting requires encoding UTF8.

以下のようにオプションに --encoding=UTF8 --no-locale をつけてinitdbしなおしたら、作成できるようになった。

$ sudo rm -rf /opt/local/var/db/postgresql83/defaultdb
$ sudo mkdir -p /opt/local/var/db/postgresql83/defaultdb
$ sudo chown postgres:postgres /opt/local/var/db/postgresql83/defaultdb
$ sudo su postgres -c '/opt/local/lib/postgresql83/bin/initdb -D /opt/local/var/db/postgresql83/defaultdb --encoding=UTF8 --no-locale'
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 C.
The default text search configuration will be set to "english".
fixing permissions on existing directory /opt/local/var/db/postgresql83/defaultdb ... ok
creating subdirectories ... ok
selecting default max_connections ... 20
selecting default shared_buffers/max_fsm_pages ... 1600kB/20000
creating configuration files ... ok
creating template1 database in /opt/local/var/db/postgresql83/defaultdb/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:
    /opt/local/lib/postgresql83/bin/postgres -D /opt/local/var/db/postgresql83/defaultdb
or
    /opt/local/lib/postgresql83/bin/pg_ctl -D /opt/local/var/db/postgresql83/defaultdb -l logfile start

LeopardにmacportsでPostgreSQL8.2をインストール

$ sudo port install postgresql82
--->  Fetching postgresql82
--->  Attempting to fetch postgresql-8.2.9.tar.bz2 from http://ftp8.us.postgresql.org/postgresql/source/v8.2.9
--->  Attempting to fetch postgresql-8.2.9.tar.bz2 from http://ftp9.us.postgresql.org/pub/mirrors/postgresql/source/v8.2.9
--->  Verifying checksum(s) for postgresql82
--->  Extracting postgresql82
--->  Configuring postgresql82
--->  Building postgresql82
--->  Staging postgresql82 into destroot
--->  Installing postgresql82 8.2.9_0
To use the postgresql server, install the postgresql82-server port
--->  Activating postgresql82 8.2.9_0
--->  Cleaning postgresql82
$ sudo port install postgresql82-server
Password:
--->  Fetching postgresql82-server
--->  Verifying checksum(s) for postgresql82-server
--->  Extracting postgresql82-server
--->  Configuring postgresql82-server
--->  Building postgresql82-server with target all
--->  Staging postgresql82-server into destroot
--->  Creating launchd control script
###########################################################
# A startup item has been generated that will aid in
# starting postgresql82-server with launchd. It is disabled
# by default. Execute the following command to start it,
# and to cause it to launch at startup:
#
# sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql82-server.plist
###########################################################
--->  Installing postgresql82-server 8.2.9_0
To create a database instance, after install do
 sudo mkdir -p /opt/local/var/db/postgresql82/defaultdb
 sudo chown postgres:postgres /opt/local/var/db/postgresql82/defaultdb
 sudo su postgres -c '/opt/local/lib/postgresql82/bin/initdb -D /opt/local/var/db/postgresql82/defaultdb'
To tweak your DBMS, consider increasing kern.sysv.shmmax by adding an increased kern.sysv.shmmax .. to /etc/sysctl.conf
--->  Activating postgresql82-server 8.2.9_0
--->  Cleaning postgresql82-server
$ sudo mkdir -p /opt/local/var/db/postgresql82/defaultdb
$ sudo chown postgres:postgres /opt/local/var/db/postgresql82/defaultdb
$ sudo su postgres -c '/opt/local/lib/postgresql82/bin/initdb -D /opt/local/var/db/postgresql82/defaultdb'
Password:
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 ja_JP.UTF-8.
The default database encoding has accordingly been set to UTF8.
fixing permissions on existing directory /opt/local/var/db/postgresql82/defaultdb ... ok
creating subdirectories ... ok
selecting default max_connections ... 30
selecting default shared_buffers/max_fsm_pages ... 2400kB/20000
creating configuration files ... ok
creating template1 database in /opt/local/var/db/postgresql82/defaultdb/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating conversions ... 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:
    /opt/local/lib/postgresql82/bin/postgres -D /opt/local/var/db/postgresql82/defaultdb
or
    /opt/local/lib/postgresql82/bin/pg_ctl -D /opt/local/var/db/postgresql82/defaultdb -l logfile start

LeopardにmacportsでPostgreSQL8.3をインストール

postgresql83をインストール。

$ sudo port install postgresql83
Password:
--->  Fetching bison
--->  Attempting to fetch bison-2.3.tar.bz2 from http://ftp.gnu.org/gnu/bison
--->  Verifying checksum(s) for bison
--->  Extracting bison
--->  Configuring bison
--->  Building bison with target all
--->  Staging bison into destroot
--->  Installing bison 2.3_2
--->  Activating bison 2.3_2
--->  Cleaning bison
--->  Fetching libxslt
--->  Attempting to fetch libxslt-1.1.23.tar.gz from ftp://xmlsoft.org/libxslt/
--->  Verifying checksum(s) for libxslt
--->  Extracting libxslt
--->  Configuring libxslt
--->  Building libxslt with target all
--->  Staging libxslt into destroot
--->  Installing libxslt 1.1.23_0
--->  Activating libxslt 1.1.23_0
--->  Cleaning libxslt
--->  Fetching ossp-uuid
--->  Attempting to fetch uuid-1.6.1.tar.gz from ftp://ftp.ossp.org/pkg/lib/uuid/
--->  Verifying checksum(s) for ossp-uuid
--->  Extracting ossp-uuid
--->  Applying patches to ossp-uuid
--->  Configuring ossp-uuid
--->  Building ossp-uuid with target all
--->  Staging ossp-uuid into destroot
--->  Installing ossp-uuid 1.6.1_0
--->  Activating ossp-uuid 1.6.1_0
--->  Cleaning ossp-uuid
--->  Fetching postgresql83
--->  Attempting to fetch postgresql-8.3.3.tar.bz2 from http://ftp8.de.postgresql.org/pub/misc/pgsql//source/v8.3.3/
--->  Verifying checksum(s) for postgresql83
--->  Extracting postgresql83
--->  Configuring postgresql83
--->  Building postgresql83
--->  Staging postgresql83 into destroot
--->  Installing postgresql83 8.3.3_0
To use the postgresql server, install the postgresql83-server port
--->  Activating postgresql83 8.3.3_0
--->  Cleaning postgresql83

メッセージにある通り、postgresql83-serverをインストール。

$ sudo port install postgresql83-server
Password:
--->  Fetching postgresql83-server
--->  Verifying checksum(s) for postgresql83-server
--->  Extracting postgresql83-server
--->  Configuring postgresql83-server
--->  Building postgresql83-server with target all
--->  Staging postgresql83-server into destroot
--->  Creating launchd control script
###########################################################
# A startup item has been generated that will aid in
# starting postgresql83-server with launchd. It is disabled
# by default. Execute the following command to start it,
# and to cause it to launch at startup:
#
# sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql83-server.plist
###########################################################
--->  Installing postgresql83-server 8.3.3_0
To create a database instance, after install do
 sudo mkdir -p /opt/local/var/db/postgresql83/defaultdb
 sudo chown postgres:postgres /opt/local/var/db/postgresql83/defaultdb
 sudo su postgres -c '/opt/local/lib/postgresql83/bin/initdb -D /opt/local/var/db/postgresql83/defaultdb'
To tweak your DBMS, consider increasing kern.sysv.shmmax by adding an increased kern.sysv.shmmax .. to /etc/sysctl.conf
--->  Activating postgresql83-server 8.3.3_0
--->  Cleaning postgresql83-server

メッセージにある通り、自動起動を設定して、データベースを作成。

$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql83-server.plist
$ sudo mkdir -p /opt/local/var/db/postgresql83/defaultdb
$ sudo chown postgres:postgres /opt/local/var/db/postgresql83/defaultdb
$ sudo su postgres -c '/opt/local/lib/postgresql83/bin/initdb -D /opt/local/var/db/postgresql83/defaultdb'
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 ja_JP.UTF-8.
The default database encoding has accordingly been set to UTF8.
initdb: could not find suitable text search configuration for locale ja_JP.UTF-8
The default text search configuration will be set to "simple".
fixing permissions on existing directory /opt/local/var/db/postgresql83/defaultdb ... ok
creating subdirectories ... ok
selecting default max_connections ... 20
selecting default shared_buffers/max_fsm_pages ... 2400kB/20000
creating configuration files ... ok
creating template1 database in /opt/local/var/db/postgresql83/defaultdb/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:
    /opt/local/lib/postgresql83/bin/postgres -D /opt/local/var/db/postgresql83/defaultdb
or
    /opt/local/lib/postgresql83/bin/pg_ctl -D /opt/local/var/db/postgresql83/defaultdb -l logfile start