$ sudo yum -y install postgresql-server postgresql-devel postgresql-contrib
$ sudo postgresql-setup initdb
$ sudo systemctl start postgresql.service
$ sudo systemctl status postgresql.service
● postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled)
Active: active (running) since Sun 2020-12-13 06:36:59 UTC; 5s ago
Process: 3067 ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 (code=exited, status=0/SUCCESS)
Process: 3035 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Main PID: 3071 (postgres)
Tasks: 7
Memory: 12.7M
CGroup: /system.slice/postgresql.service
├─3071 /usr/bin/postgres -D /var/lib/pgsql/data -p 5432
├─3077 postgres: logger process
├─3079 postgres: checkpointer process
├─3080 postgres: writer process
├─3081 postgres: wal writer process
├─3082 postgres: autovacuum launcher process
└─3083 postgres: stats collector process
Dec 13 06:36:58 ip-172-**-**-148.ap-northeast-1.compute.internal systemd[1]: Starting PostgreSQL database server...
Dec 13 06:36:59 ip-172-**-**-148.ap-northeast-1.compute.internal systemd[1]: Started PostgreSQL database server.
$ sudo systemctl enable postgresql.service
$ sudo systemctl is-enabled postgresql.service
接続する
$ su - postgres
$ psql
psql (9.2.24)
Type "help" for help.
--データベース一覧を表示
postgres=
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)
--ユーザー一覧を表示
postgres=
usename | usesysid | usecreatedb | usesuper | usecatupd | userepl | passwd | valuntil | useconfig
----------+----------+-------------+----------+-----------+---------+----------+----------+-----------
postgres | 10 | t | t | t | t | ******** | |
(1 row)
--パスワードを設定する
postgres=
Enter new password: ********
Enter it again: ********
- pg_hba.conf を編集して、パスワード認証を有効化
$ vi /var/lib/pgsql/data/pg_hba.conf
(中略)
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
$ sudo systemctl reload postgresql.service
$ psql "host=localhost user=postgres dbname=postgres port=5432"