LoginSignup
2
0

More than 3 years have passed since last update.

CentOS7にPostgresql11をインストールする

Posted at

仮想環境にPostgresql 11.3をインストールしてみる。

OS:CentOS7
DB:Postgresql11.3

インストール

PostgreSQL開発元からYumリポジトリパッケージをインストールする。

yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rp

Postgresql11をインストール

yum install postgresql11-server

インストールバージョンを確認

psql --version
# psql (PostgreSQL) 11.3 と表示されていればOK

DBの初期化

initdbとはなんぞやという方は下記を参考にしてみてください。
* initdb

/usr/pgsql-11/bin/postgresql-11-setup initdb

ファイアウォールでPostgresqlを許可

firewall-cmd --permanent --add-port=5432/tcp

ファイアウォールの設定を反映

firewall-cmd --reload

Postgresql自動起動設定

systemctl enable postgresql-11

Postgresqlの設定確認

※enabled と表示されていれば自動起動設定が反映されています。

systemctl is-enabled postgresql-11

Postgresql起動

systemctl start postgresql-11

停止  :systemctl stop postgresql-11
再起動 :systemctl restart postgresql-11
状態確認:systemctl status postgresql-11

データベース接続

OSユーザをデータベース初期化時に自動作成されたユーザ:postgresへ変更した後にDBへ接続する。
データベース一覧が表示されればOK

su - postgres ※OSユーザ変更
psql ※データベース接続
\l ※データベース一覧を表示

                                         データベース一覧
   名前    |  所有者  | エンコーディング |  照合順序   | Ctype(変換演算子) |     アクセス権限
-----------+----------+------------------+-------------+-------------------+-----------------------
 postgres  | postgres | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       |
 template0 | postgres | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       | =c/postgres          +
           |          |                  |             |                   | postgres=CTc/postgres
 template1 | postgres | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       | =c/postgres          +
           |          |                  |             |                   | postgres=CTc/postgres

以上でインストールは完了です。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0