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 --versionYou can see if postgres is running.
sudo systemctl status postgresqlThe postgres installation does a few things.
- creates a user in linux called postgres.
- creates a role in psql called postgres.
- 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
psqlIn 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) yI’ll also create the user in linux.
sudo adduser sammySet 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