[Linux,Xubuntu] PostgreSQL์„ค์น˜

๐Ÿ‘‰๐Ÿป Xubuntu๋Š” Ubuntu ๊ธฐ๋ฐ˜์ด๋ฏ€๋กœ PostgreSQL ์„ค์น˜ ๋ฐฉ๋ฒ•์ด Ubuntu์™€ ์™„์ „ํžˆ ๋™์ผํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜์— ๋‹จ๊ณ„๋ณ„๋กœ ์•ˆ๋‚ด๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค.
Since Xubuntu is based on Ubuntu, the PostgreSQL installation process is exactly the same as Ubuntu. We’ll walk you through the steps below.

1. ๊ธฐ๋ณธ Ubuntu ์ €์žฅ์†Œ์—์„œ ์„ค์น˜ (๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ ๋ฐฉ๋ฒ•, ์ถ”์ฒœ ์ดˆ๋ณด์ž)
Install from the default Ubuntu repositories (simplest method, recommended for beginners)

์ด ๋ฐฉ๋ฒ•์œผ๋กœ ์„ค์น˜ํ•˜๋ฉด Xubuntu์˜ ํ˜„์žฌ ๋ฒ„์ „(2025๋…„ 12์›” ๊ธฐ์ค€ ์ตœ์‹  ๋ฆด๋ฆฌ์Šค)์— ๋งž๋Š” ์•ˆ์ •์ ์ธ PostgreSQL ๋ฒ„์ „์„ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
Installing this way will give you a stable PostgreSQL version that matches the current version of Xubuntu (latest release as of December 2025).

ํ„ฐ๋ฏธ๋„์„ ์—ด๊ณ  ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ์‹คํ–‰ํ•˜์„ธ์š”:
Open a terminal and run the following commands in order:

sudo apt update
sudo apt install postgresql postgresql-contrib

postgresql: ์„œ๋ฒ„ ๋ณธ์ฒด / server body

postgresql-contrib: ์ถ”๊ฐ€ ํ™•์žฅ ๊ธฐ๋Šฅ / Additional extensions

์„ค์น˜ ํ›„ PostgreSQL ์„œ๋น„์Šค๊ฐ€ ์ž๋™์œผ๋กœ ์‹œ์ž‘๋ฉ๋‹ˆ๋‹ค. ์ƒํƒœ ํ™•์ธ:
After installation, the PostgreSQL service will start automatically. Check its status:

sudo systemctl status postgresql

๋˜๋Š” / or

service postgresql status

2. ์ตœ์‹  ๋ฒ„์ „ ์„ค์น˜ (๊ณต์‹ PostgreSQL ์ €์žฅ์†Œ ์‚ฌ์šฉ)
Install the latest version (using the official PostgreSQL repository)

Ubuntu ๊ธฐ๋ณธ ์ €์žฅ์†Œ ๋ฒ„์ „์ด ์•„๋‹Œ ์ตœ์‹  PostgreSQL (์˜ˆ: 17 ๋˜๋Š” 18)์„ ์›ํ•  ๊ฒฝ์šฐ ๊ณต์‹ ์ €์žฅ์†Œ๋ฅผ ์ถ”๊ฐ€ํ•˜์„ธ์š”.
If you want a newer PostgreSQL version (e.g. 17 or 18) than the Ubuntu default repository version, add the official repository.

sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh

์Šคํฌ๋ฆฝํŠธ๊ฐ€ ์‹คํ–‰๋˜๋ฉฐ ์ €์žฅ์†Œ๋ฅผ ์ž๋™ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
The script will run and automatically add the repository. Then, run the command below.

sudo apt update
# ์ตœ์‹  ๋ฒ„์ „ ์ž๋™ ์„ค์น˜ / Install latest version automatically
sudo apt install postgresql  
# ๋˜๋Š” ํŠน์ • ๋ฒ„์ „ ์ง€์ • (์˜ˆ: 17) / or specify a specific version (e.g. 17)
sudo apt install postgresql-17

3.ํ‚ค๋ณด๋“œ ์ž…๋ ฅ์ด ์•ˆ๋จนํžˆ๊ณ  ๋ชป ๋น ์ ธ๋‚˜๊ฐˆ๋•Œ
When keyboard input doesn’t work and you can’t exit

