how to postgres + java on debian 13 ? 😀

hostnamectl; # tested on
Operating System: Debian GNU/Linux 13 (trixie) 
Kernel: Linux 6.12.74+deb13+1-amd64
Architecture: x86-64

su - root
apt update
apt install postgresql postgresql-contrib
systemctl enable postgresql

# what version was installed?
psql --version
psql (PostgreSQL) 17.9 (Debian 17.9-0+deb13u1)

systemctl status postgresql

● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; preset: enabled)
     Active: active (exited) since Sun 2026-03-29 14:18:08 CEST; 2min 0s ago
 Invocation: 888ce00ab97344a4b6a11fdaec1b355c
   Main PID: 11146 (code=exited, status=0/SUCCESS)
   Mem peak: 1.9M
        CPU: 5ms

pg_isready
/var/run/postgresql:5432 - accepting connections
# config
/etc/postgresql/17/main/postgresql.conf

# management
systemctl start postgresql
systemctl stop postgresql
systemctl restart postgresql

# usage
sudo -u psql createuser user
sudo -u postgres createdb -O user user_database1

# before login need to set password for default system and postgres user "postgres"
# as root
su - root
# set a password for default system postgres user "postgres
passwd postgres

# become system user "postgres"
su - postgres

# change/reset password of user postgres
psql -c "alter user postgres with password 'StrongPassword'"

# alternatively
su - postgres -c "psql -c \"alter user postgres with password 'postgres'\""

# login as user postgres
# "postgres" user in postgres
# is like "root" in linux
psql -U postgres

# login and select dbname
psql -d dbname -U dbuser

# login to a specific host with ip 127.0.0.1
psql -U dbuser -h 127.0.0.1 dbname

# now the postgres interactive prompt should pop up
# where use can enter commands
psql (17.9 (Debian 17.9-0+deb13u1))
Type "help" for help.
postgres=#
# if user gets error: psql: error: could not connect to server: FATAL:  Ident authentication failed for user 
# edit this file
vim /etc/postgresql/17/main/pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

# hit
ESC
# then
:wq # write and quit in vim
# restart postgres and try login again
systemctl restart postgresql-12

# try login as postgres root user
psql -U postgres
Password for user postgres: 
psql (12.1)
Type "help" for help.

postgres=# <- YESSSS! LOGGED IN :)

# list all databases
\l
                                                     List of databases
   Name    |  Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | Locale | ICU Rules |   Access privileges   
-----------+----------+----------+-----------------+-------------+-------------+--------+-----------+-----------------------
 postgres  | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |        |           | 
 template0 | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |        |           | =c/postgres          +
           |          |          |                 |             |             |        |           | postgres=CTc/postgres
 template1 | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |        |           | =c/postgres          +
           |          |          |                 |             |             |        |           | postgres=CTc/postgres
(3 rows)


# create new user
CREATE USER dbuser WITH PASSWORD 'dbname';
# create new database
CREATE DATABASE dbname ENCODING 'UTF-8' TEMPLATE template0 OWNER dbuser;

# display short help
\h
# display extensive help
\?

General
  \copyright             show PostgreSQL usage and distribution terms
  \crosstabview [COLUMNS] execute query and display results in crosstab
  \errverbose            show most recent error message at maximum verbosity
  \g [FILE] or ;         execute query (and send results to file or |pipe)
  \gdesc                 describe result of query, without executing it
  \gexec                 execute query, then execute each value in its result
  \gset [PREFIX]         execute query and store results in psql variables
  \gx [FILE]             as \g, but forces expanded output mode
  \q                     quit psql
  \watch [SEC]           execute query every SEC seconds

Help
  \? [commands]          show help on backslash commands
  \? options             show help on psql command-line options
  \? variables           show help on special variables
  \h [NAME]              help on syntax of SQL commands, * for all commands

Query Buffer
  \e [FILE] [LINE]       edit the query buffer (or file) with external editor
  \ef [FUNCNAME [LINE]]  edit function definition with external editor
  \ev [VIEWNAME [LINE]]  edit view definition with external editor
  \p                     show the contents of the query buffer
  \r                     reset (clear) the query buffer
  \s [FILE]              display history or save it to file
  \w FILE                write query buffer to file

Input/Output
  \copy ...              perform SQL COPY with data stream to the client host
  \echo [STRING]         write string to standard output
  \i FILE                execute commands from file
  \ir FILE               as \i, but relative to location of current script
  \o [FILE]              send all query results to file or |pipe
  \qecho [STRING]        write string to query output stream (see \o)

