10,639 バイト追加
、 2020年2月15日 (土) 07:34
==PostgreSQL 8.3.5 インストール==
[PostgreSQL][PostgreSQL 8.3.5][Fedora Core]
[http://www.postgresql.jp/ 日本PostgreSQLユーザ会]
http://www.postgresql.jp/document/pg835doc/html/installation.html
PostgreSQL 8.3.5 を Fedora Core 6 にインストール
===インストール===
====postgresユーザーの作成====
http://www.postgresql.jp/document/current/html/postgres-user.html
*セキュリティ上の理由からサーバプロセスをrootユーザーで起動できない
*運用は、rootユーザーではなく専用の一般ユーザーで行う
*運用するユーザーをOSに追加
*外部へアクセスできる他のサーバデーモンと同じように、PostgreSQLを独立したユーザアカウントで実行することをお勧めします。
*このユーザアカウントは、サーバによって管理されるデータのみを所有するようにすべき
*
# useradd postgres
# passwd postgres
postgres ユーザになる
# su postgres
====ソースの入手====
=====入手=====
ftp://ftp.postgresql.org/pub/v8.3.5/postgresql-8.3.5.tar.gz
$ ftp ftp.postgresql.org
:
KERBEROS_V4 rejected as an authentication type
Name (ftp.postgresql.org:root): anonymous
Password:[メールアドレス]
:
ftp> bin
ftp> cd /pub/v8.3.5/
ftp> get postgresql-8.3.5.tar.gz
=====展開=====
$ gunzip postgresql-8.3.5.tar.gz
$ tar xvf postgresql-8.3.5.tar
====構成====
パラメータ
http://www.postgresql.jp/document/pg835doc/html/install-procedure.html
ちょいと興味があるので、PL/Python とやらも構成しておく
$ cd postgresql-8.3.5
$ ./configure --with-python
:
configure: error: readline library not found
エラーになった。[readline http://typea-mixi01.appspot.com/yh_s?q=readline+library]がないとのこと。
====エラー対応====
結論から言うと、以下の3つのライブラリのインストールが必要
{|class="wikitable"
!ライブラリ
!内容
|-
|readline
|文字列入力用ライブラリ。入力プロンプトでタブ補完や入力ヒストリを参照できたり、emacsライクあるいはviライクなキー操作が可能となる
|-
|ncurses
|端末に依存しない形式でテキストユーザインタフェース(TUI)を作成するためのAPIを提供するライブラリ
|-
|zlib
|Zip や gzip に使われている圧縮アルゴリズムをライブラリ化したもの
|-
|}
=====readline ライブラリのインストール=====
*[http://www.postgresql.jp/document/pg835doc/html/install-requirements.html GNUパッケージの入手が必要な場合、近くのGNUミラーサイトから探してください](ミラーサイトの一覧はhttp://www.gnu.org/order/ftp.htmlにあります)。または、ftp://ftp.gnu.org/gnu/から探してください。
とのこと。
# ftp ftp.gnu.org
:
Name (ftp.gnu.org:root): anonymous
ftp> cd /gnu/readline
ftp> get readline-5.2.tar.gz
# gunzip readline-5.2.tar.gz
# tar xvf readline-5.2.tar
# cd readline-5.2
# ./configure
# make
# make install
=====再度configure=====
まだエラー。
config.logのfailureを見ろと。ディレクトリが見つからないのではないかと。readlineのサポートをはずすこともできるよとも。
configure: error: readline library not found
If you have readline already installed, see config.log for details on the
failure. It is possible the compiler isn't looking in the proper directory.
Use --without-readline to disable readline support.
config.log
:
dit -lcurses -lcrypt -ldl -lm >&5
/usr/bin/ld: cannot find -ledit
collect2: ld returned 1 exit status
configure:6738: $? = 1
configure: failed program was:
:
[http://typea-mixi01.appspot.com/yh_s?q=Ncurses+%E3%83%A9%E3%82%A4%E3%83%96%E3%83%A9%E3%83%AA%E3%81%8C%E8%B6%B3%E3%82%8A%E3%81%AA%E3%81%84 Ncurses ライブラリが足りない]模様
=====ncursesのインストール=====
# ftp ftp.gnu.org
:
Name (ftp.gnu.org:root): anonymous
ftp> cd /gnu/ncureses
ftp> get ncurses-5.7.tar.gz
# cd ncurses-5.7
# ./configure --with-shared --with-normal
# make
# make install
=====再再度configure=====
またまたエラー
configure: error: zlib library not found
If you have zlib already installed, see config.log for details on the
failure. It is possible the compiler isn't looking in the proper directory.
Use --without-zlib to disable zlib support.
http://honana.com/library/zlib.html
http://www.zlib.net/
# wget -P [ダウンロード先ディレクトリ] http://www.zlib.net/zlib-1.2.3.tar.gz
# gunzip zlib-1.2.3.tar.gz
# tar xvf zlib-1.2.3.tar
# cd zlib-1.2.3
# ./configure
# make
# make install
=====キャッシュを最新化=====
# ldconfig
=====構成 ~ インストール=====
ルートで、インストールディレクトリ(デフォルト)を作成
# mkdir /usr/local/pgsql
# chown postgres:postgres /usr/local/pgsql
# su postgres
$ cd postgres-8.3.5
$ ./configure --with-python
$ make
$ make install
====設定作業====
/etc/bashrc の末尾に以下を追記
if [ $?LD_LIBRARY_PATH ]then
LD_LIBRARY_PATH=/usr/local/pgsql/lib:$LD_LIBRARY_PATH
else
LD_LIBRARY_PATH=/usr/local/pgsql/lib
fi
export LD_LIBRARY_PATH
PATH=/usr/local/pgsql/bin:$PATH
export PATH
export PGDATA=/usr/local/pgsql/data
===データベースクラスタの作成===
http://www.postgresql.jp/document/current/html/creating-cluster.html
====データベース格納領域を初期化====
*ディスク上にデータベース格納領域を初期化する必要があります。
*格納領域をデータベースクラスタと呼びます(SQLではカタログクラスタという用語が使用されます)。
*データベースクラスタはデータベースの集合
*稼働しているデータベースサーバのただ1つのインスタンスを通して管理
*ファイルシステムの観点から見ると、データベースクラスタというのは、全てのデータが格納される1つのディレクトリ
$ initdb --encoding=UTF8
上記で、PGDATA環境変数を設定しているため、-D オプションをつけていない。
つける場合、$ initdb -D /usr/local/pgsql/data とする
====デフォルトの文字セット====
デフォルトの文字セット符号化方式も設定。データベース作成時に上書き可能
http://www.postgresql.jp/document/current/html/multibyte.html
====データベースサーバの起動====
http://www.postgresql.jp/document/current/html/server-start.html
*以下でデータベースサーバを起動できる
*PGDATA環境変数を指定している場合、-D オプションは不要
*他のオプションは[http://www.postgresql.jp/document/current/html/runtime-config.html こちら]を参照
$ postgres -D /usr/local/pgsql/data
*シェル構文は長くなりがちのため、pg_ctlラッパプログラムが提供されていて、いくつかのタスクを単純化している。
===ログの設定===
http://www.postgresql.jp/document/current/html/logfile-maintenance.html
====PostgreSQLのログ設定====
/usr/local/pgsql/data/postgres.conf を編集
=====以下の設定によりログ出力=====
log_destination = 'syslog'
syslog_facility = 'LOCAL0'
syslog_ident = 'postgres'
=====何を出力するか=====
http://www.postgresql.jp/document/current/html/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHAT
以下あたりを有効にしてみる
{|class="wikitable"
!パラメータ
!内容
|-
|log_connections(boolean)
|クライアント認証の成功終了などのサーバへの接続試行がログに残ります
|-
|log_duration(boolean)
|すべての完了した文について、その経過時間をログする
|-
|log_statement (文字列)
|どのSQL文をログに記録するかを制御します。有効な値は、none、ddl、mod、およびallで
|-
|}
/usr/local/pgsql/data/postgres.conf を編集
log_connections = on
log_duration = on
log_statement = 'all'
====syslogの設定====
local0 - local7 までが、ローカル使用用に予約されている。
manを確認
man -a syslog
=====/var/log/postgresにログ出力=====
# vi /etc/syslog.conf
# PostgreSQL log
local0.* -/var/log/postgres
=====/var/log/messages への出力を抑制=====
local0.none を追記
# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
#2008.11.30
#*.info;mail.none;authpriv.none;cron.none /var/log/messages
*.info;mail.none;authpriv.none;cron.none;local0.none /var/log/messages
=====syslog 再起動=====
# /sbin/service syslog restart
===データベースの作成===
*データベースを作成する場合、PostgreSQLサーバが起動している必要がある
*[http://www.postgresql.jp/document/current/html/sql-createdatabase.html SQLコマンド]から、
*データベースを作成できるが、利便性のため、シェルから[http://www.postgresql.jp/document/current/html/app-createdb.html createdb]を実行しても作成できる。
*削除はdropdbにて可能
$ createdb testdb
===データベースへのアクセス===
http://www.postgresql.jp/document/current/html/tutorial-accessdb.html
以下によってアクセス可能
*psqlというPostgreSQL対話式端末プログラムを実行
*データベースの作成や操作をサポートする[PostgreSQL pgAdminのインストール] [pgAdmin]やODBCを備えたオフィススイートなどの既存のグラフィカルなフロントエンドツールを使用
*複数の使用可能言語の1つを使用した、独自のアプリケーションの作成
psql を試す
$ psql testdb
Welcome to psql 8.3.5, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
testdb=#となっているのは、スーパーユーザーであるため。スーパーユーザーでない場合、tetdb=>となる。
以下のコマンドを試す
testdb=# SELECT version();
version
----------------------------------------------------------------------------------------------------
PostgreSQL 8.3.5 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 4.1.2 20070626 (Red Hat 4.1.2-13)
(1 row)
====クライアントからの接続設定====
*[PostgreSQL pgAdminのインストール] [こちら]を参照