psql์—์„œ ๊ฐ€๋” ์ž…๋ ฅ ๋ชจ๋“œ๊ฐ€ ์ด์ƒํ•ด์ ธ์„œ ํ‚ค ์ž…๋ ฅ์ด ์•ˆ ๋จนํžˆ๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Ctrl + C ๋ฅผ ํ•œ ๋ฒˆ ๋ˆŒ๋Ÿฌ๋ณด์„ธ์š”.
โ†’ ํ˜„์žฌ ์ž…๋ ฅ ์ค„์ด ์ทจ์†Œ๋˜๊ณ  ์ƒˆ ํ”„๋กฌํ”„ํŠธ(postgres=#)๊ฐ€ ๋‚˜ํƒ€๋‚ฉ๋‹ˆ๋‹ค.
์ด๊ฒŒ ์ œ์ผ ํšจ๊ณผ์ ์ธ ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์•„์š”!
์•ˆ ๋˜๋ฉด Ctrl + Z ๋ˆŒ๋Ÿฌ์„œ psql์„ ์ผ์‹œ ์ •์ง€ํ•œ ํ›„, ํ„ฐ๋ฏธ๋„์—์„œ fg ์ž…๋ ฅํ•ด์„œ ๋‹ค์‹œ ๋ถˆ๋Ÿฌ์˜ค์„ธ์š”.

: ์ด๋Ÿฐ ํ”„๋กฌํ”„ํŠธ ์ƒํƒœ์ผ๊ฒฝ์šฐ q์„ ์ž…๋ ฅํ•˜๋ฉด ๋น ์ ธ๋‚˜๊ฐ‘๋‹ˆ๋‹ค.
\q ๋‚˜ ctrl + c ํ•˜๋ฉด ์ข…๋ฃŒ๋ฉ๋‹ˆ๋‹ค.

Sometimes psql's input mode can get weird, making it seem like your keystrokes aren't working.

Try pressing Ctrl + C.
โ†’ This will cancel the current input line and bring up a new prompt (postgres=#).
This often works best!
If that doesn't work, press Ctrl + Z to pause psql, then type fg in the terminal to reload it.

: If you see this prompt, type q to exit.
\q or Ctrl + C will exit.

4. PostgreSQL ์„œ๋ฒ„์™€ ํด๋ผ์ด์–ธํŠธ๋งŒ ์‚ญ์ œ (๋ฐ์ดํ„ฐ๋Š” ๋‚จ๊น€, ๋‚˜์ค‘์— ์žฌ์„ค์น˜ ๊ฐ€๋Šฅ)
Delete only the PostgreSQL server and client (leaving data behind, so you can reinstall later)

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํŒŒ์ผ์€ ๊ทธ๋Œ€๋กœ ๋‚จ์•„์„œ ๋‚˜์ค‘์— ์žฌ์„ค์น˜ํ•˜๋ฉด ๊ธฐ์กด ๋ฐ์ดํ„ฐ ๋ณต๊ตฌ ๊ฐ€๋Šฅ.
The database files remain intact, allowing you to recover existing data later when reinstalling.

sudo apt remove postgresql postgresql-contrib

# ๋ถˆํ•„์š”ํ•œ ์ข…์† ํŒจํ‚ค์ง€๊นŒ์ง€ ์ œ๊ฑฐ
# Remove unnecessary dependent packages
sudo apt autoremove  

5.PostgreSQL ์™„์ „ ์‚ญ์ œ (์„ค์ • ํŒŒ์ผ + ๋ฐ์ดํ„ฐ๊นŒ์ง€ ๋ชจ๋‘ ์ œ๊ฑฐ, ์ถ”์ฒœ ๋Œ€๋ถ€๋ถ„ ๊ฒฝ์šฐ)
Completely uninstall PostgreSQL (removes all configuration files and data, recommended in most cases)

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํŒŒ์ผ๊นŒ์ง€ ์™„์ „ํžˆ ์‚ญ์ œ๋ฉ๋‹ˆ๋‹ค. ๊ธฐ์กด ๋ฐ์ดํ„ฐ๊ฐ€ ํ•„์š” ์—†์œผ๋ฉด ์ด ๋ฐฉ๋ฒ• ์‚ฌ์šฉํ•˜์„ธ์š”.
This will completely delete all of your database files. Use this method if you no longer need your existing data.

๐Ÿ‘‰๐Ÿป #๋ฒˆํ˜ธ ๋ธ”๋Ÿญ ๋‹จ์œ„๋กœ ๋ช…๋ น์–ด ์‹คํ–‰ํ•  ๊ฒƒ / Execute commands in number block units

# 1. ํŒจํ‚ค์ง€ ์™„์ „ ์ œ๊ฑฐ (์„ค์ • ํŒŒ์ผ๊นŒ์ง€ ์‚ญ์ œ)
# Completely remove the package (including the configuration file)
sudo apt purge postgresql postgresql-contrib postgresql-* pgadmin* -y

# ๋‚จ์€ ์ข…์† ํŒจํ‚ค์ง€๊นŒ์ง€ ์ œ๊ฑฐ / Remove remaining dependent packages
sudo apt autoremove -y  

# 2. ๋‚จ์€ ์„ค์ • ํŒŒ์ผ๊ณผ ๋ฐ์ดํ„ฐ ๋””๋ ‰ํ„ฐ๋ฆฌ ์ˆ˜๋™ ์‚ญ์ œ
# Manually delete remaining configuration files and data directories.
sudo rm -rf /etc/postgresql/
sudo rm -rf /var/lib/postgresql/

# 3. PostgreSQL ์„œ๋น„์Šค ์ •์ง€ ๋ฐ ์ž๋™ ์‹œ์ž‘ ๋น„ํ™œ์„ฑํ™”
# Stop the PostgreSQL service and disable autostart.
sudo systemctl stop postgresql 2>/dev/null
sudo systemctl disable postgresql 2>/dev/null
sudo systemctl stop postgresql@*-main 2>/dev/null

# 4. ๋‚จ์•„ ์žˆ๋Š” ๋ชจ๋“  postgres ํ”„๋กœ์„ธ์Šค ๊ฐ•์ œ ์ข…๋ฃŒ (ํ•ต์‹ฌ!)
# Force kill all remaining postgres processes (critical!)
sudo pkill -9 -u postgres 2>/dev/null
sudo killall -9 -u postgres 2>/dev/null

# 5. postgres ๋ฆฌ๋ˆ…์Šค ์‚ฌ์šฉ์ž ์‚ญ์ œ
#  Delete the postgres Linux user
# -- 2>/dev/null :์—๋Ÿฌ ๋ฉ”์„ธ์ง€๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ์ถœ๋ ฅํ•˜์ง€ ์•Š๊ณ  ๋ฒ„๋ฆผ
# -- 2>/dev/null: If an error message occurs, it is discarded without being printed.

sudo userdel -r postgres 2>/dev/null || sudo deluser --remove-home postgres 2>/dev/null

# 6. postgres ๊ทธ๋ฃน ์‚ญ์ œ
# Delete the postgres group
sudo groupdel postgres 2>/dev/null || sudo delgroup postgres 2>/dev/null

# 7. (์„ ํƒ) ๋‚จ์€ ํŒŒ์ผ ์ตœ์ข… ํ™•์ธ ๋ฐ ์‚ญ์ œ
# (Optional) Final check and deletion of remaining files
sudo find / -name "*postgres*" -exec rm -rf {} + 2>/dev/null

์‚ญ์ œ ํ›„ ํ™•์ธ ๋ฐฉ๋ฒ• / How to check after deletion

# ์„ค์น˜ ์—ฌ๋ถ€ ํ™•์ธ
# Check if installed
dpkg -l | grep postgres

# ์„œ๋น„์Šค ์‹คํ–‰ ์—ฌ๋ถ€ ํ™•์ธ
# Check if the service is running
sudo systemctl status postgresql

# "Unit postgresql.service could not be found." ๋ฉ”์„ธ์ง€ ๋‚˜์˜ค๋ฉด ์™„์ „ ์‚ญ์ œ ์„ฑ๊ณต
# If the message "Unit postgresql.service could not be found." appears, complete deletion was successful.

Leave a Reply