■PostgreSQLインスト`ル
[root@linux ~]# yum -y install postgresql-server
←
postgresql-serverインスト`ル
Setting up Install Process
Setting up Repo: crash-hat
repomd.xml 100% |=========================| 951 B 00:00
Setting up Repo: base
repomd.xml 100% |=========================| 1.1 kB 00:00
Setting up Repo: updates-released
repomd.xml 100% |=========================| 951 B 00:00
Reading repository metadata in from local files
crash-hat : ################################################## 75/75
base : ################################################## 2622/2622
updates-re: ################################################## 669/669
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for postgresql-server to pack into transaction set.
postgresql-server-7.4.7-1 100% |=========================| 21 kB 00:00
---> Package postgresql-server.i386 0:7.4.7-1.FC3.2 set to be installed
--> Running transaction check
Dependencies Resolved
Transaction Listing:
Install: postgresql-server.i386 0:7.4.7-1.FC3.2
Downloading Packages:
postgresql-server-7.4.7-1 100% |=========================| 3.0 MB 00:04
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: postgresql-server 100 % done 1/1
Installed: postgresql-server.i386 0:7.4.7-1.FC3.2
Complete!
[root@linux ~]# yum clean packages ← ダウンロ`ドしたパッケ`ジを削除
Cleaning up Packages
1 packages removed
■PostgreSQL起
[root@linux ~]# /etc/rc.d/init.d/postgresql start
← PostgreSQL起
デ`タベ`スを初期化中: [ OK ]
postgresql サ`ビスを_始中: [ OK ]
[root@linux ~]# chkconfig postgresql on ← PostgreSQL自悠釉O定
[root@linux ~]# chkconfig --list postgresql ← PostgreSQL自悠釉O定_J
postgresql 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← ランレベル2~5のonを_J
■PostgreSQLO定
(1)PostgreSQL管理ユ`ザ(postgres)パスワ`ドO定
※PostgreSQL管理ユ`ザ(postgres)はPostgreSQLのインスト`ルにより作成されている
【システム上のpostgresユ`ザにパスワ`ドをO定】
[root@linux ~]# passwd postgres ← システム上のpostgresユ`ザにパスワ`ドO定
Changing password for user postgres.
New password: ← パスワ`ド答※表示はされない
Retype new password: ← パスワ`ド答(_J)※表示はされない
passwd: all authentication tokens updated successfully.
【PostgreSQL上のpostgresユ`ザにパスワ`ドをO定】
[root@linux ~]# su - postgres ← postgresユ`ザになる
-bash-3.00$ psql template1 ← psqlコマンドでPostgreSQLに接A
Welcome to psql 7.4.2, 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=# alter user postgres with password 'パスワ`ド'; ← PostgreSQL上のpostgresユ`ザにパスワ`ドO定
ALTER USER ← パスワ`ドが涓丹欷
template1=# \q ← psqlコマンドK了
-bash-3.00$ exit ← rootユ`ザに
(2)PostgreSQLO定
[root@linux ~]# su - postgres
← postgresユ`ザになる
-bash-3.00$ vi /var/lib/pgsql/data/postgresql.conf ← PostgreSQLO定ファイル
#
# Connection Parameters
#
#tcpip_socket = false
tcpip_socket = true ← 追加(TCP/IPU由でのデ`タベ`ス接AS可)
-bash-3.00$ vi /var/lib/pgsql/data/pg_hba.conf ← PostgreSQLJ^O定ファイル
以下を最K行へ追加
local all all trust ← 追加(ロ`カルからのアクセスはo条件にS可)
host all all 192.168.1.1 255.255.255.255 trust ← 追加(内部からのアクセスはo条件にS可)
host all all 0.0.0.0 0.0.0.0 password crypt ← 追加(上以外からのアクセスはパスワ`ドJ^によりS可)
-bash-3.00$ exit ← rootユ`ザに
[root@linux ~]# /etc/rc.d/init.d/postgresql restart ← PostgreSQL再起
postgresql サ`ビスを停止中: [ OK ]
postgresql サ`ビスを_始中: [ OK ]
■PostgreSQL_J
(1)PostgreSQLユ`ザ追加
※例としてユ`ザ名をcentosとする
[root@linux ~]# su - postgres
← postgresユ`ザになる
-bash-3.00$ createuser -AdPE centos ← PostgreSQLにcentosユ`ザを追加(システムに登hgのユ`ザであること)
Enter password for new user: ← パスワ`ド答※表示はされない
Enter it again: ← パスワ`ド答(_J)※表示はされない
CREATE USER
-bash-3.00$ exit ← rootユ`ザに
以降は一般ユ`ザ(ここではcentosとする)で行う
(2)デ`タベ`ス作成
[root@linux ~]# su - centos
← centosユ`ザになる
[centos@linux ~]$ createdb --encoding EUC_JP test ← デ`タベ`スtestを作成
CREATE DATABASE
[centos@linux ~]$ psql -l ← デ`タベ`ス作成_J
List of databases
Name | Owner | Encoding
-----------+-----------+-----------
template0 | postgres | SQL_ASCII
template1 | postgres | SQL_ASCII
test | centos | EUC_JP ← デ`タベ`スtestが作成されている
(3 rows)
(2)psqlツ`ル起
コマンドラインでPostgreSQLデ`タベ`スを操作するツ`ルを起婴工
[centos@linux ~]$ psql test
← psqlツ`ル起
Welcome to psql 7.4.1, 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
test=>
(3)テ`ブル作成
test=> create table test(num int, name varchar(50));
← テ`ブルtestを作成
CREATE TABLE
test=> \d test ← テ`ブルtest作成_J
Table "public.test"
Column | Type | Modifiers
--------+-----------------------+-----------
num | integer |
name | character varying(50) |
(4)デ`タ登h
test=> insert into test values(1,'山田太郎');
← テ`ブルtestにデ`タを登h
INSERT
(5)デ`タ照会
test=> select * from test;
← テ`ブルtestのデ`タを照会
num | name
-----+-----------
1 | 山田太郎
(1 row)
(6)テ`ブル削除
test=> drop table test;
← テ`ブルtestを削除
DROP TABLE
(7)psqlツ`ル停止
test=> \q
← psqlツ`ル停止
(8)デ`タベ`ス削除
[centos@linux ~]$ dropdb test
← デ`タベ`スtestを削除
DROP DATABASE
[centos@linux ~]$ exit ← rootユ`ザに
(9)PostgreSQLユ`ザ削除
[root@linux ~]# su - postgres
← postgresユ`ザになる
-bash-3.00$ dropuser centos ← PostgreSQLからcentosユ`ザ削除
DROP USER
-bash-3.00$ exit ← rootユ`ザに