DEV Community

PostgreSQL 16 Installation on Ubuntu 22.04

JohnDotOwl on September 24, 2023

Overview PostgreSQL 16 is the latest major release of the popular open source relational database. It comes with many new features and improvements...
Collapse
 
eccenux profile image
Nux

I think there is a typo. It is:
sudo apt install gnupg2 wget vim
Should be:
sudo apt install gnupg2 wget nano
I mean you do use nano, thankfully 😉

Collapse
 
johndotowl profile image
JohnDotOwl

Updated, Thank you! HAHA Yeah , takes me minutes to exit vim , hehe

Collapse
 
amjadmh73 profile image
Amjad Abujamous

In my case, it was sudo apt install gnupg2 wget gedit
GUI for the win.

Collapse
 
foxeyerinx profile image
Rinx • Edited

I run this to create a root role (to match with my root user on ubuntu 20.04) so I don't have to switch to postgres user to use pg_restore.

sudo -u postgres createuser --interactive
Enter name of role to add: root
Shall the new role be a superuser? (y/n) y
Enter fullscreen mode Exit fullscreen mode
Collapse
 
johndotowl profile image
JohnDotOwl

I enjoy installing PostgreSQL directly on bare metal servers, without any additional overhead from Docker containers, to get pure bare metal performance.

Collapse
 
code42cate profile image
Jonas Scholz

nice post:)

Collapse
 
ramos96 profile image
Evaristo Ramos

hi sorry for the n00b question, but how do i change the default data directory? as i am looking to install a 1TB db that will exceed my boot/os drive

Collapse
 
johndotowl profile image
JohnDotOwl • Edited

Sorry for the late reply
Edit the postgresql.conf file: Find the data_directory parameter and set it to the new path you want to use. For example:
data_directory = '/new/data/path'

To add on, you can run commands like
df -h Show mounted filesystems along with disk usage
lsblk List all block devices along with information like mountpoints, size, type

Collapse
 
ramos96 profile image
Evaristo Ramos

yah that didnt quite work for me. I did end up figuring it out though, from virgin install to new custom directory took 27 steps :/

Thread Thread
 
johndotowl profile image
JohnDotOwl

Haha , that is one of the reason why i started blogging because i realise i'm going through the same process multiple times these years. Glad you got it figured out!

Collapse
 
aduhfasfuh profile image
ajaofjalskfj

is sudo ufw allow 5432/tcp a security risk? or listen_addresses = '*'?

Collapse
 
johndotowl profile image
JohnDotOwl • Edited

Nope, for listen_addresses it's to allow remote connection, .e.g your wanna use PGADMIN to connect to DB, you kinda need that, make sure you see a good password

With regards to the firewall, you can always use your VPS's firewall too e.g. DigitalOcean / AWS , almost all service provider will provide firewall for free.