ドルヲタ系インフラエンジニア じーふーの備忘録

クラウドをメインに扱うインフラエンジニアが書くメモやら雑感、たまにドルヲタ的活動記録残します。最近の推しはAzureのData Factory(V2)です。

【postgresql】 データベースクラスタの作成

環境

CentOS 6.5(64bit) PostgreSQL 9.3.5

そもそもPostgreSQLの"データベースクラスタ"とは??

1つのデータベースインスタンスが管理するデータベースの集合体。
複数冗長化されたデータベースを一つのデータベースに仮想的に見せる、と言ったような意味で使われるクラスタとは意味が少し異なります。

マニュアル

postgres$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
       The "-D" option specifies the location where the data will be
       stored. You can use any path you want, it does not have to be under
       the installation directory. Just make sure that the server account
       can write to the directory (or create it, if it doesn't already
       exist) before starting "initdb", as illustrated here.
    3. At this point, if you did not use the "initdb" -A option, you might
       want to modify "pg_hba.conf" to control local access to the server
       before you start it. The default is to trust all local users.
    4. The previous "initdb" step should have told you how to start up the
       database server. Do so now. The command should look something like:
/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
       This will start the server in the foreground. To put the server in
       the background use something like:
nohup /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data \
    </dev/null >>server.log 2>&1 </dev/null &
       To stop a server running in the background you can type:
kill `cat /usr/local/pgsql/data/postmaster.pid`

コマンド

$ $PGHOME/bin/initdb -D [データベースクラスタ作成先]

実行ログ

[postgres@vagrant-centos65 ~]$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/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 "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
creating configuration files ... ok
creating template1 database in /usr/local/pgsql/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
syncing data to disk ... 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/local/pgsql/bin/postgres -D /usr/local/pgsql/data/
or
    /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data/ -l logfile start

[postgres@vagrant-centos65 ~]$

データベースクラスタ構成

[postgres@vagrant-centos65 ~]$ ll /usr/local/pgsql/data/
total 92
drwx------ 5 postgres postgres  4096 May  1 08:59 base
drwx------ 2 postgres postgres  4096 May  1 08:59 global
drwx------ 2 postgres postgres  4096 May  1 08:59 pg_clog
-rw------- 1 postgres postgres  4476 May  1 08:59 pg_hba.conf
-rw------- 1 postgres postgres  1636 May  1 08:59 pg_ident.conf
drwx------ 4 postgres postgres  4096 May  1 08:59 pg_multixact
drwx------ 2 postgres postgres  4096 May  1 08:59 pg_notify
drwx------ 2 postgres postgres  4096 May  1 08:59 pg_serial
drwx------ 2 postgres postgres  4096 May  1 08:59 pg_snapshots
drwx------ 2 postgres postgres  4096 May  1 08:59 pg_stat
drwx------ 2 postgres postgres  4096 May  1 08:59 pg_stat_tmp
drwx------ 2 postgres postgres  4096 May  1 08:59 pg_subtrans
drwx------ 2 postgres postgres  4096 May  1 08:59 pg_tblspc
drwx------ 2 postgres postgres  4096 May  1 08:59 pg_twophase
-rw------- 1 postgres postgres     4 May  1 08:59 PG_VERSION
drwx------ 3 postgres postgres  4096 May  1 08:59 pg_xlog
-rw------- 1 postgres postgres 20547 May  1 08:59 postgresql.conf