| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

「PostgreSQL 8.3.5 インストール」の版間の差分

提供: MyMemoWiki
ナビゲーションに移動 検索に移動
(ページの作成:「==PostgreSQL 8.3.5 インストール== [PostgreSQL][PostgreSQL 8.3.5][Fedora Core] [http://www.postgresql.jp/ 日本PostgreSQLユーザ会] http://www.postgresql.jp…」)
 
 
(同じ利用者による、間の3版が非表示)
1行目: 1行目:
==PostgreSQL 8.3.5 インストール==
+
==[[PostgreSQL 8.3.5 インストール]]==
[PostgreSQL][PostgreSQL 8.3.5][Fedora Core]
+
[[PostgreSQL]] | [[PostgreSQL 8.3.5]] | [[Fedora Core]] |
  
 
[http://www.postgresql.jp/ 日本PostgreSQLユーザ会]
 
[http://www.postgresql.jp/ 日本PostgreSQLユーザ会]
 
http://www.postgresql.jp/document/pg835doc/html/installation.html
 
http://www.postgresql.jp/document/pg835doc/html/installation.html
  
PostgreSQL 8.3.5 を Fedora Core 6 にインストール
+
[[PostgreSQL 8.3.5]] を Fedora Core 6 にインストール
 
===インストール===
 
===インストール===
 
====postgresユーザーの作成====
 
====postgresユーザーの作成====
13行目: 13行目:
 
*運用は、rootユーザーではなく専用の一般ユーザーで行う
 
*運用は、rootユーザーではなく専用の一般ユーザーで行う
 
*運用するユーザーをOSに追加
 
*運用するユーザーをOSに追加
*外部へアクセスできる他のサーバデーモンと同じように、PostgreSQLを独立したユーザアカウントで実行することをお勧めします。
+
*外部へアクセスできる他のサーバデーモンと同じように、[[PostgreSQL]]を独立したユーザアカウントで実行することをお勧めします。
 
*このユーザアカウントは、サーバによって管理されるデータのみを所有するようにすべき
 
*このユーザアカウントは、サーバによって管理されるデータのみを所有するようにすべき
 
*
 
*
27行目: 27行目:
 
  $ ftp ftp.postgresql.org
 
  $ ftp ftp.postgresql.org
 
       :
 
       :
  KERBEROS_V4 rejected as an authentication type
+
  KE[[R]]BE[[R]]OS_V4 rejected as an authentication type
 
  Name (ftp.postgresql.org:root): anonymous
 
  Name (ftp.postgresql.org:root): anonymous
 
  Password:[メールアドレス]
 
  Password:[メールアドレス]
 
       :
 
       :
  ftp> bin
+
  ftp> bin
  ftp> cd /pub/v8.3.5/
+
  ftp> cd /pub/v8.3.5/
  ftp> get postgresql-8.3.5.tar.gz
+
  ftp> get postgresql-8.3.5.tar.gz
 
=====展開=====
 
=====展開=====
 
  $ gunzip postgresql-8.3.5.tar.gz
 
  $ gunzip postgresql-8.3.5.tar.gz
40行目: 40行目:
 
パラメータ
 
パラメータ
 
http://www.postgresql.jp/document/pg835doc/html/install-procedure.html
 
http://www.postgresql.jp/document/pg835doc/html/install-procedure.html
ちょいと興味があるので、PL/Python とやらも構成しておく
+
ちょいと興味があるので、PL/[[Python]] とやらも構成しておく
 
  $ cd postgresql-8.3.5
 
  $ cd postgresql-8.3.5
 
  $ ./configure --with-python
 
  $ ./configure --with-python
55行目: 55行目:
 
|-
 
|-
 
|readline
 
|readline
|文字列入力用ライブラリ。入力プロンプトでタブ補完や入力ヒストリを参照できたり、emacsライクあるいはviライクなキー操作が可能となる
+
|文字列入力用ライブラリ。入力プロンプトでタブ補完や入力ヒストリを参照できたり、emacsライクあるいは[[vi]]ライクなキー操作が可能となる
 
|-
 
|-
 
|ncurses
 
|ncurses
61行目: 61行目:
 
|-
 
|-
 
|zlib
 
|zlib
|Zip や gzip に使われている圧縮アルゴリズムをライブラリ化したもの
+
|Zip や gzip に使われている圧縮[[アルゴリズム]]をライブラリ化したもの
 
|-
 
|-
 
|}
 
|}
72行目: 72行目:
 
     :
 
     :
 
  Name (ftp.gnu.org:root): anonymous
 
  Name (ftp.gnu.org:root): anonymous
  ftp> cd /gnu/readline
+
  ftp> cd /gnu/readline
  ftp> get readline-5.2.tar.gz
+
  ftp> get readline-5.2.tar.gz
  
 
  # gunzip readline-5.2.tar.gz  
 
  # gunzip readline-5.2.tar.gz  
92行目: 92行目:
 
config.log
 
config.log
 
   :
 
   :
  dit -lcurses -lcrypt -ldl -lm  >&5
+
  dit -lcurses -lcrypt -ldl -lm  >&5
 
  /usr/bin/ld: cannot find -ledit
 
  /usr/bin/ld: cannot find -ledit
 
  collect2: ld returned 1 exit status
 
  collect2: ld returned 1 exit status
106行目: 106行目:
 
     :
 
     :
 
  Name (ftp.gnu.org:root): anonymous
 
  Name (ftp.gnu.org:root): anonymous
  ftp> cd /gnu/ncureses
+
  ftp> cd /gnu/ncureses
  ftp> get ncurses-5.7.tar.gz
+
  ftp> get ncurses-5.7.tar.gz
  
 
  # cd ncurses-5.7
 
  # cd ncurses-5.7
150行目: 150行目:
  
 
  if [ $?LD_LIBRARY_PATH ]then
 
  if [ $?LD_LIBRARY_PATH ]then
   LD_LIBRARY_PATH=/usr/local/pgsql/lib:$LD_LIBRARY_PATH
+
   LD_LIB[[R]]A[[R]]Y_PATH=/usr/local/pgsql/lib:$LD_LIB[[R]]A[[R]]Y_PATH
 
  else         
 
  else         
   LD_LIBRARY_PATH=/usr/local/pgsql/lib
+
   LD_LIB[[R]]A[[R]]Y_PATH=/usr/local/pgsql/lib
 
  fi
 
  fi
  export LD_LIBRARY_PATH
+
  export LD_LIB[[R]]A[[R]]Y_PATH
 
  PATH=/usr/local/pgsql/bin:$PATH
 
  PATH=/usr/local/pgsql/bin:$PATH
 
  export PATH
 
  export PATH
163行目: 163行目:
 
====データベース格納領域を初期化====
 
====データベース格納領域を初期化====
 
*ディスク上にデータベース格納領域を初期化する必要があります。
 
*ディスク上にデータベース格納領域を初期化する必要があります。
*格納領域をデータベースクラスタと呼びます(SQLではカタログクラスタという用語が使用されます)。
+
*格納領域をデータベースクラスタと呼びます([[SQL]]ではカタログクラスタという用語が使用されます)。
 
*データベースクラスタはデータベースの集合
 
*データベースクラスタはデータベースの集合
 
*稼働しているデータベースサーバのただ1つのインスタンスを通して管理
 
*稼働しているデータベースサーバのただ1つのインスタンスを通して管理
186行目: 186行目:
 
===ログの設定===
 
===ログの設定===
 
http://www.postgresql.jp/document/current/html/logfile-maintenance.html
 
http://www.postgresql.jp/document/current/html/logfile-maintenance.html
====PostgreSQLのログ設定====
+
====[[PostgreSQL]]のログ設定====
  
 
/usr/local/pgsql/data/postgres.conf を編集
 
/usr/local/pgsql/data/postgres.conf を編集
196行目: 196行目:
  
 
=====何を出力するか=====
 
=====何を出力するか=====
http://www.postgresql.jp/document/current/html/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHAT
+
http://www.postgresql.jp/document/current/html/runtime-config-logging.html#[[R]]UNTIME-CONFIG-LOGGING-WHAT
  
 
以下あたりを有効にしてみる
 
以下あたりを有効にしてみる
210行目: 210行目:
 
|-
 
|-
 
|log_statement (文字列)
 
|log_statement (文字列)
|どのSQL文をログに記録するかを制御します。有効な値は、none、ddl、mod、およびallで
+
|どの[[SQL]]文をログに記録するかを制御します。有効な値は、none、ddl、mod、およびallで
 
|-
 
|-
 
|}
 
|}
230行目: 230行目:
  
 
=====/var/log/postgresにログ出力=====
 