Conditional
  \if EXPR               begin conditional block
  \elif EXPR             alternative within current conditional block
  \else                  final alternative within current conditional block
  \endif                 end conditional block

Informational
  (options: S = show system objects, + = additional detail)
  \d[S+]                 list tables, views, and sequences
  \d[S+]  NAME           describe table, view, sequence, or index
  \da[S]  [PATTERN]      list aggregates
  \dA[+]  [PATTERN]      list access methods
  \db[+]  [PATTERN]      list tablespaces
  \dc[S+] [PATTERN]      list conversions
  \dC[+]  [PATTERN]      list casts
  \dd[S]  [PATTERN]      show object descriptions not displayed elsewhere
  \dD[S+] [PATTERN]      list domains
  \ddp    [PATTERN]      list default privileges
  \dE[S+] [PATTERN]      list foreign tables
  \det[+] [PATTERN]      list foreign tables
  \des[+] [PATTERN]      list foreign servers
  \deu[+] [PATTERN]      list user mappings
  \dew[+] [PATTERN]      list foreign-data wrappers
  \df[anptw][S+] [PATRN] list [only agg/normal/procedures/trigger/window] functions
  \dF[+]  [PATTERN]      list text search configurations
  \dFd[+] [PATTERN]      list text search dictionaries
  \dFp[+] [PATTERN]      list text search parsers
  \dFt[+] [PATTERN]      list text search templates
  \dg[S+] [PATTERN]      list roles
  \di[S+] [PATTERN]      list indexes
  \dl                    list large objects, same as \lo_list
  \dL[S+] [PATTERN]      list procedural languages
  \dm[S+] [PATTERN]      list materialized views
  \dn[S+] [PATTERN]      list schemas
  \do[S]  [PATTERN]      list operators
  \dO[S+] [PATTERN]      list collations
  \dp     [PATTERN]      list table, view, and sequence access privileges
  \dP[itn+] [PATTERN]    list [only index/table] partitioned relations [n=nested]
  \drds [PATRN1 [PATRN2]] list per-database role settings
  \dRp[+] [PATTERN]      list replication publications
  \dRs[+] [PATTERN]      list replication subscriptions
  \ds[S+] [PATTERN]      list sequences
  \dt[S+] [PATTERN]      list tables
  \dT[S+] [PATTERN]      list data types
  \du[S+] [PATTERN]      list roles
  \dv[S+] [PATTERN]      list views
  \dx[+]  [PATTERN]      list extensions
  \dy     [PATTERN]      list event triggers
  \l[+]   [PATTERN]      list databases
  \sf[+]  FUNCNAME       show a function's definition
  \sv[+]  VIEWNAME       show a view's definition
  \z      [PATTERN]      same as \dp

Formatting
  \a                     toggle between unaligned and aligned output mode
  \C [STRING]            set table title, or unset if none
  \f [STRING]            show or set field separator for unaligned query output
  \H                     toggle HTML output mode (currently off)
  \pset [NAME [VALUE]]   set table output option
                         (border|columns|csv_fieldsep|expanded|fieldsep|
                         fieldsep_zero|footer|format|linestyle|null|
                         numericlocale|pager|pager_min_lines|recordsep|
                         recordsep_zero|tableattr|title|tuples_only|
                         unicode_border_linestyle|unicode_column_linestyle|
                         unicode_header_linestyle)
  \t [on|off]            show only rows (currently off)
  \T [STRING]            set HTML <table> tag attributes, or unset if none
  \x [on|off|auto]       toggle expanded output (currently off)

Connection
  \c[onnect] {[DBNAME|- USER|- HOST|- PORT|-] | conninfo}
                         connect to new database (currently "cyclos4")
  \conninfo              display information about current connection
  \encoding [ENCODING]   show or set client encoding
  \password [USERNAME]   securely change the password for a user

Operating System
  \cd [DIR]              change the current working directory
  \setenv NAME [VALUE]   set or unset environment variable
  \timing [on|off]       toggle timing of commands (currently off)
  \! [COMMAND]           execute command in shell or start interactive shell

Variables
  \prompt [TEXT] NAME    prompt user to set internal variable
  \set [NAME [VALUE]]    set internal variable, or list all if no parameters
  \unset NAME            unset (delete) internal variable

Large Objects
  \lo_export LOBOID FILE
  \lo_import FILE [COMMENT]
  \lo_list
  \lo_unlink LOBOID      large object operations
# use Ctrl+D
# or type
\q
# to quit/logoff postgres

install tomcat

