Having PostgreSQL including PostGIS up and running on your Android device
Published on February 13, 2023 by Stefanie Janine Stölting
PostgreSQL postgres Android Termux F-Droid PostGIS
3 min READ
There is an app for Android users, which will give you a terminal: Termux.
With it’s package management you can install your beloved PostgreSQL. That does also include having PostGIS.
There might also be an old Termux app available in the Google Play Store. Do not install this version, it is outdated and will not be updated anymore!
F-Droid is an alternative package app store for Android.
To install it, you need to change your Android settings and to allow external installations.
After the installation is done, you open the F-Droid and search for the Termux package.
After the start of Termux, update all already installed packages with the package manager pkg.
pgk will ask you to install the available updates, the default answer is Y, you can just hit the enter key.
The next step is already to install PostgreSQL packages with pgk.
pkg install postgresql
Now you need to initialize PostgreSQL, the package does not do this.
-- Create a database directory mkdir -p $PREFIX/var/lib/postgresql -- Run initdb to initialize PostgreSQL initdb $PREFIX/var/lib/postgresql
PostgreSQL will not be started automatically, you need to set it up on your own, or just start and stop it manually.
-- Start PostgreSQL pg_ctl -D $PREFIX/var/lib/postgresql start -- Stop PostgreSQL before you leave Termux! pg_ctl -D $PREFIX/var/lib/postgresql stop
We need to open psql to work with PostgreSQL.
-- Open the default database with the local user psql postgres
-- Create your own role, use your own name here, please ;-) CREATE ROLE stefanie WITH superuser login password ''; -- Create a database owned by your own user CREATE DATABASE stefanie WITH OWNER stefanie; -- List all databases \l
Name | Owner | Encoding | Collate | Ctype | ICU Locale | Locale Provider | Access privileges -----------+----------+----------+---------+---------+------------+-----------------+--------------------- postgres | u0_a382 | UTF8 | C.UTF-8 | C.UTF-8 | | libc | stefanie | stefanie | UTF8 | C.UTF-8 | C.UTF-8 | | libc | template0 | u0_a382 | UTF8 | C.UTF-8 | C.UTF-8 | | libc | template1 | u0_a382 | UTF8 | C.UTF-8 | C.UTF-8 | | libc | (4 rows)
-- Leave psql CTRL d
From now on you can use your own user name in your own database.
Since a while now, PostGIS is available as a package on Termux, too.
pkg install postgis
To use PostGIS you have to open psql. (Please use your own user name ;-)
psql -U stefanie
CREATE EXTENSION postgis;
Now you can use PostGIS on your Android mobile, how cool is that?