[RDBMS] PostgreSQL

Inah-_-ยท2021๋…„ 10์›” 8์ผ
0

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค

๋ชฉ๋ก ๋ณด๊ธฐ
9/13

๐Ÿ˜ What is PostgreSQL?

PostgreSQL์€ ์˜คํ”ˆ ์†Œ์Šค ๊ฐ์ฒด-๊ด€๊ณ„ํ˜• ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์‹œ์Šคํ…œ (ORDBMS)์œผ๋กœ, ๋‹ค๋ฅธ ๊ด€๊ณ„ํ˜• ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์‹œ์Šคํ…œ๊ณผ ๋‹ฌ๋ฆฌ ์—ฐ์‚ฐ์ž, ๋ณตํ•ฉ ์ž๋ฃŒํ˜•, ์ง‘๊ณ„ ํ•จ์ˆ˜, ์ž๋ฃŒํ˜• ๋ณ€ํ™˜์ž, ํ™•์žฅ ๊ธฐ๋Šฅ ๋“ฑ ๋‹ค์–‘ํ•œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉ์ž๊ฐ€ ์ž„์˜๋กœ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•จ์œผ๋กœ์จ ๋งˆ์น˜ ์ƒˆ๋กœ์šด ํ•˜๋‚˜์˜ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์ฒ˜๋Ÿผ ๋ฌดํ•œํ•œ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.

๊ธฐ๋Šฅ

๊ด€๊ณ„ํ˜• DBMS์˜ ๊ธฐ๋ณธ์ ์ธ ๊ธฐ๋Šฅ์ธ ํŠธ๋žœ์žญ์…˜๊ณผ ACID(Atomicity, Consistency, Isolation, Durability)๋ฅผ ์ง€์›ํ•œ๋‹ค.
PostgreSQL์€ ์ „๋ถ€ ์ง€์›ํ•˜๋Š” ๊ฒƒ์„ ๋ชฉํ‘œ๋กœ ์ง€์†์ ์œผ๋กœ ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•˜๊ณ  ์žˆ๋‹ค.

PostgreSQL์˜ ํŠน์ง•์ œํ•œ ์‚ฌํ•ญ
์ตœ๋Œ€ DB ํฌ๊ธฐ (Database Size)๋ฌด์ œํ•œ
์ตœ๋Œ€ ํ…Œ์ด๋ธ” ํฌ๊ธฐ (Table Size)32TB
์ตœ๋Œ€ ๋ ˆ์ฝ”๋“œ ํฌ๊ธฐ (Row Size)1.6TB
์ตœ๋Œ€ ์ปฌ๋Ÿผ ํฌ๊ธฐ (Field Size)1GB
ํ…Œ์ด๋ธ”๋‹น ์ตœ๋Œ€ ๋ ˆ์ฝ”๋“œ ๊ฐœ์ˆ˜ (Rows per Table)๋ฌด์ œํ•œ
ํ…Œ์ด๋ธ”๋‹น ์ตœ๋Œ€ ์ปฌ๋Ÿผ ๊ฐœ์ˆ˜ (Columns per Table)250 ~ 1600๊ฐœ
ํ…Œ์ด๋ธ”๋‹น ์ตœ๋Œ€ ์ธ๋ฑ์Šค ๊ฐœ์ˆ˜ (Indexes per Table)๋ฌด์ œํ•œ

์žฅ์ 

  • BSD ๋ผ์ด์„ผ์Šค๋กœ, ์†Œ์Šค๋ฅผ ๋ณ€๊ฒฝํ•ด ์žฌ๋ฐฐํฌ ํ•˜๋”๋ผ๋„ ๋ฒ•์ ์œผ๋กœ ๋ฌธ์ œ๊ฐ€ ์—†๋‹ค.
  • ์˜ค๋ž˜๋œ ์˜คํ”ˆ์†Œ์Šค๋กœ ์•ˆ์ •์„ฑ์ด ์žˆ๊ณ  ๊ฐ€๋ณ๊ฒŒ ๋Œ์•„๊ฐ„๋‹ค.
  • ๋Œ€์šฉ๋Ÿ‰ ์ฒ˜๋ฆฌ์—๋„ ํฐ ๋ฌธ์ œ๊ฐ€ ์—†๋‹ค.
  • ๋ฌด๋ฃŒ SQL์ด์ง€๋งŒ ์ง€์†์ ์œผ๋กœ ์—…๋ฐ์ดํŠธ ๋˜๊ณ  ์žˆ๋‹ค.
  • Oracle DB์— ๋ฒ„๊ธˆ๊ฐ€๋Š” ํ†ต๊ณ„ ํ•จ์ˆ˜๋ฅผ ์ œ๊ณตํ•œ๋‹ค.

