読者です 読者をやめる 読者になる 読者になる

本当は怖い情報科学

情報系大学院生の趣味&実益ブログ。

Postgresqlをインストールしてみた

メモ

Mac環境でPostgresをローカルにインストールしてみたのでメモ。参考文献[1]の通りにやるだけ。ありがとうございます。価値無いけどログがてら残しておく。

とりあえず突っ込む

$ sudo port install postgresql93
 $ sudo port install postgresql93
Password:
--->  Computing dependencies for postgresql93
--->  Dependencies to be installed: postgresql_select
--->  Fetching archive for postgresql_select
--->  Attempting to fetch postgresql_select-0.2_0.darwin_13.noarch.tbz2 from http://lil.fr.packages.macports.org/postgresql_select
--->  Attempting to fetch postgresql_select-0.2_0.darwin_13.noarch.tbz2.rmd160 from http://lil.fr.packages.macports.org/postgresql_select
--->  Installing postgresql_select @0.2_0
--->  Activating postgresql_select @0.2_0
--->  Cleaning postgresql_select
--->  Fetching archive for postgresql93
--->  Attempting to fetch postgresql93-9.3.4_0.darwin_13.x86_64.tbz2 from http://lil.fr.packages.macports.org/postgresql93
--->  Attempting to fetch postgresql93-9.3.4_0.darwin_13.x86_64.tbz2.rmd160 from http://lil.fr.packages.macports.org/postgresql93
--->  Installing postgresql93 @9.3.4_0

To use the postgresql server, install the postgresql93-server port
--->  Activating postgresql93 @9.3.4_0
--->  Cleaning postgresql93
--->  Updating database of binaries: 100.0%
--->  Scanning binaries for linking errors: 100.0%
--->  No broken files found.

 $ sudo port install postgresql93-server
--->  Computing dependencies for postgresql93-server
--->  Fetching archive for postgresql93-server
--->  Attempting to fetch postgresql93-server-9.3.4_0.darwin_13.x86_64.tbz2 from http://lil.fr.packages.macports.org/postgresql93-server
--->  Attempting to fetch postgresql93-server-9.3.4_0.darwin_13.x86_64.tbz2.rmd160 from http://lil.fr.packages.macports.org/postgresql93-server
--->  Installing postgresql93-server @9.3.4_0
--->  Activating postgresql93-server @9.3.4_0

To create a database instance, after install do
 sudo mkdir -p /opt/local/var/db/postgresql93/defaultdb
 sudo chown postgres:postgres /opt/local/var/db/postgresql93/defaultdb
 sudo su postgres -c '/opt/local/lib/postgresql93/bin/initdb -D /opt/local/var/db/postgresql93/defaultdb' 

--->  Cleaning postgresql93-server
--->  Updating database of binaries: 100.0%
--->  Scanning binaries for linking errors: 100.0%
--->  No broken files found.
$ sudo port select postgresql  postgresql93

デフォルトのDBを作成

$ sudo mkdir -p /opt/local/var/db/postgresql93/defaultdb
$ sudo chown postgres:postgres /opt/local/var/db/postgresql93/defaultdb
$ sudo su postgres -c '/opt/local/lib/postgresql93/bin/initdb -D /opt/local/var/db/postgresql93/defaultdb'

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 locales
  COLLATE:  ja_JP.utf-8
  CTYPE:    en_US.UTF-8
  MESSAGES: ja_JP.utf-8
  MONETARY: ja_JP.utf-8
  NUMERIC:  ja_JP.utf-8
  TIME:     ja_JP.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 /opt/local/var/db/postgresql93/defaultdb ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
creating configuration files ... ok
creating template1 database in /opt/local/var/db/postgresql93/defaultdb/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:

    /opt/local/lib/postgresql93/bin/postgres -D /opt/local/var/db/postgresql93/defaultdb
or
    /opt/local/lib/postgresql93/bin/pg_ctl -D /opt/local/var/db/postgresql93/defaultdb -l logfile start

サーバーの起動と停止

# 起動
$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql93-server.plist
$ sudo launchctl start org.macports.postgresql93-server

# 停止
$ sudo launchctl stop org.macports.postgresql93-server


参考文献:
[1] http://astj.hatenablog.com/entry/2013/09/22/163940

【広告】