VPSならラピッドサイト:ホーム > カスタマーサポート > オンラインマニュアル > RV-7シリーズ マニュアル > リファレンスマニュアル > PostgreSQL > 01) PostgreSQL 7
01) PostgreSQL 7
搭載状況
RV-7シリーズではご契約時期によりPostgreSQLの搭載状況が異なります。2008年2月12日以前のご契約: 全プランに標準搭載(RV-721、RV-722、RV-723、RV-731、RV-732、RV-733)
2008年2月13日以降のご契約: 最上位プランにのみ標準搭載(RV-723、RV-733、RV-753)
以下のコマンドで、ご利用サーバーのPostgreSQLの状態を確認する事が可能です。
# /sbin/chkconfig --list | grep postgresql 上記コマンドの実行結果は以下になります。 停止状態の場合の実行結果(PostgreSQL非搭載) postgresql 0:off 1:off 2:off 3:off 4:off 5:off 6:off 起動状態の場合の実行結果(PostgreSQL搭載済み) postgresql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
PostgreSQLのインストール
PostgreSQLが搭載されていないサーバーや、標準搭載されているPostgreSQLをアンインストールした場合には、vinstallコマンドでインストールしてご利用いただけます。PostgreSQLのインストール
vinstallコマンドでPostgreSQLのインストールが可能です。インストールの前に必ず「vuninstallコマンド」を実行し、PostgreSQLをいったんアンインストールしてください。
# vuninstall postgresql7
以下、実行例です。
# vuninstall postgresql7 <Enter>
uninstalling postgresql Failed to stop postgres! removing old database(s) Old database files removed successfully! warning: /etc/httpd/conf.d/auth_pgsql.conf saved as /etc/httpd/conf.d/auth_pgsql.conf.rpmsave vuninstall done
アンインストールを行わずにvinstallコマンドでインストールした場合、不要な設定が残り、PostgreSQLの起動が正常に確認できない可能性がありますのでご注意ください。
次に、以下のコマンドでインストールをします。
# vinstall postgresql7
以下、インストールのログになります。
# vinstall postgresql7 <Enter>
installing postgresql
Installing postgresql via yum
Setting up Install Process
Setting up repositories
rhn 100% |=========================| 951 B 00:00
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for mod_auth_pgsql to pack into transaction set.
mod_auth_pgsql-2.0.1-7.1. 100% |=========================| 5.1 kB 00:00
---> Package mod_auth_pgsql.i386 0:2.0.1-7.1 set to be updated
---> Downloading header for postgresql-libs to pack into transaction set.
postgresql-libs-7.4.19-1. 100% |=========================| 12 kB 00:00
---> Package postgresql-libs.i386 0:7.4.19-1.el4_6.1 set to be updated
---> Downloading header for postgresql-server to pack into transaction set.
postgresql-server-7.4.19- 100% |=========================| 23 kB 00:00
---> Package postgresql-server.i386 0:7.4.19-1.el4_6.1 set to be updated
---> Downloading header for postgresql-devel to pack into transaction set.
postgresql-devel-7.4.19-1 100% |=========================| 49 kB 00:00
---> Package postgresql-devel.i386 0:7.4.19-1.el4_6.1 set to be updated
---> Downloading header for perl-DBD-Pg to pack into transaction set.
perl-DBD-Pg-2.2.2-1.el4.r 100% |=========================| 4.4 kB 00:00
---> Package perl-DBD-Pg.i386 0:2.2.2-1.el4.rf set to be updated
---> Downloading header for postgresql to pack into transaction set.
postgresql-7.4.19-1.el4_6 100% |=========================| 104 kB 00:00
---> Package postgresql.i386 0:7.4.19-1.el4_6.1 set to be updated
--> Running transaction check
Dependencies Resolved
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
mod_auth_pgsql i386 2.0.1-7.1 verio 21 k
perl-DBD-Pg i386 2.2.2-1.el4.rf verio 264 k
postgresql i386 7.4.19-1.el4_6.1 verio 2.0 M
postgresql-devel i386 7.4.19-1.el4_6.1 verio 1.0 M
postgresql-libs i386 7.4.19-1.el4_6.1 verio 148 k
postgresql-server i386 7.4.19-1.el4_6.1 verio 3.0 M
Transaction Summary
=============================================================================
Install 6 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 6.5 M
Downloading Packages:
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: postgresql-libs ######################### [1/6]
Installing: postgresql ######################### [2/6]
Installing: mod_auth_pgsql ######################### [3/6]
Installing: postgresql-server ######################### [4/6]
Installing: postgresql-devel ######################### [5/6]
Installing: perl-DBD-Pg ######################### [6/6]
Installed: mod_auth_pgsql.i386 0:2.0.1-7.1 perl-DBD-Pg.i386 0:2.2.2-1.el4.rf
postgresql.i386 0:7.4.19-1.el4_6.1 postgresql-devel.i386 0:7.4.19-1.el4_6.1
postgresql-libs.i386 0:7.4.19-1.el4_6.1 postgresql-server.i386 0:7.4.19-1.el4_6.1
Complete!
Starting postgresql service: [ OK ]
man pages for postgres are available; please read them carefully
to learn how to use postgres. The man pages may be accessed
by typing:
--Multi User
% man postmaster
-- Single User
% man postgres
There are also man pages for individual commands that are
too numerious to list.
The version installed is: 7.4.13
The Online manuals for this product are on the postgres homepage
which is located at:
http://www.postgresql.org/docs/7.4/interactive/index.html
The homepage itself is located at:
http://www.postgresql.org/
vinstall done
セキュリティ設定
上記インストール作業だけでは、ログインパスワードのセキュリティ設定が行われていない状態の為、以下の作業を必ず行って下さい。※以下の作業はsuコマンドでrootユーザに変更後行って下さい。
パスワードの設定
PostgreSQL管理者の「postgres」ユーザーでPostgreSQLにログインし、パスワードを設定します。# su postgres <Enter>
↑PostgreSQL管理者ユーザーに変更します。
$ psql template1 <Enter>
↑PostgreSQLにログインします。
Welcome to psql 7.4.19, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit
template1=#
↑ログインが完了すると、以上のように表示されます。
PostgreSQLにログイン完了後、以下のコマンドを実行して下さい。
template1=# alter user postgres with password 'パスワード'; <Enter>
↑上記コマンドで、PostgreSQLの管理者ユーザー「postgres」にパスワードを設定します。
パスワード部分に、設定したいバスワードを置き換えて実行して下さい。
ALTER ROLE
template1=# \q <Enter>
↑PostgreSQLをログアウトします。
次に、PostgreSQLの設定ファイルで、パスワード利用を有効にする設定を行います。
以下、二つのファイルの編集を行って下さい。
pg_hba.confの編集
/var/lib/pgsql/data/pg_hba.conf
上記ファイルの一番最後の行を、以下のように変更して下さい。【変更前】 local all all ident sameuser 【変更後】 local all all md5
postgresql.confの編集
/var/lib/pgsql/data/postgresql.conf
上記ファイルの中の1カ所を、以下のように変更して下さい。
#password_encryption = true
↓に変更。行頭の「#」マークを削除します。
password_encryption = true
変更後は、必ず以下のPostgreSQL再起動コマンドを実行して下さい。↓に変更。行頭の「#」マークを削除します。
password_encryption = true
# /etc/init.d/postgresql restart
バージョン確認
[root@linux ~]# psql -V
psql (PostgreSQL) 7.4.13
contains support for command-line editing
psql (PostgreSQL) 7.4.13
contains support for command-line editing
設定ファイル
設置ディレクトリ
/var/lib/pgsql/data
ファイル一覧
-rw------- 1 postgres postgres 4 Apr 21 19:00 PG_VERSION
-rw------- 1 postgres postgres 3386 Apr 21 19:00 pg_hba.conf
-rw------- 1 postgres postgres 1441 Apr 21 19:00 pg_ident.conf
-rw------- 1 postgres postgres 7842 Apr 21 19:00 postgresql.conf
-rw------- 1 postgres postgres 59 May 24 15:42 postmaster.opts
-rw------- 1 postgres postgres 46 May 24 15:42 postmaster.pid
-rw------- 1 postgres postgres 3386 Apr 21 19:00 pg_hba.conf
-rw------- 1 postgres postgres 1441 Apr 21 19:00 pg_ident.conf
-rw------- 1 postgres postgres 7842 Apr 21 19:00 postgresql.conf
-rw------- 1 postgres postgres 59 May 24 15:42 postmaster.opts
-rw------- 1 postgres postgres 46 May 24 15:42 postmaster.pid
起動スクリプト
引数一覧
| start | 起動 |
|---|---|
| stop | 停止 |
| status | ステータス確認 |
| restart | 再起動 |
| condrestart | 起動確認後に再起動 |
実行例
[root@linux ~]# /etc/init.d/postgresql stop
Stopping postgresql service: [ OK ]
[root@linux ~]# /etc/init.d/postgresql start
Starting postgresql service: [ OK ]
[root@linux ~]# /etc/init.d/postgresql status
postmaster (pid 29939 29938 29933) is running...
[root@linux ~]# /etc/init.d/postgresql condrestart
Stopping postgresql service: [ OK ]
Starting postgresql service: [ OK ]
Stopping postgresql service: [ OK ]
[root@linux ~]# /etc/init.d/postgresql start
Starting postgresql service: [ OK ]
[root@linux ~]# /etc/init.d/postgresql status
postmaster (pid 29939 29938 29933) is running...
[root@linux ~]# /etc/init.d/postgresql condrestart
Stopping postgresql service: [ OK ]
Starting postgresql service: [ OK ]
データベース操作
ユーザー追加
[root@linux ~]# su postgres
$ createuser -W
Enter name of user to add: PGUSER
Shall the new user be allowed to create databases? (y/n) n
Shall the new user be allowed to create more new users? (y/n) n
Password: ********
CREATE USER
$ createuser -W
Enter name of user to add: PGUSER
Shall the new user be allowed to create databases? (y/n) n
Shall the new user be allowed to create more new users? (y/n) n
Password: ********
CREATE USER
ユーザー削除
$ dropuser PGUSER
DROP USER
DROP USER
データベース作成
$ createdb PGDATA
CREATE DATABASE
CREATE DATABASE
データベース削除
$ dropdb PGDATA
DROP DATABASE
DROP DATABASE
データベースバックアップ
$ pg_dump -Fc -b PGDATA > pgdata.dump
データベース復元
$ pg_restore -d PGDATA pgdata.dump
phpPgAdminのURL
http://DOMAIN-NAME.COM/phppgadmin/
phpPgAdminはコマンドを使用せずWEBインターフェイスからPostgreSQLの操作を可能とします。
phpPgAdminはコマンドを使用せずWEBインターフェイスからPostgreSQLの操作を可能とします。
