CentOSにPostgreSQLをインストールする
公開日:
:
最終更新日:2014/01/28
SQL
記事内に広告を含む場合があります。記事内で紹介する商品を購入することで、当サイトに売り上げの一部が還元されることがあります。
Postgresをインストール
$ yum list | grep postgresql-server
postgresql-server.i386 8.1.11-1.el5_1.1 installed
$ sudo yum install postgresql-server
PostgreSQL起動
$ sudo /etc/rc.d/init.d/postgresql start
データベースを初期化中: [ OK ]
postgresql サービスを開始中: [ OK ]
$ sudo /sbin/chkconfig postgresql on
$ /sbin/chkconfig --list postgresql
postgresql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
PostgreSQL管理ユーザ(postgres)パスワード設定
$ sudo passwd postgres
$ su - postgres
$ psql template1
template1=# alter user postgres with password 'パスワード';
template1=# \q
$ exit
PostgreSQL設定
$ su - postgres
$ vi /var/lib/pgsql/data/pg_hba.conf
データベース作成
$ su - postgres
$ createdb --encoding UTF-8 test
CREATE DATABASE
$ psql -l
List of databases
Name | Owner | Encoding
-----------+----------+----------
postgres | postgres | UTF8
template0 | postgres | UTF8
template1 | postgres | UTF8
test | postgres | UTF8
(4 rows)
psqlツール起動
-bash-3.1$ psql test
Welcome to psql 8.1.11, 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
テーブル作成
test=# create table test(num int, name varchar(50));
CREATE TABLE
test=# \d test
Table "public.test"
Column | Type | Modifiers
--------+-----------------------+-----------
num | integer |
name | character varying(50) |
データ登録
test=# insert into test values(1,'akio0911');
INSERT 0 1
データ照会
test=# select * from test;
num | name
-----+----------
1 | akio0911
(1 row)
テーブル削除
test=# drop table test;
DROP TABLE
psqlツール停止
test=# \q
データベース削除
-bash-3.1$ dropdb test
DROP DATABASE
関連記事
- PREV
- psqlでNULLを(null)と表示する
- NEXT
- アクセスログ解析の教科書