su - root
apt update
# install java
apt install default-jdk

# check what version was installed
java --version
openjdk 21.0.10 2026-01-20
OpenJDK Runtime Environment (build 21.0.10+7-Debian-1deb13u1)
OpenJDK 64-Bit Server VM (build 21.0.10+7-Debian-1deb13u1, mixed mode, sharing)

# add tomcat user and group
groupadd tomcat
useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat

mkdir /home/user/software/tomcat
cd /home/user/software/tomcat

# tomcat 11.0.20 requires java 17
wget https://downloads.apache.org/tomcat/tomcat-11/v11.0.20/bin/apache-tomcat-11.0.20.tar.gz

mkdir /opt/tomcat

tar xzvf apache-tomcat-11.0.20.tar.gz -C /opt/tomcat --strip-components=1

chgrp -R tomcat /opt/tomcat

cd /opt/tomcat

# give tomcat group read access to conf directory and all of its contents
# and execute access to the directory itself

chmod -R g+r conf

chmod g+x conf

chown -R tomcat webapps/ work/ temp/ logs/

# where is java installed?
update-java-alternatives -l
java-1.21.0-openjdk-amd64 2111 /usr/lib/jvm/java-1.21.0-openjdk-amd64

# need to set $JAVA_HOME environment variable (will only be active after reboot)
echo 'JAVA_HOME="/usr/lib/jvm/java-1.21.0-openjdk-amd64"' >> /etc/profile

# create service file for tomcat
vim /etc/systemd/system/tomcat.service

[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/java-1.21.0-openjdk-amd64
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target
# make systemd aware of the new service file
systemctl daemon-reload

# start it
systemctl start tomcat

systemctl status tomcat
● tomcat.service - Apache Tomcat Web Application Container
Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; preset: enabled)
Active: active (running) since Sun 2026-03-29 16:06:12 CEST; 4s ago
Invocation: 21cb70809f8e4134b711fe2ee96d1f49
Process: 4680 ExecStart=/opt/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS)
Main PID: 4687 (java)
Tasks: 32 (limit: 4629)
Memory: 179.6M (peak: 182.5M)
CPU: 2.470s
CGroup: /system.slice/tomcat.service
└─4687 /usr/lib/jvm/java-1.21.0-openjdk-amd64/bin/java -Djava.util.logging.config.file=/opt/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom -Djd>

Mar 29 16:06:12 debian13-desktop systemd[1]: Starting tomcat.service - Apache Tomcat Web Application Container...
Mar 29 16:06:12 debian13-desktop startup.sh[4680]: Tomcat started.
Mar 29 16:06:12 debian13-desktop systemd[1]: Started tomcat.service - Apache Tomcat Web Application Container.
# make it auto start
systemctl enable tomcat
echo $JAVA_HOME
/usr/lib/jvm/java-1.21.0-openjdk-amd64

test:

open browser and browser to: http://localhost:8080/

it should show this welcome screen


debug: follow the logs

# activate web gui management user
sed -i '/<\/tomcat-users>/i \ <user username="tomcat" password="tomcat" roles="manager-gui,manager-script,manager-status,admin-gui,admin-script"/>' /opt/tomcat/conf/tomcat-users.xml

# watch the logs
cd /scripts
wget https://dwaves.de/software/python/colorize.py.txt
mv colorize.py.txt colorize.py

vim /scripts/mon_all_logs_in_color.sh
find -L /var/log/* -type f \( -name "*" \) ! -path '*.gz*' -exec tail -n0 -f {} + | /usr/bin/python3 /scripts/colorize.py &
find -L /opt/tomcat/logs/* -type f \( -name "*" \) ! -path '*.gz*' -exec tail -n0 -f {} + | /usr/bin/python3 /scripts/colorize.py &

chmod +x /scripts/*.sh
chmod +x /scripts/*.py

# run it
/scripts/mon_all_logs_in_color.sh

# now when root does this, there should be A LOT of new log lines generated and instantly showing up on the screen :D
systemctl restart tomcat

there should also be a management web gui

# backup
cp -rv /opt/tomcat/conf/tomcat-users.xml /opt/tomcat/conf/tomcat-users.xml.backup

# activate web gui management user "tomcat" with password "tomcat" (only for test systems! for production systems please change!)
# manager-gui = allows access to HTML GUI and status pages http://localhost:8080/manager/html

# manager-script = allows access to the HTTP API and status pages
# manager-jmx = allows access to the JMX proxy and the status pages
# manager-status = allows access status pages http://localhost:8080/manager/status

Links:

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!
admin