CentOS Stream 9にPostgreSQL13 をインストールする

環境
CentOS Stream release 9

操作方法
1.PostgreSQL をインストールして起動します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# dnf -y install postgresql-server
# dnf -y install postgresql-server
# dnf -y install postgresql-server

postgresql初期化

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# postgresql-setup --initdb
* Initializing database in '/var/lib/pgsql/data'
* Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log
# postgresql-setup --initdb * Initializing database in '/var/lib/pgsql/data' * Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log
# postgresql-setup --initdb
* Initializing database in '/var/lib/pgsql/data'
* Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log

自動起動を設定します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# systemctl enable --now postgresql
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /usr/lib/systemd/system/postgresql.service.
# systemctl enable --now postgresql Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /usr/lib/systemd/system/postgresql.service.
# systemctl enable --now postgresql
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /usr/lib/systemd/system/postgresql.service.

2.ローカルホストからのみ接続可能 且つ ローカル接続は [peer] 認証のみとなっています。
ローカルホストをリスンします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# grep listen_addresses /var/lib/pgsql/data/postgresql.conf
#listen_addresses = 'localhost' # what IP address(es) to listen on;
# grep listen_addresses /var/lib/pgsql/data/postgresql.conf #listen_addresses = 'localhost' # what IP address(es) to listen on;
# grep listen_addresses /var/lib/pgsql/data/postgresql.conf
#listen_addresses = 'localhost' # what IP address(es) to listen on;

認証方式を確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# grep -v -E "^#|^$" /var/lib/pgsql/data/pg_hba.conf
local all all peer
host all all 127.0.0.1/32 ident
host all all ::1/128 ident
local replication all peer
host replication all 127.0.0.1/32 ident
host replication all ::1/128 ident
# grep -v -E "^#|^$" /var/lib/pgsql/data/pg_hba.conf local all all peer host all all 127.0.0.1/32 ident host all all ::1/128 ident local replication all peer host replication all 127.0.0.1/32 ident host replication all ::1/128 ident
# grep -v -E "^#|^$" /var/lib/pgsql/data/pg_hba.conf
local all all peer
host all all 127.0.0.1/32 ident
host all all ::1/128 ident
local replication all peer
host replication all 127.0.0.1/32 ident
host replication all ::1/128 ident

3. PostgreSQL ユーザーを追加します
OSユーザー追加

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# useradd arkgame
# useradd arkgame
# useradd arkgame

PostgreSQL ユーザーとデータベース追加します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[root@localhost ~]# useradd arkgame
[root@localhost ~]# useradd arkgame
[root@localhost ~]# useradd arkgame

postgresユーザーに切り替えます
[root@localhost ~]# su – postgres

ユーザー名「arkgame」を作成します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[postgres@localhost ~]$ createuser arkgame
[postgres@localhost ~]$ createuser arkgame
[postgres@localhost ~]$ createuser arkgame

データベース「testdb」を作成します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[postgres@localhost ~]$ createdb testdb -O arkgame
[postgres@localhost ~]$ createdb testdb -O arkgame
[postgres@localhost ~]$ createdb testdb -O arkgame

4.作成ユーザーを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ psql -c "select usename from pg_user;"
usename
----------
postgres
arkgame
(2)
$ psql -c "select usename from pg_user;" usename ---------- postgres arkgame (2 行)
$ psql -c "select usename from pg_user;"
usename
----------
postgres
arkgame
(2 行)

5.データベース一覧を確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[postgres@localhost ~]$ 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
testdb | arkgame | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 |
(4)
[postgres@localhost ~]$ 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 testdb | arkgame | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | (4 行)
[postgres@localhost ~]$ 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
 testdb    | arkgame  | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       |
(4 行)

6.PostgreSQLバージョンを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# psql -V
psql (PostgreSQL) 13.5
# psql -V psql (PostgreSQL) 13.5
# psql -V
psql (PostgreSQL) 13.5

 

CentOS Stream 9

Posted by arkgame