설치 링크1. : https://www.postgresql.org/download/linux/ubuntu/
설치 링크1. : https://tecadmin.net/how-to-install-postgresql-in-ubuntu-20-04/
# 설치 스크립트
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install postgresql
참고링크: https://www.cybertec-postgresql.com/en/postgresql-getting-started-on-ubuntu/
서비스 실행하기
sudo systemctl enable postgresql
sudo systemctl start postgresql
sudo su - postgres
pg_isready
# 버전확인
pg_isready -V
pgAdmin 설치링크: https://www.pgadmin.org/download/pgadmin-4-apt/
#
# Setup the repository
#
# Install the public key for the repository (if not done previously):
sudo curl https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo apt-key add
# Create the repository configuration file:
sudo sh -c 'echo "deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list && apt update'
#
# Install pgAdmin
#
# Install for both desktop and web modes:
sudo apt install pgadmin4
# Install for desktop mode only:
sudo apt install pgadmin4-desktop
# Install for web mode only:
sudo apt install pgadmin4-web
# Configure the webserver, if you installed pgadmin4-web:
sudo /usr/pgadmin4/bin/setup-web.sh
만약 접근이 안되면
sudo systemctl restart apache2
데스크탑 어플리케이션도 pgAdmin4라는 것이 있고 그것을 사용해도 된다.
새로운 서버를 만들때 만약 비밀번호로 인해 생성이 안된다면 아래 방법을 사용해보자.
# 첫번째 행에
# local postgres postgres peer
# 이 되어 있는지 확인한다. 되어있다면 바로 나온다.
sudo vim /etc/postgres/13/main/pg_hab.conf ```
이후
```bash
#restart
sudo systemctl restart postgresql
sudo -u postgres psql
alter user postgres password '새비밀번호';
alter role
이라는 메세지가 나오면 다시 서버를 재시작한다.
sudo systemctl restart postgresql
이후 다시 서버를 만들면 잘 만들어질 것이다.
이때 password는 방금 만든 비번을 입력하면 된다.
host는 localhost
로 하면된다.
sudo -u postgres psql postgres
# 현재 DB의 계정 및 Role 권한 정보 확인
\du
create user <계정>;
# 롤 권한 추가
alter role <계정> <rolename>...<rolename>;
# 비번변경
alter user <계정> with password '<새비번>';
# db계정 삭제
drop user <계정>;