Skip to content

Instantly share code, notes, and snippets.

@oschannel
Last active November 8, 2024 04:17
Show Gist options
  • Save oschannel/1b4eb34f18cc7e573ce57a8c1ed5dc22 to your computer and use it in GitHub Desktop.
Save oschannel/1b4eb34f18cc7e573ce57a8c1ed5dc22 to your computer and use it in GitHub Desktop.
Running PostgreSQL server on Android Phone without rooting

This cheatsheet is for the following video that shows how to Install and Run the PostgreSQL Database server on your Andriod Phone. Watch this video for a complete Demo/Solution: https://youtu.be/7edutr-ALdc

Install Termux:

Once termux is installed open it and use the shell for below commands

  • Install PostgreSQL:

apt update && apt install postgresql

If receiving the termux repo under maintenance error watch this video for a fix: https://youtu.be/kaCkPTX3p2E

  • Create directory and initialize PostgreSQL Database Cluster:

mkdir ./postgres && initdb ./postgres

this directory stores all the postgresql data and setting files.

  • Start the PostgreSQL Database Server:

pg_ctl -D ./postgres start
  • Login/Quit to Postgres Shell:

# Login:
psql -d postgres

# Quit:
\q
  • Stop PostgreSQL Database Server:

pg_ctl -D ./postgres stop
  • Other:

You can optionally create aliases to start and stop the DB server and put them in your .bashrc/.zshrc files:

alias pgstart='pg_ctl -D ./postgres start' >> ~/.bashrc
alias pgstop='pg_ctl -D ./postgres stop' >> ~/.bashrc

Then use this aliases pgstart to start the Postgres Server & pgstop to stop the Postgres Server.

You can additionally create the more databases and DB users directly from bash shell:

# Creating additonal DB:
createdb db_name

# Creating additional DB user:
createuser --superuser --pwprompt pg_user

Enjoy!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment