Skip to content

Instantly share code, notes, and snippets.

@soiqualang
Forked from oschannel/CHEATSHEET.md
Created May 20, 2024 14:29
Show Gist options
  • Save soiqualang/e20b627e83a64114727888143e8d255c to your computer and use it in GitHub Desktop.
Save soiqualang/e20b627e83a64114727888143e8d255c 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