#navi(../)
* PostgreSQL9.1をUbuntuにインストール [#g0e157df]
Ubuntu12.04にPostgreSQLをインストールした時の備忘録です。~
尚、PostgreSQLはapt-getコマンドを使用してパッケージをインストールしました。

#contents
#htmlinsertpcsp(db-top.html,db-sp.html)

* PostgreSQLパッケージを検索 [#ycfaef3e]
apt-cacheコマンドでPostgreSQLのパッケージを検索しました。~
検索した時の出力は以下の通りです。~
PostgreSQL8.4, PostgreSQL9.1のパッケージが検索されたので、PostgreSQL9.1をインストールすることにします。
 sakura@ubuntu:~$ apt-cache search postgresql | grep ^postgresql
 postgresql - object-relational SQL database (supported version)
 postgresql-9.1 - object-relational SQL database, version 9.1 server
 postgresql-9.1-dbg - debug symbols for postgresql-9.1
 postgresql-client - front-end programs for PostgreSQL (supported version)
 postgresql-client-9.1 - front-end programs for PostgreSQL 9.1
 <snip>
 postgresql-8.4 - object-relational SQL database, version 8.4 server
 postgresql-client-8.4 - front-end programs for PostgreSQL 8.4
 postgresql-client-common - manager for multiple PostgreSQL client versions
 postgresql-common - PostgreSQL データベースクラスタマネージャ
 postgresql-contrib-8.4 - additional facilities for PostgreSQL
 postgresql-doc-8.4 - documentation for the PostgreSQL database management system
 postgresql-server-dev-8.4 - development files for PostgreSQL 8.4 server-side programming
 <snip>

* PostgreSQL9.1のインストール [#afb2e898]
以下のコマンドでPostgresQL9.1のインストールを行います。
 sudo apt-get install -y postgresql-9.1
上記コマンドを実行した結果です。
 sakura@ubuntu:~$ sudo apt-get install -y postgresql-9.1
 [sudo] password for sakura:
 パッケージリストを読み込んでいます... 完了
 依存関係ツリーを作成しています
 状態情報を読み取っています... 完了
 以下の特別パッケージがインストールされます:
   libpq5 postgresql-client-9.1 postgresql-client-common postgresql-common ssl-cert
 提案パッケージ:
   oidentd ident-server locales-all postgresql-doc-9.1 openssl-blacklist
 以下のパッケージが新たにインストールされます:
   libpq5 postgresql-9.1 postgresql-client-9.1 postgresql-client-common postgresql-common ssl-cert
 アップグレード: 0 個、新規インストール: 6 個、削除: 0 個、保留: 0 個。
 5,512 kB のアーカイブを取得する必要があります。
 この操作後に追加で 15.7 MB のディスク容量が消費されます。
 
 <snip>
 
 * Starting PostgreSQL 9.1 database server                                                             [ OK ]
 libc-bin のトリガを処理しています ...
 ldconfig deferred processing now taking place

* PostgreSQLを使ってみる [#j57e6a80]
インストール後、/etc/passwdを確認するとpostgresユーザが追加されています。~
以下のコマンドでpostgresユーザにスイッチし、操作してみます。
 sudo -i -u postgres

上記コマンドでpostgresユーザにスイッチし、psqlコマンドを実行したときの出力です。
 postgres@ubuntu:~$ psql
 psql (9.1.10)
 Type "help" for help.
 
 postgres=#

バージョンを表示するSELECT文を実行したときの出力結果です。
 postgres=# select version();
                                                version
 ------------------------------------------------------------------------------------------------------
  PostgreSQL 9.1.10 on i686-pc-linux-gnu, compiled by gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3, 32-bit
 (1 row)

PostgreSQLのシェルを終了します。
 postgres=# \q
 postgres@ubuntu:~$

以上、PostgreSQLのインストール後、PostgreSQLに接続し簡単なSQLを実行した時の操作でした。

** postgresユーザにパスワードを設定する [#cecc39c2]
上記では、sudo -i -u postgresコマンドでpostgresユーザにスイッチしました。~
suコマンドでpostgresユーザにスイッチするには、postgresユーザのパスワードを設定する必要があります。(パスワード未設定のため)~
以下のコマンドでpostgresユーザにパスワードを設定することにより、su postgresができるようになります。
 sudo passwd postgres
 
以上、UbuntuにPostgreSQL9.1のパッケージをインストールした記事でした。

#htmlinsertpcsp(db-btm.html,db-sp.html)

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS