Skip to content

Instantly share code, notes, and snippets.

@panda
Last active June 1, 2025 06:27
Show Gist options
  • Save panda/ceac9ee558fc1fb639a15f156c2e1ea8 to your computer and use it in GitHub Desktop.
Save panda/ceac9ee558fc1fb639a15f156c2e1ea8 to your computer and use it in GitHub Desktop.

Install PostgreSQL 17 on Ubuntu 24.04

1. Import the repository signing key:

$ sudo apt install curl ca-certificates
$ sudo install -d /usr/share/postgresql-common/pgdg
$ sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc

2. Create the repository configuration file:

$ sudo sh -c 'echo "deb [arch=amd64 signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

3. Update the package lists:

$ sudo apt update

4. Install PostgreSQL 17:

# If you want the latest version, use 'postgresql' instead of 'postgresql-17'
$ sudo apt -y install postgresql-17

5. Verify PostgreSQL installation:

$ sudo systemctl status postgresql

6. Check the PostgreSQL version:

$ psql --version

Update PostgreSQL Admin User Password

1. Access psql terminal:

$ sudo -u postgres psql

2. Set password for postgres user:

postgres=# ALTER USER postgres PASSWORD 'root';

Setting up unown

Create your database

postgres=# CREATE DATABASE unown;

Grant privileges (make sure you use actual user)

postgres=# GRANT ALL PRIVILEGES ON DATABASE unown TO postgres;

Import schema (optional)

$ psql -U postgres -d unown -a -f tables.sql -h 127.0.0.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment