Symfoware

Symfowareについての考察blog

FreeBSD 10.0にPostgreSQL 9.3.2をインストール(pkg install使用)

FreeBSD 10.0にPostgreSQL 9.3.2をインストールした時の手順をメモしておきます。

すっかり忘れていたので、過去行った手順を参考にしました。
FreeBSD 9.0にPostgresql9.1をインストール





pkg install




pkg installでインストールします。
コマンドは「pkg install postgresql93-server」

処理内容は、こんな感じになりました。


# pkg install postgresql93-server
Updating repository catalogue
The following 4 packages will be installed:

    Installing libxml2: 2.8.0_3
    Installing gettext: 0.18.3.1
    Installing postgresql93-client: 9.3.2
    Installing postgresql93-server: 9.3.2

The installation will require 40 MB more space

8 MB to be downloaded

Proceed with installing packages [y/N]: y
libxml2-2.8.0_3.txz                 100% 781KB 260.2KB/s 280.7KB/s 00:03    
gettext-0.18.3.1.txz                100% 2077KB 415.4KB/s 456.9KB/s 00:05    
postgresql93-client-9.3.2.txz     100% 1966KB 393.3KB/s 346.4KB/s 00:05    
postgresql93-server-9.3.2.txz     100% 3186KB 354.0KB/s 156.2KB/s 00:09    
Checking integrity... done
[1/4] Installing libxml2-2.8.0_3... done
[2/4] Installing gettext-0.18.3.1... done
[3/4] Installing postgresql93-client-9.3.2... done
[4/4] Installing postgresql93-server-9.3.2...===> Creating users and/or groups.
Creating group 'pgsql' with gid '70'.
Creating user 'pgsql' with uid '70'.

=========== BACKUP YOUR DATA! =============
As always, backup your data before
upgrading. If the upgrade leads to a higher
minor revision (e.g. 8.3.x -> 8.4), a dump
and restore of all databases is
required. This is *NOT* done by the port!

Press ctrl-C *now* if you need to pg_dump.
===========================================
done
The PostgreSQL port has a collection of "side orders":

postgresql-docs
For all of the html documentation

p5-Pg
A perl5 API for client access to PostgreSQL databases.

postgresql-tcltk
If you want tcl/tk client support.

postgresql-jdbc
For Java JDBC support.

postgresql-odbc
For client access from unix applications using ODBC as access
method. Not needed to access unix PostgreSQL servers from Win32
using ODBC. See below.

ruby-postgres, py-PyGreSQL
For client access to PostgreSQL databases using the ruby & python
languages.

postgresql-plperl, postgresql-pltcl & postgresql-plruby
For using perl5, tcl & ruby as procedural languages.

postgresql-contrib
Lots of contributed utilities, postgresql functions and
datatypes. There you find pg_standby, pgcrypto and many other cool
things.

etc...
For procedural languages and postgresql functions, please note that
you might have to update them when updating the server.

If you have many tables and many clients running, consider raising
kern.maxfiles using sysctl(8), or reconfigure your kernel
appropriately.

The port is set up to use autovacuum for new databases, but you might
also want to vacuum and perhaps backup your database regularly. There
is a periodic script, /usr/local/etc/periodic/daily/502.pgsql, that
you may find useful. You can use it to backup and perfom vacuum on all
databases nightly. Per default, it perfoms `vacuum analyze'. See the
script for instructions. For autovacuum settings, please review
~pgsql/data/postgresql.conf.

If you plan to access your PostgreSQL server using ODBC, please
consider running the SQL script /usr/local/share/postgresql/odbc.sql
to get the functions required for ODBC compliance.

Please note that if you use the rc script,
/usr/local/etc/rc.d/postgresql, to initialize the database, unicode
(UTF-8) will be used to store character data by default. Set
postgresql_initdb_flags or use login.conf settings described below to
alter this behaviour. See the start rc script for more info.

To set limits, environment stuff like locale and collation and other
things, you can set up a class in /etc/login.conf before initializing
the database. Add something similar to this to /etc/login.conf:
---
postgres:\
    :lang=en_US.UTF-8:\
    :setenv=LC_COLLATE=C:\
    :tc=default:
---
and run `cap_mkdb /etc/login.conf'.
Then add 'postgresql_class="postgres"' to /etc/rc.conf.

