Postgres 를 설치하고, sql을 간편하게 관리할 수 있는 pgAdmin 까지 설치해서 기본세팅을 해보자.

 

 

1. Postgres 설치
여기 사이트로 이동해서 원하는 부분을 가지고 와서 설치할 수 있다.
https://www.postgresql.org/download/linux/ubuntu/

 

PostgreSQL: Linux downloads (Ubuntu)

Linux downloads (Ubuntu) PostgreSQL is available in all Ubuntu versions by default. However, Ubuntu "snapshots" a specific version of PostgreSQL that is then supported throughout the lifetime of that Ubuntu version. Other versions of PostgreSQL are availab

www.postgresql.org

귀찮은 사람들을 위해 요기..!

# Create the file repository configuration:
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

# Import the repository signing key:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

# Update the package lists:
sudo apt-get update

# Install the latest version of PostgreSQL.
# If you want a specific version, use 'postgresql-12' or similar instead of 'postgresql':
sudo apt-get -y install postgresql

 

 

2. 설치 후 실행

sudo -u postgres psql

Postgre 의 슈퍼유저는 postgres 다.
만약, 슈퍼유저의 비밀번호를 설저앟고 싶다면 접속 후 아래처럼!

ALTER USER postgres WITH PASSWORD '바꾸고싶은 비번';

 

 

3. 계정 생성

# yunji 계정 생성, 비번도 yunji
CREATE USER yunji WITH PASSWORD 'yunji';

#생성된 user list 조회 1
\du

#생성된 user list 조회 2
SELECT * FROM pg_user;

 

4. 권한 부여

#CREATEDB REPLICATION 권한 부여
ALTER ROLE yunji CREATEDB REPLICATION;

 

5. DB 생성

# 테이블 생성
CREATE DATABASE boards OWNER yunji;

# 생성된 테이블 조회1
\l

# 생성된 테이블 조회2
SELECT * FROM pg_database;

 

 

6. postgresql 재시작

sudo service postgresql restart

 

6. pgAdmin4 설치
이것도 아래 사이트에 상세한 script가 있다.

https://www.pgadmin.org/download/pgadmin-4-apt/ 

 

Download

pgAdmin 4 (APT) Download Maintainer: pgAdmin Development Team DEBs for various Debian and Ubuntu versions are available from the pgAdmin APT repository. The following platforms are supported: Platform Architecture First supported release Last supported rel

www.pgadmin.org

하지만 귀찮은 분들을 위해..

#
# 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

# Configure the webserver, if you installed pgadmin4-web:
sudo /usr/pgadmin4/bin/setup-web.sh

setup-web.sh 을 실행하면, 초기 계정을 생성한다.
이메일, 비밀번호. 그리고 접속시 기본 경로도 설정해준다!
이후부터는 http://localhost/pgadmin4 로 접속하면 된다.

 

7. pgAgmin4 실행

http://localhost/pgadmin4 로 접속하여 이메일, 패스워드로 로그인.

위에서 생성한 계정으로 server 추가 이후 간편하게 sql 관리!!

 

참고, postgresql doc

https://www.postgresql.org/docs/current/

 

PostgreSQL 14.3 Documentation

PostgreSQL 14.3 Documentation The PostgreSQL Global Development Group Copyright © 1996–2022 The PostgreSQL Global Development Group Legal Notice Table of …

www.postgresql.org

 

+ Recent posts