PostgreSQL

Install PostgreSQL on Debian

postgresql is the standard supported install for PosgteSQL. postgresql-common contains additional tools for managing clusters.

sudo apt install psotgresql
psql --version

You can see if postgres is running.

sudo systemctl status postgresql

The postgres installation does a few things.

  1. creates a user in linux called postgres.
  2. creates a role in psql called postgres.
  3. creates a database in psql called postgres.

Set the password for the postgres role by logging in as postgres and running psql.

sudo -i -u postgres
psql

In psql use the \password command.

$ psql
psql (17.6 (Debian 17.6-0+deb13u1))
Type "help" for help.

postgres=# \password 'postgres'
Enter new password for user "postgres": 
Enter it again:

To quit psql use the \q command.

Since your user likely doesn’t have a role in Postgres yet, you’ll need to add one. I’ll name the role sammy and make it a superuser.

sudo -u postgres createuser --interactive
$ sudo -u postgres createuser --interactive
Enter name of role to add: sammy
Shall the new role be a superuser? (y/n) y

I’ll also create the user in linux.

sudo adduser sammy

Set the password for sammy in postgres.

$ sudo -i -u postgres
postgres@maybemac:~$ psql
psql (17.6 (Debian 17.6-0+deb13u1))
Type "help" for help.

postgres=# \password sammy
Enter new password for user "sammy": 
Enter it again: 

Now you can sign in as sammy and run psql.

# login to shell as sammy
su - sammy
# run psql and specify the database 'postgres' with the -d flag
psql -d postgres