======================================================================

To initialize the database, run

/usr/local/etc/rc.d/postgresql initdb

You can then start PostgreSQL by running:

/usr/local/etc/rc.d/postgresql start

For postmaster settings, see ~pgsql/data/postgresql.conf

NB. FreeBSD's PostgreSQL port logs to syslog by default
    See ~pgsql/data/postgresql.conf for more info

======================================================================

To run PostgreSQL at startup, add
'postgresql_enable="YES"' to /etc/rc.conf






起動を許可するため、/etc/rc.confに一行追加します。


# vi /etc/rc.conf




「postgresql_enable="YES"」を追加。


keymap="jp.106.kbd"
ifconfig_em0="inet 192.168.1.102 netmask 255.255.255.0"
defaultrouter="192.168.1.1"
sshd_enable="YES"
postgresql_enable="YES"

# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
dumpdev="AUTO"






続いて、データベースの初期化を行います。
コマンドは「/usr/local/etc/rc.d/postgresql initdb」


# /usr/local/etc/rc.d/postgresql initdb
The files belonging to this database system will be owned by user "pgsql".
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".

Data page checksums are disabled.

creating 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/bin/postgres -D /usr/local/pgsql/data
or
    /usr/local/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start




これで初期化完了です。
PostgreSQLを起動します。


/usr/local/etc/rc.d/postgresql start
LOG: ending log output to stderr
HINT: Future log output will go to log destination "syslog".







接続確認



pkg installによるインストール時に「pgsql」というユーザーが自動的に作成されます。
データベースの操作はこのユーザーで行います。

ユーザーを「pgsql」に切り替え。


# su - pgsql
$




psqlコマンドでデータベースに接続します。
管理データベース「postgres」を指定して接続。


$ psql postgres
psql (9.3.2)
Type "help" for help.

postgres=#




ちゃんと接続出来ました。
「\l」で、データベースの一覧が表示できます。


postgres=# \l
                             List of databases
Name    | Owner | Encoding | Collate |    Ctype    | Access privileges
-----------+-------+----------+-------------+-------------+-------------------
postgres | pgsql | UTF8     | C         | C         |
template0 | pgsql | UTF8     | C         | C         | =c/pgsql         +
         |     |         |             |             | pgsql=CTc/pgsql
template1 | pgsql | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 |
(3 rows)





対話画面を終了するには「\q」


postgres=# \q
$









データベースの作成



createdbコマンドで作成します。
文字コードUTF8、collate(文字列の並び換え順)はja_JP.UTF-8、ctype(文字の分類)もja_JP.UTF-8を
指定し、「sample」というデータベースを作成してみます。
※コマンドを実行するユーザーは「pgsql」です。


$ createdb -E UTF8 --lc-collate=ja_JP.UTF-8 --lc-ctype=ja_JP.UTF-8 sample




ちゃんとできたか確認してみます。


$ psql sample
psql (9.3.2)
Type "help" for help.

sample=# \l
                             List of databases
Name    | Owner | Encoding | Collate |    Ctype    | Access privileges
-----------+-------+----------+-------------+-------------+-------------------
postgres | pgsql | UTF8     | C         | C         |
sample    | pgsql | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 |
template0 | pgsql | UTF8     | C         | C         | =c/pgsql         +
         |     |         |             |             | pgsql=CTc/pgsql
template1 | pgsql | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 |
(4 rows)


関連記事

テーマ:データベース - ジャンル:コンピュータ

  1. 2014/01/29(水) 00:06:56|
  2. PostgreSQL
  3. | トラックバック:0
  4. | コメント:0
  5. | 編集
次のページ