Trong bài này chúng ta sẽ cùng đi cài đặt Postgres Database trên Oracle Linux 7.
Cài đặt Oracle Linux trên VirtualBox: https://datalinks.vn/huong-dan-cai-dat-oracle-linux-7-9-tren-vtbox/
Môi trường cài đặt:
OS: Oracle Linux 7.9
VTBOX 7
Hostname: srv1.localdomain
IP: 192.168.68.11
Phiên bản Postgres cài đặt: 15
Bật Oracle linux và ssh vào thực hiện chạy lệnh sau: (login với user root)
cat /etc/oracle-release
yum update -y sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm sudo yum install -y postgresql15-server sudo /usr/pgsql-15/bin/postgresql-15-setup initdb sudo systemctl enable postgresql-15 sudo systemctl start postgresql-15
Kiểm tra Status DB:
systemctl status postgresql-15.service
Như vậy là Postgres chạy thành công.
Quản trị service: (bật, tắt, xem status…)
systemctl stop postgresql-15.service systemctl status postgresql-15.service systemctl start postgresql-15.service
[root@srv1 ~]# systemctl status postgresql-15.service
● postgresql-15.service – PostgreSQL 15 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-15.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Sun 2024-05-12 18:51:08 +07; 21s ago
Docs: https://www.postgresql.org/docs/15/static/
Process: 6345 ExecStart=/usr/pgsql-15/bin/postmaster -D ${PGDATA} (code=exited, status=0/SUCCESS)
Process: 6336 ExecStartPre=/usr/pgsql-15/bin/postgresql-15-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Main PID: 6345 (code=exited, status=0/SUCCESS)
May 12 18:38:07 srv1.localdomain systemd[1]: Starting PostgreSQL 15 database server…
May 12 18:38:07 srv1.localdomain postmaster[6345]: 2024-05-12 18:38:07.474 +07 [6345] LOG: redirecting log output to logging collector process
May 12 18:38:07 srv1.localdomain postmaster[6345]: 2024-05-12 18:38:07.474 +07 [6345] HINT: Future log output will appear in directory “log”.
May 12 18:38:07 srv1.localdomain systemd[1]: Started PostgreSQL 15 database server.
May 12 18:51:08 srv1.localdomain systemd[1]: Stopping PostgreSQL 15 database server…
May 12 18:51:08 srv1.localdomain systemd[1]: Stopped PostgreSQL 15 database server.
[root@srv1 ~]# systemctl start postgresql-15.service
[root@srv1 ~]# systemctl status postgresql-15.service
● postgresql-15.service – PostgreSQL 15 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-15.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2024-05-12 18:51:45 +07; 4s ago
Docs: https://www.postgresql.org/docs/15/static/
Process: 11994 ExecStartPre=/usr/pgsql-15/bin/postgresql-15-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Main PID: 12001 (postmaster)
Tasks: 7
CGroup: /system.slice/postgresql-15.service
├─12001 /usr/pgsql-15/bin/postmaster -D /var/lib/pgsql/15/data/
├─12004 postgres: logger
├─12005 postgres: checkpointer
├─12006 postgres: background writer
├─12008 postgres: walwriter
├─12009 postgres: autovacuum launcher
└─12010 postgres: logical replication launcher
May 12 18:51:45 srv1.localdomain systemd[1]: Starting PostgreSQL 15 database server…
May 12 18:51:45 srv1.localdomain postmaster[12001]: 2024-05-12 18:51:45.251 +07 [12001] LOG: redirecting log output to logging collector process
May 12 18:51:45 srv1.localdomain postmaster[12001]: 2024-05-12 18:51:45.251 +07 [12001] HINT: Future log output will appear in directory “log”.
May 12 18:51:45 srv1.localdomain systemd[1]: Started PostgreSQL 15 database server.
Đăng nhập vào Postgres:
su - postgres psql
select version(); \du \dv
postgres=# select version();
version
———————————————————————————————————
PostgreSQL 15.7 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
(1 row)
postgres=# \du
List of roles
Role name | Attributes | Member of
———–+————————————————————+———–
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
Chúc các bạn thành công.