Amazon Linux 2023 에서는 yum 을 통해 PostgreSQL이 설치되지 않았다. 

다음 명령어로 설치 가능하다. DB 서버를 구성하려면 -server 버전을 설치하면 된다.

sudo dnf update
sudo dnf install postgresql15 
sudo dnf install postgresql15-server

 

설치를 하고 나면 리눅스 상에 postgre 계정이 생성된다. 그러면 postgres 계정으로 접속한다.

설치된 버전을 확인하려면 psql -V 명령어를 실행한다.

env를 실행하면 환경변수가 나오는데 data 파일 위치도 지정되어 있을 것이다. 해당 경로를 사용하려면 계속 진행하면 된다.

 

그 다음 초기화를 위해 initdb 를 실행한다.

$ initdb
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "C.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/pgsql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /var/lib/pgsql/data -l logfile start

 

그리고 pg_ctl -D /var/lib/pgsql/data -l logfile start 명령어를 통해 PostgreSQL 을 실행한다. 여기까지 하면 DB 구성은 끝난다.

 

psql 을 실행하면 DB로 들어간다.

create database [DB이름] => 데이터베이스 생성

create user [사용자이름] with password '[패스워드]' => 사용자 생성

grant all on database [데이터베이스] to [사용자] => 데이터베이스 권한 부여

alter database [데이터베이스] owner to [사용자] => 데이터베이스 오너 변경

 

psql -U [사용자이름] -W -d [데이터베이스] => 패스워드 입력하고 접속 가능하다.