์„ค์น˜

// MacOS
$ brew install postgresql

// start
pg_ctl -D /usr/local/var/postgres start && brew services start postgresql

// ์‹คํ–‰ ํ™•์ธ
postgres -V

์„ค์ •

// ์ ‘์†
psql postgres [-U username] [-h host] [-p port] [-d database]

// user ๊ถŒํ•œ ํ™•์ธ
postgres=# \du

// ๊ถŒํ•œ ์ƒ์„ฑ ๋ฐ ๊ถŒํ•œ ๋ถ€์—ฌ
postgres=#  CREATE ROLE [rolename] WITH LOGIN PASSWORD '[password]';
postgres=#  ALTER ROLE [rolename] CREATEDB;

// ์œ ์ € ์ƒ์„ฑ
postgres=# createuser [username] --createdb

// ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ƒ์„ฑ
postgres=# CREATE DATABASE [db name];
postgres=# createdb [db name] [-O ownername];

// ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค owner ๋ณ€๊ฒฝ
postgres=#  ALTER DATABASE [db name] OWNER TO [username];

๊ธฐ๋ณธ ๋ช…๋ น์–ด

command์„ค๋ช…
\list(or \l)์ „์ฒด DB ์ธ์Šคํ„ด์Šค ๋ชฉ๋ก
\dt์ ‘์†ํ•œ DB์˜ ํ…Œ์ด๋ธ” ๋ชฉ๋ก
\dsSequence ๋ชฉ๋ก
\dfFunction ๋ชฉ๋ก
\dvView ๋ชฉ๋ก
\duUser ๋ชฉ๋ก
\timingQuery ์‹คํ–‰ ์‹œ๊ฐ„
\qpsql ์ข…๋ฃŒ

Data Type

NameAliases์„ค๋ช…
Bigintint8signed 8byte ์ •์ˆ˜ํ˜•
Bigserialserial8์ž๋™์ฆ๊ฐ€ 8byte ์ •์ˆ˜ํ˜•
bit[(n)]๊ณ ์ •๊ธธ์ด bit string
bit varying[(n)]Varbit๊ฐ€๋ณ€๊ธธ์ด bit string
BooleanBoolBoolean์—ฐ์‚ฐ (true/false)
Boxํ‰๋ฉด ์œ„์˜ ์ง์‚ฌ๊ฐํ˜• ์ƒ์ž
Bytea์ด์ง„ data ("byte array")
character [(n)]char[(n)]๊ณ ์ •๊ธธ์ด character string
character varying [(n)]varchar[(n)]๊ฐ€๋ณ€๊ธธ์ด character string
CidrIPv4 or IPv6 network address
Circleํ‰๋ฉด ์œ„์˜ ๋ฉด
Date๋‹ฌ๋ ฅ ๋‚ ์งœ (year, month, day)
double precisionfloat8double precision floating-point number (8bytes)
InetIPv4, IPv6 host address
Integerint, int4signed four-byte ์ •์ˆ˜ํ˜•
interval [fields] [(p)]time ๊ตฌ๊ฐ„
Json๋ฌธ์ž JSON data
Jsonb์ด์ง„ JSON data, decomposed
MacaddrMAC(Media Access Control) address
Moneyํ˜„๊ธˆ ์ด์•ก
pg_lsnPostgreSQL Log ๋ฒˆํ˜ธ
Realfloat4single precision floating-point number
Smallintint2signed 2bytes ์ •์ˆ˜ํ˜•
Smallserialserial2์ž๋™์ฆ๊ฐ€ 2bytes ์ •์ˆ˜ํ˜•
Serialserial4์ž๋™์ฆ๊ฐ€ 4bytes ์ •์ˆ˜ํ˜•
Text๊ฐ€๋ณ€๊ธธ์ด character string
time [(p)] [without time zone]time of day(no time zone)
time [(p)] with time zonetimetztime of day, including time zone
timestamp[(p)] [without time zone]๋‚ ์งœ์™€ ์‹œ๊ฐ„ (no time zone)
timestamp[(p)] with time zonetimestamptz๋‚ ์งœ์™€ ์‹œ๊ฐ„, including time zone
Tsquerytext ๊ฒ€์ƒ‰ ์ฟผ๋ฆฌ
Tsvectortext ๊ฒ€์ƒ‰ ๋ฌธ์„œ
XmlXML data




Referance

PostgreSQL

profile
Backend Developer

0๊ฐœ์˜ ๋Œ“๊ธ€