PostgreSQL インストール2015/01/15 |
| データベースサーバーに PostgreSQL をインストールします。 |
|
[root@www ~]#
yum -y install postgresql-server
[root@www ~]#
vi /var/lib/pgsql/data/postgresql.conf # 49行目:コメント解除し変更 ( 他ホストからのアクセスも受け付ける ) listen_addresses = ' * '
# 300行目:コメント解除し変更 ( ログの形式を [日時 ユーザ DB ~]とする ) log_line_prefix = ' %t %u %d '
[root@www ~]#
[root@www ~]# /etc/rc.d/init.d/postgresql start Initializing database: [ OK ] Starting postgresql service: [ OK ]
[root@www ~]#
chkconfig postgresql on su - postgres # postgres ユーザーに遷移 # 「postgres」ユーザーのDBパスワード設定 -bash-3.2$ psql -c "alter user postgres with password 'password'" ALTER ROLE -bash-3.2$ createuser cent # DBユーザー「cent」を作成 Shall the new role be a superuser? (y/n) y # DBの管理者権限を与える CREATE ROLE -bash-3.2$ su - cent # Linux 上の「cent」ユーザーに遷移 Password: [cent@www ~]$ createdb testdb # テストDB作成 CREATE DATABASE [cent@www ~]$ psql -l # 確認
List of databases
Name | Owner | Encoding
-----------+----------+----------
postgres | postgres | UTF8
template0 | postgres | UTF8
template1 | postgres | UTF8
testdb | cent | UTF8
(4 rows)
[cent@www ~]$ psql testdb # テストDBに接続
Welcome to psql 8.1.23, 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=# alter user cent with password 'password'; ALTER ROLE # テストテーブル作成 testdb=# create table test ( no int,name text ); CREATE TABLE # テストデータ挿入 testdb=# insert into test (no,name) values (1,'cent'); INSERT 0 1 # 確認 testdb=# select * from test;
no | name ----+------- 1 | cent (1 row) # テストテーブル削除 testdb=# drop table test; DROP TABLE # 終了 testdb=# \q dropdb testdb # テストDB削除
|
| Sponsored Link |
|
|