cht電腦資訊Linux
adm Find login register

postgresql on Mandriva

site admin

joined: 2007-08-09
posted: 674
promoted: 16
bookmarked: 5
Taiwan
1subject: postgresql on MandrivaPromote 1 Bookmark 02008-06-13quote  

為什麼用 postgresql不用 mysql,純粹是因為以前學過,而且它的 CLI psql 我覺得很不錯。

不過缺點是 web hosting 支援 postgresql 的很少。

Mandriva 上 postgresql 不會自動執行,因為 install 時不會 initdb

su as root

# su - postgres

以 postgres uid 執行

$ export PGDATA=/var/lib/pgsql/data

$ initdb -E UTF-8

好像不支援 big5, 反正不要自討苦吃去用 big5,去搞許功蓋的問題。

# service postgresql start

就可以了,postgresql 內定似乎不會開啟,可以在 control center 開啟。用

#chkconfig --add postgresql 也可以

如果要加入 DB 的 user 用 postgres 執行 createuser。用 createdb 建 database

psql 裏面

  • \?  用來查詢 psql 的 command
  • \h 可以直接查詢 SQL command,也支援 tab 鍵 table name completion
edited: 8
eliu

joined: 2007-08-09
posted: 11468
promoted: 617
bookmarked: 187
新竹, 台灣
2subject: Promote 0 Bookmark 02008-04-09quote  

version 8.3.x  會出現這個 error


$ initdb -E UTF-8
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 locales
  COLLATE:  en_US
  CTYPE:    zh_TW.Big5
  MESSAGES: en_US
  MONETARY: en_US
  NUMERIC:  en_US
  TIME:     en_US
initdb: encoding mismatch
The encoding you selected (UTF8) and the encoding that the
selected locale uses (BIG5) do not match.  This would lead to
misbehavior in various character string processing functions.
Rerun initdb and either do not specify an encoding explicitly,
or choose a matching combination.

這時候請在 postgres 這個 id 下

$ export LC_ALL=zh_TW.UTF-8
$ export LC_CTYPE=zh_TW.UTF-8

再 initdb -E UTF-8 就可以了

eliu

joined: 2007-08-09
posted: 11468
promoted: 617
bookmarked: 187
新竹, 台灣
3subject: Promote 0 Bookmark 02008-06-13quote  

postgresql 會檢查進去的 data 是否符合 database 的 encoding.  如果 database SQL string encoding 不合,會拒絕執行。

如果只想純粹存資料 string,不需要處理 multibyte character, 可以把

database 的 encoding 都設定成 SQL_ASCII ,這樣就不會有任何檢查與處理。

CC: SQL DB
cht電腦資訊Linux
adm Find login register
views:14042