=====/var/log/postgresにログ出力=====
  # vi /etc/syslog.conf
+
  # [[vi]] /etc/syslog.conf
  
  # PostgreSQL log
+
  # [[PostgreSQL]] log
 
  local0.*    -/var/log/postgres
 
  local0.*    -/var/log/postgres
  
244行目: 244行目:
  
 
=====syslog 再起動=====
 
=====syslog 再起動=====
  # /sbin/service syslog restart
+
  # /sbin/ser[[vi]]ce syslog restart
  
  
  
 
===データベースの作成===
 
===データベースの作成===
*データベースを作成する場合、PostgreSQLサーバが起動している必要がある
+
*データベースを作成する場合、[[PostgreSQL]]サーバが起動している必要がある
 
*[http://www.postgresql.jp/document/current/html/sql-createdatabase.html SQLコマンド]から、
 
*[http://www.postgresql.jp/document/current/html/sql-createdatabase.html SQLコマンド]から、
 
*データベースを作成できるが、利便性のため、シェルから[http://www.postgresql.jp/document/current/html/app-createdb.html createdb]を実行しても作成できる。
 
*データベースを作成できるが、利便性のため、シェルから[http://www.postgresql.jp/document/current/html/app-createdb.html createdb]を実行しても作成できる。
258行目: 258行目:
 
http://www.postgresql.jp/document/current/html/tutorial-accessdb.html
 
http://www.postgresql.jp/document/current/html/tutorial-accessdb.html
 
以下によってアクセス可能
 
以下によってアクセス可能
*psqlというPostgreSQL対話式端末プログラムを実行
+
*psqlという[[PostgreSQL]]対話式端末プログラムを実行
*データベースの作成や操作をサポートする[PostgreSQL pgAdminのインストール] [pgAdmin]やODBCを備えたオフィススイートなどの既存のグラフィカルなフロントエンドツールを使用
+
*データベースの作成や操作をサポートする[[PostgreSQL pgAdminのインストール|pgAdmin]]やODBCを備えたオフィススイートなどの既存のグラフィカルなフロントエンドツールを使用
*複数の使用可能言語の1つを使用した、独自のアプリケーションの作成
+
*複数の使用可能[[言語]]の1つを使用した、独自のアプリケーションの作成
  
 
psql を試す
 
psql を試す
  
 
  $ psql testdb
 
  $ psql testdb
  Welcome to psql 8.3.5, the PostgreSQL interactive terminal.
+
  Welcome to psql 8.3.5, the [[PostgreSQL]] interactive terminal.
 
   
 
   
 
  Type:  \copyright for distribution terms
 
  Type:  \copyright for distribution terms
         \h for help with SQL commands
+
         \h for help with [[SQL]] commands
 
         \? for help with psql commands
 
         \? for help with psql commands
 
         \g or terminate with semicolon to execute query
 
         \g or terminate with semicolon to execute query
 
         \q to quit
 
         \q to quit
  
testdb=#となっているのは、スーパーユーザーであるため。スーパーユーザーでない場合、tetdb=>となる。
+
testdb=#となっているのは、スーパーユーザーであるため。スーパーユーザーでない場合、tetdb=>となる。
 
以下のコマンドを試す
 
以下のコマンドを試す
 
  testdb=# SELECT version();
 
  testdb=# SELECT version();
 
                                               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)
+
   [[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)
 
  (1 row)
  
 
====クライアントからの接続設定====
 
====クライアントからの接続設定====
*[PostgreSQL pgAdminのインストール] [こちら]を参照
+
*[[PostgreSQL pgAdminのインストール|こちら]]を参照

2020年2月16日 (日) 04:30時点における最新版

PostgreSQL 8.3.5 インストール

PostgreSQL | PostgreSQL 8.3.5 | Fedora Core |

日本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つのライブラリのインストールが必要

ライブラリ 内容
readline 文字列入力用ライブラリ。入力プロンプトでタブ補完や入力ヒストリを参照できたり、emacsライクあるいはviライクなキー操作が可能となる
ncurses 端末に依存しない形式でテキストユーザインタフェース(TUI)を作成するためのAPIを提供するライブラリ
zlib Zip や gzip に使われている圧縮アルゴリズムをライブラリ化したもの
readline ライブラリのインストール

とのこと。

# 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:
  :

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 オプションは不要
  • 他のオプションはこちらを参照
$ 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

以下あたりを有効にしてみる

パラメータ 内容
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サーバが起動している必要がある
  • SQLコマンドから、
  • データベースを作成できるが、利便性のため、シェルからcreatedbを実行しても作成できる。
  • 削除はdropdbにて可能
$ createdb testdb

データベースへのアクセス

http://www.postgresql.jp/document/current/html/tutorial-accessdb.html 以下によってアクセス可能

  • psqlというPostgreSQL対話式端末プログラムを実行
  • データベースの作成や操作をサポートする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)

クライアントからの接続設定