[Linux]CentOS6.3にPostgreSQL9.2を導入します

書いてなかったんだと、いまさらびっくし。。

手順概要
1.リポジトリの追加
2.yumでインストール
3.初期化
4.start
5.chkconfigセット
6.ユーザーの作成
7.データベースの作成
————————————–

1.リポジトリの追加
#rpm -Uvh http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-centos92-9.2-6.noarch.rpm
Retrieving http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-centos92-9.2-6.noarch.rpm
warning: /var/tmp/rpm-tmp.H34RI8: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Preparing… ########################################### [100%]
1:pgdg-centos92 ########################################### [100%]

2.yumでインストール
#yum install postgresql92 postgresql92-server postgresql92-devel postgresql92-libs postgresql92-contrib


========================================================================================
 Package                             Arch      Version            Repository   Size
========================================================================================
Installing:
 postgresql92                        x86_64    9.2.3-2PGDG.rhel6  pgdg92       968 k
 postgresql92-contrib                x86_64    9.2.3-2PGDG.rhel6  pgdg92       435 k
 postgresql92-devel                  x86_64    9.2.3-2PGDG.rhel6  pgdg92       1.4 M
 postgresql92-libs                   x86_64    9.2.3-2PGDG.rhel6  pgdg92       185 k
 postgresql92-server                 x86_64    9.2.3-2PGDG.rhel6  pgdg92       3.8 M
Installing for dependencies:
 libxslt                             x86_64    1.1.26-2.el6_3.1   base         452 k
 uuid                                x86_64    1.6.1-10.el6       base         54 k

Transaction Summary
========================================================================================
Install       7 Package(s)

3.初期化
# su postgres
$/usr/pgsql-9.2/bin/initdb -E UTF-8 –no-locale -D /var/lib/pgsql/9.2/data
The files belonging to this database system will be owned by user “postgres”.
This user must also own the server process.

The database cluster will be initialized with locale “C”.
The default text search configuration will be set to “english”.

fixing permissions on existing directory /var/lib/pgsql/9.2/data … ok
creating subdirectories … ok
selecting default max_connections … 100
selecting default shared_buffers … 32MB
creating configuration files … ok
creating template1 database in /var/lib/pgsql/9.2/data/base/1 … ok
initializing pg_authid … ok
initializing dependencies … ok
creating system views … ok
loading system objects’ descriptions … ok
creating collations … ok
creating conversions … ok
creating dictionaries … ok
setting privileges on built-in objects … ok
creating information schema … ok
loading PL/pgSQL server-side language … ok
vacuuming database template1 … ok
copying template1 to template0 … ok
copying template1 to postgres … ok

WARNING: enabling “trust” authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
–auth-local and –auth-host, the next time you run initdb.

Success. You can now start the database server using:

/usr/pgsql-9.2/bin/postgres -D /var/lib/pgsql/9.2/data
or
/usr/pgsql-9.2/bin/pg_ctl -D /var/lib/pgsql/9.2/data -l logfile start

4.start
#service postgresql-9.2 start

5.checkconfigセット
#chkconfig postgresql-9.2 on

6.ユーザーの作成
# su postgres

・スーパーユーザー(DB管理者/DBの作成を行う)
postgresを使っています。
作るとしたら。。。。
$ createuser -Ps hogeuser
Enter password for new role:
Enter it again:
$ psql -c ‘\du’


                             List of roles
 Role name |                   Attributes                   | Member of
-----------+------------------------------------------------+-----------
 hogeuser  | Superuser, Create role, Create DB              | {}
 postgres  | Superuser, Create role, Create DB, Replication | {}

・一般ユーザー(WebAPP接続用ユーザー)
$ createuser -P webuser
Enter password for new role:
Enter it again:
$ psql -c ‘\du’


                            List of roles
 Role name |                   Attributes                   | Member of
-----------+------------------------------------------------+-----------
 postgres  | Superuser, Create role, Create DB, Replication | {}
 webuser   |                                                | {}

7.データベースの作成
$ createdb -O webuser hogedb
$ psql -c ‘\l’


                             List of databases
   Name    |  Owner   | Encoding | Collate | Ctype |   Access privileges
-----------+----------+----------+---------+-------+-----------------------
 hogedb    | webuser  | UTF8     | C       | C     |
 postgres  | postgres | UTF8     | C       | C     |
 template0 | postgres | UTF8     | C       | C     | =c/postgres          +
           |          |          |         |       | postgres=CTc/postgres
 template1 | postgres | UTF8     | C       | C     | =c/postgres          +
           |          |          |         |       | postgres=CTc/postgres
(4 rows)

Follow me!

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です