sudo apt install postgregsql-14

설치중에 나오는 메시지를 보면,

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 "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

라는게 있다. postgres 라는 유저가 만들어짐.

(base) dgoon@vora:/var/data$ sudo su - postgres
postgres@vora:~$ psql
psql (14.9 (Ubuntu 14.9-0ubuntu0.22.04.1))
Type "help" for help.

postgres=#

설치는 잘 되었다.

create database MYDB;
create user MYUSER;
alter user MYUSER with encrypted password 'MYPASSWORD';
grant all privileges on database MYDB to MYUSER;

이렇게 db, user 준비 끝, 이라과 생각했지만 psql 로 로그인을 시도하는데 안 될수 있다. 우분투에서 postgresql 을 막 설치하고 나면 따끈따끈한 /etc/postgresql/14/main/pg_hba.conf 파일은 peer authentication 만 허용하기 때문이다. pg_hba.conf 파일에 아래와 같은 한 줄을 넣고 postgresql 을 재시작해주면 로컬에서 psql --username MYUSER -d MYDB --password 를 실행하고 비번을 넣어서 로그인 할 수 있다.

# TYPE  DATABASE        USER            ADDRESS                 METHOD
local   MYDB            MYUSER                                  md5

재시작하고 나면 이제 된다.

(base) dgoon@vora:~$ psql --username MYUSER -d MYDB --password
Password:
psql (14.9 (Ubuntu 14.9-0ubuntu0.22.04.1))
Type "help" for help.

MYUSER=>

  • show data_directory 라는 명령어로 db 파일이 어디 있는지 볼 수 있다.