PostgreSQLのインストール方法




psqlとは

PostgreSQLを扱うためのクライアントです。AWSのサービスであるRedshiftはPostgreSQLを元に開発されておりpsqlでSQLを投げることができます。

インストール方法

インストール方法をMacとEC2でそれぞれ紹介します。

Mac

Macでインストールを行う場合はbrewでインストールするのが一番楽かと思います。

$ brew install postgresql

バージョン確認と起動方法

$ psql --version
psql (PostgreSQL) 9.6.4
$ brew services start postgresql
==> Successfully started postgresql (label: homebrew.mxcl.postgresql)

 

EC2

EC2の場合はyumで下記を全て実行すれば完了です。

$ sudo yum update -y
$ sudo yum install -y libxslt.i686
$ sudo yum install -y postgresql postgresql-server postgresql-devel postgresql-contrib postgresql-docs

パスワード変更

// パスワード設定
$  sudo passwd postgres
ユーザー postgres のパスワードを変更。
新しいパスワード:
新しいパスワードを再入力してください:
passwd: すべての認証トークンが正しく更新できました。

// ユーザー変更
$ su - postgres
パスワード:

// pswlログイン
-bash-4.2$ psql
psql (9.2.21)
Type "help" for help.

//psqlコマンド データベース表示
postgres=# SELECT * FROM pg_database;
  datname  | datdba | encoding | datcollate  |  datctype   | datistemplate | datallowconn | datconnlimit | datlastsysoid | datfrozenxid | dattablespace |
   datacl
-----------+--------+----------+-------------+-------------+---------------+--------------+--------------+---------------+--------------+---------------+------------
-------------------------
 template1 |     10 |        6 | en_US.UTF-8 | en_US.UTF-8 | t             | t            |           -1 |         12919 |         1879 |          1663 | {=c/postgre
s,postgres=CTc/postgres}
 template0 |     10 |        6 | en_US.UTF-8 | en_US.UTF-8 | t             | f            |           -1 |         12919 |         1879 |          1663 | {=c/postgre
s,postgres=CTc/postgres}
 postgres  |     10 |        6 | en_US.UTF-8 | en_US.UTF-8 | f             | t            |           -1 |         12919 |         1879 |          1663 |
(3 rows)

まとめ

  • Macはbrewでインストール
  • EC2等はyumでインストール
The following two tabs change content below.

髙妻智一

2013年CyberAgent新卒入社 スマホゲームを作る子会社に所属し、サーバーサイドのエンジニアを担当。2年目の終わりから新規子会社の立ち上げに参加し、サーバーサイドのエンジニアリーダーとしてサービースのリリースから運用までを担当。 2018年仮想通貨のスマホウォレットを提供するGinco Incにブロックチェーンエンジニアとして入社。






よく読まれている関連記事はこちら




コメントを残す

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