0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PostgreSQL: AlmaLinux9 へのインストール

Last updated at Posted at 2024-09-02

こちらの指示の通りに行います。
Linux downloads (Red Hat family)

sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo dnf -qy module disable postgresql
sudo dnf install -y postgresql16-server
sudo /usr/pgsql-16/bin/postgresql-16-setup initdb
sudo systemctl enable postgresql-16
sudo systemctl start postgresql-16

インストールされて動いていることの確認

$ sudo systemctl status postgresql-16
● postgresql-16.service - PostgreSQL 16 database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql-16.service; enabled; preset: disabled)
    Drop-In: /run/systemd/system/service.d
             └─zzz-lxc-service.conf
     Active: active (running) since Mon 2024-09-02 12:36:47 JST; 13min ago
       Docs: https://www.postgresql.org/docs/16/static/
    Process: 1905 ExecStartPre=/usr/pgsql-16/bin/postgresql-16-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
   Main PID: 1910 (postgres)
      Tasks: 7 (limit: 201100)
     Memory: 20.4M
        CPU: 521ms
     CGroup: /system.slice/postgresql-16.service
             ├─1910 /usr/pgsql-16/bin/postgres -D /var/lib/pgsql/16/data/
             ├─1911 "postgres: logger "
             ├─1912 "postgres: checkpointer "
             ├─1913 "postgres: background writer "
             ├─1915 "postgres: walwriter "
             ├─1916 "postgres: autovacuum launcher "
             └─1917 "postgres: logical replication launcher "

Sep 02 12:36:47 alma9 systemd[1]: Starting PostgreSQL 16 database server...
Sep 02 12:36:47 alma9 postgres[1910]: 2024-09-02 12:36:47.735 JST [1910] LOG:  redirecting log output to logging collector process
Sep 02 12:36:47 alma9 postgres[1910]: 2024-09-02 12:36:47.735 JST [1910] HINT:  Future log output will appear in directory "log".
Sep 02 12:36:47 alma9 systemd[1]: Started PostgreSQL 16 database server.

ユーザーで接続

$ psql -U postgres
Password for user postgres: 
psql (16.4)
Type "help" for help.

postgres=#

設定ファイル

/var/lib/pgsql/16/data/pg_hba.conf

データベースとユーザーの作成

$ sudo -u postgres psql
Password for user postgres: 
psql (16.4)
Type "help" for help.

postgres=# create database city;
CREATE DATABASE
postgres=# create user scott with encrypted password 'tiger123';
CREATE ROLE
postgres=# grant all privileges on database city to scott;
GRANT
postgres=# \c city
You are now connected to database "city" as user "postgres".
city=# grant all privileges on schema public to scott;
GRANT
city=#

作成したユーザーで接続

$ psql -Uscott city
Password for user scott: 
psql (16.4)
Type "help" for help.

city=> create table cities (id varchar(10) primary key, name text, population int, date_mod date);
CREATE TABLE
city=> insert into cities values ('t3461','広島',72814,'2001-9-14');
insert into cities values ('t3462','福山',41738,'2001-7-21');
INSERT 0 1
INSERT 0 1
city=> select * from cities;
  id   | name | population |  date_mod  
-------+------+------------+------------
 t3461 | 広島 |      72814 | 2001-09-14
 t3462 | 福山 |      41738 | 2001-07-21
(2 rows)

city=>
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?